Skip to content

Instantly share code, notes, and snippets.

@aasmith
aasmith / javascript option stuff.js
Created August 14, 2010 22:34
black scholes & IV in javascript
/* Returns probability of occuring below and above target price. */
function probability(price, target, days, volatility) {
var p = price;
var q = target;
var t = days / 365;
var v = volatility;
var vt = v*Math.sqrt(t);
var lnpq = Math.log(q/p);
@border
border / googleFinance.py
Created October 28, 2011 07:03
Access Stock Quotes Realtime through Google Finance
import urllib2
import json
import time
# Form: http://digitalpbk.com/stock/google-finance-get-stock-quote-realtime
class GoogleFinanceAPI:
def __init__(self):
self.prefix = "http://finance.google.com/finance/info?client=ig&q="
def get(self,symbol,exchange):
@rkmax
rkmax / install-r15b.sh
Created December 14, 2011 20:59 — forked from ramgole/install-r14b04.sh
Script to install Erlang R15B (tested on a fresh Ubuntu 11.10 install)
# You will need to make this file executable (chmod u+x) and run it with sudo
apt-get -y install build-essential m4 libncurses5-dev libssh-dev unixodbc-dev libgmp3-dev libwxgtk2.8-dev libglu1-mesa-dev fop xsltproc default-jdk
mkdir -p /src/erlang
cd /src/erlang
wget http://www.erlang.org/download/otp_src_R15B.tar.gz
tar -xvzf otp_src_R15B.tar.gz
chmod -R 777 otp_src_R15B
cd otp_src_R15B
./configure
make
@femto113
femto113 / transpose.js
Last active September 6, 2023 00:28
one line transpose for 2-dimensional Javascript arrays
function transpose(a)
{
return a[0].map(function (_, c) { return a.map(function (r) { return r[c]; }); });
// or in more modern dialect
// return a[0].map((_, c) => a.map(r => r[c]));
}
@adammw
adammw / socks.js
Created February 14, 2012 16:21
Socks library snippet for Node.js
var net = require('net'),
util = require('util'),
EventEmitter = require('events').EventEmitter;
var SOCKSClient = module.exports = function() {
var args = normalizeConnectArgs(arguments);
this.state = 'connecting';
this.socket = net.connect(args[0].port, args[0].host, onConnect.bind(this));
this.socket.on('data', onData.bind(this));
this.socket.on('end', onEnd.bind(this));
// Includes functions for exporting active sheet or all sheets as JSON object (also Python object syntax compatible).
// Tweak the makePrettyJSON_ function to customize what kind of JSON to export.
var FORMAT_ONELINE = 'One-line';
var FORMAT_MULTILINE = 'Multi-line';
var FORMAT_PRETTY = 'Pretty';
var LANGUAGE_JS = 'JavaScript';
var LANGUAGE_PYTHON = 'Python';
@rbraband
rbraband / example 1
Created February 24, 2012 14:12
Howto implement stored procedures within Redis
# Step 0 -- create test data
redis-cli HSET :object:30343552:data foo bar
# Step 1 -- store sample function 'sampleFunction'
redis-cli SET :functions:sample "redis.call('SELECT', 0);local data=redis.call('HGETALL',':object:' .. ARGV[1] .. ':data');return data"
# Step 2 -- create function loader
redis-cli SCRIPT LOAD "f=loadstring(redis.call('get',':functions:' .. KEYS[1]));return f()"
# Step 3 -- test
@randylubin
randylubin / proxyServer
Created July 1, 2012 19:02
Node.js Multi-App Proxy Server with Forwarding
var http = require('http'),
httpProxy = require('http-proxy');
//
// Setup proxy server with forwarding
//
var options = {
router: {
'proxytest.randylubin.com': '127.0.0.1:7200',
'randylubin.com': '127.0.0.1:7200',
@abiank
abiank / android_emu_start.sh
Created November 12, 2012 08:15 — forked from stackedsax/android_emu_start.sh
Script for starting up multiple android emulators per box
#!/bin/bash
#####
#
# This script creates android emulators on the fly.
#
# Please refer to the README for usage instructions.
#
####
@spion
spion / screenshot.js
Last active May 27, 2022 01:38
Take website screenshots of any resolution using phantomjs
// Usage: phantomjs screenshot.js 1920x1080 site.domain.com
// outputs to site.domain.com-1920x1080.png
// dont add http to the URL
// If the page didnt render in time add a delay argument
// e.g. 3000 for 3 seconds
var page = require('webpage').create();
var args = require('system').args;
var wh = args[1].split('x');