(function($){ $.fn.extend({ yourPluginName: function(options) { var defaults = { yourDefaults: ‘here’, anotherDefault: ‘here’ } // This way, what you pass as args overwrite your defaults: var options = $.extend(defaults, options); returnselect; […]
Monthly Archives: February 2013
HTML5: Form fields
New attributes: autofocus=”autofocus” required=”required” oninput=”updateMessage(this)” /* You can run custom JS on input */ autocomplete=”on” // Remembers what the users enter in the field before, and makes it available for autofill. If you want to create your own list of autofill values: Choose an animal: <input type=”text” name=”animal” list=”animals” /><br /> <datalist id=”animals”> <option value=”Moneky”> […]
node.js: API
global — The equivalent of window in the browser. process.nextTick(cbfunction); // Schedule a function callback for the next time the loop goes around console.log and console.error // Same as in firebug
node.js: how it is different from other web platforms
Node has a single thread, looping on itself to handle requests. Unlike PHP and other platforms, where each request spawn its own thread. This means: if a request modify a variable with global scope, the modified variable will be served in the next request. Node process in a nutshell: loop taking request (running in infinite […]
Rails and devise: building associations at record creation time
In your “create” method, on your controller: @search = current_user.searches.build(params[:search]) Assumes: current_user contains your user record (via devise) search, searches is the model of the record you are trying to create build is just there to marshal your posted form parameters, so no need to include them (RoR is magical like that) current_user.searches is building […]
Python: control structures
a = [0, 1, ‘hello’, ‘python’] for i in a: print i for i, j in enumerate(a): print i, j // Same as above, but prints the index while i < 10: i = i + 1 break and continue can be used to break out of the list if i == 0: print ‘zero’ […]
Node.js: the basics
Install node.js (no need to be verbose, see website for more details) $ node -v // Verify installation Install the NPM (node package manager, this will allow you to install and manage node packages): $ curl http://npmjs.org/install.sh | sh $ npm –version // Verify version and installation of package manager Creating your application and installing […]
Heroku: handy, useful commands
// In case errors happen… $ heroku logs –tail $ git push heroku master // Push local changes $ heroku run rake db:migrate // Push your new local db migrations to Heroku
Ruby On Rails: barebones site template from the ground up.
We are talking about quick demos, site bootstraping kind of deal here. So don’t expect robust, detailed explanations. Also, assuming you have Ruby / Rails / Git / postgresql / RVM (optional) installed. Barebones, cutting through most of the commands explanations. Aim to push site and ideas fast out there. $rails new first_app -d postgresql […]
Jquery mobile: the basics
Basic page structure: <div data-role=”page”> <div data-role=”header”></div> <div data-role=”content”></div> <div data-role=”footer”></div> </div> Since links are internal (load a different part of your template), in order to call real external links, you need: Rel=”external” or data-ajax=”false” To implement a back button, you do: data-rel=”back” To implement dialogs (modals) instead of opening the page: data-rel=”dialog”, data-rel=”back” (to close […]