Posts

Showing posts from September, 2011

Isotope: An exquisite jQuery plugin for magical layouts

Check it here Can be combined with Infinte Scroll plugin

Infinite scroll - an alternative to next and prev

Interesting plugin

Making AJAX Applications Crawlable

Overview Spec from google

Best way to pass params from php to javascript

Use json_encode, better than simple parameter replacement e.g. <script type="text/javascript"> var myObj = {}; myObj.config = <?php echo json_encode($my_config); ?>; </script> Then later in js you can call myObj.config.field1, where field1 is a array key passed from php

Laravel configuration files per environment

You can define configurations per environment 1. Set the environment in apache:  SetEnv LARAVEL_ENV local 2. I defined an override application.php in /application/config/local and dev, test and prod Then I can access as follows: $myConfigValue = Config::get('application.myConfigValue'); Then pass to view as follows return View::make('home.index')->bind("myConfigValue", $myConfigValue); Here's what the config files looks like in /application/config/local return array( // Url for local 'url' => 'http://localhost', 'myConfigValue' =>  'yesDoIt' ); Of course, see the laravel documentation for all this and more.

My Jumble of Links

Ok, until I find a better place..(browsers crash too ya know!) jQuery and js jquery this http://remysharp.com/2007/04/12/jquerys-this-demystified/ js call and apply http://odetocode.com/blogs/scott/archive/2007/07/05/function-apply-and-function-call-in-javascript.aspx js module pattern http://www.adequatelygood.com/2010/3/JavaScript-Module-Pattern-In-Depth Blogs http://addyosmani.com http://www.joelonsoftware.com/ http://remysharp.com/ Backbone http://stackoverflow.com/questions/5097956/correct-way-to-insert-a-view-with-backbone-js http://addyosmani.com/blog/building-spas-jquerys-best-friends/ http://joeybeninghove.com/2011/08/16/backbone-screencast-introduction-views/ http://backbonetutorials.com/ http://www.elfsternberg.com/2010/12/08/backbonejs-introducing-backbone-store/ http://peepcode.com/products/backbone-js http://dailyjs.com/2011/04/04/node-tutorial-19/ http://blog.paracode.com/2011/08/23/image-gallery-with-backbone/ http://oneofthesedaysblog.com/bac

Backbone.js models and jsonp

Checkout this gist and comments

Access Google doc as api

This is pretty cool, here's one way in a goolge doc, click Share ->Publish to Web click Start Publishing you can choose output format for spreadsheets e.g. html, csv, txt etc you'll see a url on the page, you can actually now hit that url This is where it gets cool, you can issue a curl command against that url and pipe to a file e.g. curl 'https://docs.google.com/spreadsheet/pub?hl=en_US&hl=en_US&key=<the_key>&output=csv' -o data.csv So you can curl a google doc onto a server!

Arrays as static properties in php

The syntax is a little strange (note the self::$..) below: // the space at the start of each value is required private static $httpResponseCodes = array('200' => ' 200 OK' , '400' => ' 400 Bad Request' , '401' => ' 401 Unauthorized' , '403' => ' 403 Forbidden' , '404' => ' 404 Not Found' , '408' => ' 408 Request Timeout' , '409' => ' 409 Conflict' , '500' => ' 500 Internal Server Error' , '503' => ' 503 Service Unavailable' ); public static function lookupHTTPResponse($code) { // if passed a code which does not exist then return 500 if (! isset(self::$httpResponseCodes[$code])) { $code = '500'; } return self::$httpResponseCodes[$code]; }

jQuery find all checkboxes checked

voila $('input:checkbox[checked]') You could do something like this to find all within tbody and then check the length of the resulting set ($('tbody input:checkbox[checked]').length == 0);

HTML Tables are ok in some circumstances

Image
Yes, indeed, HTML Tables are ok in some circumstances, for example: - laying out table data e.g. a list of items - laying out forms. I know you can float each label and then clear to go onto a new line. But I had a page which was using floats already to create left and right columns. Then within the right floated column I had some form controls. Frankly, the css got complicated. Everything was float: left, I used clear:left  and I had alot of css to set margins etc. I switched to using tables to layout the form data and it was a simpler solution, less "brittle" if layout had to change. Please see screenshot below for the result (still a work in progress). Remember to set table width, usually 100%. Otherwise table will resize to size of data. You can set widths of <th> columns to define the width of each column, using % or pixel. You can align text left, right as well as up and down. To do so, use text-align and vertical-align . You can use these css properties at

How to handle backbone.js model save() to PHP server

Well just as I was making nice progress saving model updates on the client, I ran into an issue: backbone.js by default for mode.save() will call HTTP PUT passing json data. Turns out php cannot handle that so well.  After checking the php superglobals to no avail, I found this post:   http://www.lornajane. net/posts/2008/Accessing- Incoming-PUT-Data-from-PHP Using this approach, I actually got the server side code to work and handle the default backbone.js model.save(). However its a bit convoluted and took some time to work it out. I think the better approach maybe to use a backbone switch as follows:  setting  Backbone. emulateJSON = true;  will cause the JSON to be serialized under a  model  parameter, and the request to be made with a application/x-www-form- urlencoded  mime type, as if from an HTML form" In that case, I can get the "model" param passed, urldecode it, json_decode it and use it as associative array. *Note: I since saw in backbone.js code comments

Supporting searches in Rest APIs

To use query parameters or not that is the question. Consider this post from StackOverflow  Notice that the first 2 answers identify two different approaches (nested url or query parameters) and support in the community is practically evenly split (22 vs 21). Google web services such as search make extensive use of query parameters. But I do note Google search is an algorithm which has to accommodate a large range of queries. Urls generally look and work (e.g. easier to remember, caching etc) better than query parameters but there is a point at which you get deeper and deeper into nested paths that it stops making sense and/OR search combinations become too complicated. At that point it makes sense to use query parameters. I refer to this book and quote:  "Query variables are perfectly acceptable for naming algorithmic resources"  The author makes the case for uris but explains there's also a place for query parameters, especially for algorithmic resources such as sea

Backbone.js, laravel, Mercurial and Amazon Web Services SimpleDB

Yeah! working with all of these technologies for a microsite, all new to me so stay tuned for progress updates. Backbone.js is more than powerful, it's a paradigm shift. An update 9/7/2011 Backbone.js - remember for each view method to include each method in the call to _.bindAll() so that this can be used - if I want to use regex in a Router it appears I have to manually add the route in initialize() e.g. this.route(/search/, "search", this.list); // matches url with /search in it and calls list() - be careful of what model/model events you bind views to; can have unintended consequences - backbone.js is a new framework, there are some examples and Q&A on stackoverflow but some questions are harder to answer. I would also like to see a little more in the documentation e.g. using regex in route - I think I created too many view classes for parts of the main list page. So I removed 2 views and just consolidated them into the main list view class. Other vie