This gist is part of a blog post. Check it out at:
http://jasonrudolph.com/blog/2011/08/09/programming-achievements-how-to-level-up-as-a-developer
| var sDate = new Date() | |
| , today = new Date() | |
| , str = "" | |
| , node; | |
| sDate.setFullYear(2011, 0, 1); | |
| if (sDate > today) { | |
| str = sDate.getFullYear() } | |
| else { |
| var http = require('http'); | |
| var fs = require('fs'); | |
| var url = require('url'); | |
| var settingsPath='settings2.json'; | |
| var Server = function(path){ | |
| this.readSettings(path); | |
| } |
| // put inside a .js file, referenced on the page by the resource's URI | |
| // Create a local variable to hold `jQuery', so you type less. | |
| // Using $ is stupíd, since that symbol is (by ES5 specs) reserved for | |
| // machine-generated code. | |
| void function(j) { | |
| function get_data() { | |
| // use functions to abstract code sections | |
| function get_item(i) { return data[i].high + '<br>' + ~~(Math.random() * 111) } | |
| function update(idx) { return j('#high').html(get_item(idx)) } | |
| function process(data){ return j.each(data, update) } |
| var a = {}; | |
| a.foo = function() { | |
| return "foo"; | |
| } | |
| a.bar = function() { | |
| return "bar"; | |
| } |
This gist is part of a blog post. Check it out at:
http://jasonrudolph.com/blog/2011/08/09/programming-achievements-how-to-level-up-as-a-developer
| // create an array of terms from an array of objects | |
| for item in trend.search_terms | |
| search_terms.push(item.term) | |
| // while a part of the array is left | |
| while search_terms.length > 0 | |
| // create a mini array of 7 items | |
| for num in [0..7] |
| // A response to jashkenas's fine proposal for minimalist JavaScript classes. | |
| // Harmony always stipulated classes as sugar, so indeed we are keeping current | |
| // JavaScript prototype semantics, and classes would only add a syntactic form | |
| // that can desugar to ES5. This is mostly the same assumption that Jeremy | |
| // chose, but I've stipulated ES5. | |
| // Where I part company is on reusing the object literal. It is not the syntax | |
| // most classy programmers expect, coming from other languages. It has annoying | |
| // and alien overhead, namely colons and commas. For JS community members who |
| var pubsub = { | |
| // A map of event names to the listeners attached to it. | |
| // :: { "String" -> [Function] } | |
| events: { } | |
| // Notifies all the listeners of an event | |
| // :: String, a... -> Undefined | |
| , pub: function(event) { | |
| var events = this.events[event] || [] | |
| var args = arguments |
| void function(root){ | |
| var Point = boo.Base.derive({ | |
| init: | |
| function(x, y) { | |
| this.x = x | |
| this.y = y | |
| return this } | |
| , fromPoint: |
| /** | |
| * Applies a set of named arguments to a `func`. | |
| * | |
| * Example: var f = function(x, y, z) { return x * (y - z); }; | |
| * namedApply(f, {x: 1, y: 2, z: 3}); | |
| * | |
| * @param f {Function} A function to invoke. | |
| * @param args {Object} A collection of named arguments. | |
| * @return {Function} A new function with partially applied named arguments. | |
| */ |