This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var sys = require('sys'); | |
| function Child() {} | |
| // Defined on the prototype. | |
| Object.defineProperty(Child.prototype, 'foo', { enumerable: false, value: 'test', writable: true }); | |
| Object.defineProperty(Child.prototype, 'bar', { enumerable: false, value: 'test2', writable: true }); | |
| var test = new Child; | |
| // Defined local to the object "instance". | |
| Object.defineProperty(test, 'baz', { enumerable: false, writable: true }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var http = require('http'); | |
| var secure = new RegExp('(' + [ | |
| 'facebook.com', | |
| 'twitter.com', | |
| 'google.com' | |
| ].join('|').replace('.', '\\.') + ')$'); | |
| var noSecure = new RegExp('^(' + [ | |
| 'http://(www\.)?google\.com/(image|imghp)', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| > function Class(param) { if (!param) console.log('fail'); } | |
| > new Class | |
| fail | |
| {} | |
| > x = {}; | |
| {} | |
| > x.__proto__ = Class.prototype; | |
| {} | |
| > x instanceof Class | |
| true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var util = require('util'); | |
| function Parent(arg) { | |
| console.log('parent constructor: arg=' + arg); | |
| } | |
| Parent.prototype.foo = function() { | |
| console.log('fooing!'); | |
| return this; | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Object.defineProperty(global, 'foo', { | |
| set: function(val) { | |
| console.log(val); | |
| } | |
| }); | |
| var array = { key: 'value', key2: 'value2', key3: 'value3' }; | |
| for (foo in array); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $(function() { | |
| function pushState() { | |
| var url = $(this).attr('href'); | |
| replaceImage(url); | |
| if (history.pushState) { | |
| history.pushState({}, '', url); | |
| } | |
| return false; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| json() { | |
| python - $@ <<"EOS" | |
| import json, sys | |
| try: | |
| obj = json.load(open(sys.argv[1])) | |
| for key in sys.argv[2:]: obj = obj[key if type(obj) == dict else int(key)] | |
| except ValueError as msg: sys.stderr.write('Invalid JSON: %s\n' % msg); exit(1) | |
| except KeyError as msg: sys.stderr.write('Key "%s" does not exist\n' % key); exit(2) | |
| if type(obj) == dict: print '\n'.join(obj.keys()) | |
| elif type(obj) == list: print '\n'.join(obj) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #world { | |
| polygon-fill: #eee; | |
| line-color: #ccc; | |
| line-width: 1; | |
| [zoom > 5] { | |
| line-width:0.5; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function __stack__() { | |
| try { | |
| throw new Error; | |
| } catch (err) { | |
| var stack = err.stack.split('\n'); | |
| stack.splice(0, 3); | |
| return stack.join('\n') + '\n'; | |
| } | |
| } | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var util = require('util'); | |
| var EventEmitter = require('events').EventEmitter; | |
| module.exports = Queue; | |
| function Queue(callback, concurrency) { | |
| this.callback = callback; | |
| this.concurrency = concurrency || 10; | |
| this.next = this.next.bind(this); | |
| this.invoke = this.invoke.bind(this); | |
| this.queue = []; |
OlderNewer