Sometimes you'll have objects that manage state along with event handling. This happens frequently in MVC apps. Let's start with a messy example:
var Launcher = function(rocket) {
this.rocket = rocket
}
Launcher.prototype.isReady = function() {
| #!/usr/bin/env node | |
| var http = require('http') | |
| var options = { | |
| hostname: 'data.mtgox.com' | |
| , path: '/api/2/BTCUSD/money/ticker' | |
| , method: 'GET' | |
| } |
| import threading, websocket, json | |
| class mtgox( threading.Thread ): | |
| def run( self ): | |
| websocket.enableTrace( True ) | |
| url = 'wss://websocket.mtgox.com' | |
| self.socket = websocket.WebSocketApp( url, on_open = self.on_open ) | |
| self.socket.run_forever( ) | |
| def subscribe( self, channel ): |
| #!/bin/bash | |
| IN_FILE="$1" | |
| OUT_FILE="$4" | |
| CROP_W=$2 | |
| CROP_H=$3 | |
| SIZE=$(identify $IN_FILE | awk '{print $3}') | |
| IMAGE_W=${SIZE%%x*} | |
| IMAGE_H=${SIZE##*x} |
| // data comes from here http://stat-computing.org/dataexpo/2009/the-data.html | |
| // download 1994.csv.bz2 and unpack by running: cat 1994.csv.bz2 | bzip2 -d > 1994.csv | |
| // 1994.csv should be ~5.2 million lines and 500MB | |
| // importing all rows into leveldb took ~50 seconds on my machine | |
| // there are two main techniques at work here: | |
| // 1: never create JS objects, leave the data as binary the entire time (binary-split does this) | |
| // 2: group lines into 16 MB batches, to take advantage of leveldbs batch API (byte-stream does this) | |
| var level = require('level') |
| // Copyright © 2013 Darach Ennis. All rights reserved. | |
| // | |
| // Sample EEP/Beam AR drone integration. | |
| // Works with keyboard | |
| // Works with a makey makey - http://www.makeymakey.com/ | |
| // Coded during NodeConf EU but not demonstrated or tested ... | |
| // | |
| // Enjoy! | |
| // |
| #!/bin/bash | |
| echo 'dummy script' |
| import tweepy | |
| import time | |
| import re | |
| import pycoin.encoding | |
| import pickle | |
| # Removed security tokens from gist, replaced with XXX. | |
| auth = tweepy.OAuthHandler("XXX", "XXX") | |
| auth.set_access_token('XXX', 'XXX') |
| 147XRLaQjSQvDhf7Zxeh36toLJiuaPmMYY |
| from hashlib import sha256 | |
| digits58 = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz' | |
| def decode_base58(bc, length): | |
| n = 0 | |
| for char in bc: | |
| n = n * 58 + digits58.index(char) | |
| return n.to_bytes(length, 'big') | |