Skip to content

Instantly share code, notes, and snippets.

View aasmith's full-sized avatar

Andrew A Smith aasmith

View GitHub Profile
@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);
@aasmith
aasmith / Gemfile
Created September 13, 2010 19:21
Rails 3 bootstrap
# bootstrap a new rails 3.0 project from the 3-0-stable branch
#
# mkdir new_project
#
# place this Gemfile in new_project
#
# bundle install --path .gems
# bundle exec rails -v
# bundle exec rails new .
#
@aasmith
aasmith / option_calendar.rb
Created September 26, 2010 19:22
Option expiry date calculator
# Extracted this code out that was not needed.
# Keeping here for future reference.
#
# Finds upcoming expiry dates for monthly equity options.
#
# Test data is the official CBOE expiration calendars for 2010/11.
require 'date'
require 'rubygems'
@aasmith
aasmith / noscale.rb
Created May 5, 2011 18:24
Why ruby can't scale to the enterprise
def tries
@tries ||= 1
(@tries += 1) - 1
end
@aasmith
aasmith / usbank.js
Created May 23, 2011 16:24
Capture OFX for USBank
// inject jquery
var head = document.getElementsByTagName("head")[0];
var newScript = document.createElement('script');
newScript.type = 'text/javascript';
newScript.src = 'http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js';
newScript.onload = function() { head.removeChild(newScript); modifyDom() };
head.appendChild(newScript);
@aasmith
aasmith / app.rb
Created September 5, 2011 16:49
async sinatra - comet
require "rubygems"
require "sinatra/base"
require "sinatra/async"
require "redis"
module CometTest
class App < Sinatra::Base
register Sinatra::Async
puts ">> #{REDIS = Redis.new(:thread_safe => true)}"
@aasmith
aasmith / reload-chrome.sh
Created December 3, 2012 04:45
Reload the current chrome tab when vim saves (unix/X)
#!/bin/bash
# Add this script to your ~/bin (ensure in $PATH) and chmod +x.
# Requires xdotool.
#
# Add this to your vimrc:
# " reload chrome on html/css/js save
# au BufWritePost *.{html,css,js} silent !reload-chrome.sh
CUR=$(xdotool getwindowfocus)
WID=$(xdotool search --onlyvisible --class "google-chrome" | sort -n | head -1)
@aasmith
aasmith / refresh.applescript
Created December 11, 2012 21:53
Reload safari when vim saves (OSX)
tell application "Safari"
activate
do JavaScript "window.location.reload();" in first document
end tell
tell application "MacVim" to activate
@aasmith
aasmith / monitor-off.rbw
Last active October 19, 2020 02:58
Turns off all monitors in Windows using the Win32 API.
# Send all monitors to power saving mode (standby) using the WIN32 API.
#
# Documentation for WM_SYSCOMMAND & SC_MONITORPOWER:
# http://msdn.microsoft.com/en-us/library/windows/desktop/ms646360(v=vs.85).aspx
require 'fiddle'
require 'fiddle/import'
require 'fiddle/types'
module User32
extend Fiddle::Importer
@aasmith
aasmith / goof.rb
Last active December 10, 2015 13:08
Goofspiel!
# Generate all possible combinations for a 46-point win in the game of
# Goofspiel.
#
cards = [*1..13]
res = [*4..13].map do |n|
cards.combination(n).
select { |cards| cards.reduce(:+) == 46 }.
map(&:sort).
map(&:reverse)