Skip to content

Instantly share code, notes, and snippets.

@ralphtheninja
ralphtheninja / goxticker.js
Created April 27, 2013 11:43
Simple cli ticker that fetches data from MtGox. Run with node, no extra modules needed.
#!/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 ):

Put a closure on it

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() {

@ralphtheninja
ralphtheninja / crop.sh
Created August 17, 2013 23:57
./crop.sh foo.png 100 100 out.png Crops foo.png by a centered 100 100 rect and stores the result in out.png
#!/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
@ralphtheninja
ralphtheninja / base58.py
Last active January 4, 2016 04:19
Base58.py checking decode of '1' and '11' etc
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')