This file contains 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 doSomething(i, callback) { | |
console.log(i, 'doSomething before callback'); | |
// this is in fact synchronous, since don't use nextTick | |
callback(); | |
console.log(i, 'doSomething after callback'); | |
process.nextTick(function() { | |
// you might think this yeilds to the next "doSomething", | |
// but in fact it runs after everything else is done | |
console.log(i, 'nextTick'); | |
}); |
This file contains 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 EventEmitter = require('events').EventEmitter; | |
// Constructor emits before client subscribed | |
function StreamLibrary(resourceName) { | |
// should use process.nextTick here to delay the firing of the event | |
this.emit('start'); | |
// read from the file, and for every chunk read, do: | |
this.emit('data', chunkRead); | |
} | |
StreamLibrary.prototype.__proto__ = EventEmitter.prototype; // inherit from EventEmitter |
This file contains 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 doInner(i) { | |
console.log(i, 'doInner'); | |
process.nextTick(function() { | |
// runs after everything else is done | |
console.log(i, 'nextTick'); | |
}); | |
} | |
function doOuter(i) { | |
console.log(i, 'doOuter before inner'); |
This file contains 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
action = curry(goUp, 'hill') | |
[jack, jill].map(action) | |
for person in [jack, jill] | |
person.goUp('hill') |
This file contains 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
# put this in /Users/adam/Library/Application Support/Sublime Text 3/Packages/User/babelfish.py | |
import sublime, sublime_plugin | |
class Bablefish(sublime_plugin.EventListener): | |
def on_modified(self, view): | |
print(view.file_name(), "modified") | |
w = view.window() | |
This file contains 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
import SpriteKit | |
var str = "Hello, playground" | |
var dict : [String: String] = ["hi": "there"] | |
let productData = "{\"data\":[{\"url\": \"http://s2.img-b.com/build.com/imagebase/resized/330x320/moenimages/moen-tl182p-65.jpg\"}]}" | |
var error: NSError? |
This file contains 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
curl -d '{"name":"notch","agent":"minecraft"}' -H 'Content-Type: application/json' https://api.mojang.com/profiles | |
# http://skins.minecraft.net/MinecraftSkins/<USERNAME>.png for skin |
This file contains 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 CoffeeScript = require('coffee-script') | |
// CoffeeScript.register() | |
function requireCoffeeScript(relativePath) { | |
var path = require('path'); | |
var fs = require('fs'); | |
relativePath = path.resolve(__dirname, relativePath); | |
console.log('relativePath', relativePath); | |
This file contains 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 app = require('../server/app.js').create() | |
var gulp = require('gulp'); | |
var task = require('./index'); | |
/* | |
Output all the routes that the app supports | |
*/ | |
gulp.task('routes', function() { |
This file contains 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
<?php | |
$a = array(); | |
$b = $a; | |
// "When using the identity operator (===), object variables are identical | |
// if and only if they refer to the same instance of the same class." | |
if ($a === $b) print "same\n"; | |
$a['test'] = 'something'; |