Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env python
import sys
import math
import matfunc
import idmethod
import csv
for filename in sys.argv[1:]:
wdirlist=[]
function tab () {
CURRENT_RVM=$rvm_ruby_string
osascript 2>/dev/null <<EOF
tell application "System Events"
tell process "Terminal" to keystroke "t" using command down
end
tell application "Terminal"
activate
do script with command "cd $PWD; rvm $CURRENT_RVM; $*" in window 1
end tell
@tamalw
tamalw / clusterfuck.sql
Created December 15, 2010 17:50
I don't know what I was thinking…
SELECT
CAST(COALESCE(trans_online.headcount,0) + ((COALESCE(class_online.headcount,0) - (COALESCE(class_online.headcount,0) * COALESCE(nesting.nesting_percent,0)))) AS DECIMAL(6,2)) headcount
FROM training_classes
JOIN weeks
LEFT JOIN (SELECT x.training_class_id, y.start_on online_week, z.headcount FROM (SELECT a.training_class_id, MAX(b.start_on) start_on FROM training_class_forecasts a JOIN weeks b ON a.week_id = b.id WHERE a.headcount > 0 GROUP BY a.training_class_id) x JOIN weeks y ON x.start_on = y.start_on JOIN training_class_forecasts z ON x.training_class_id = z.training_class_id AND y.id = z.week_id) class_online ON class_online.training_class_id = training_classes.id AND training_classes.transition = 0 AND class_online.online_week = weeks.start_on - INTERVAL 7 DAY
LEFT JOIN (SELECT x.training_class_id, y.start_on online_week, z.headcount FROM (SELECT a.training_class_id, MAX(b.start_on) start_on FROM training_class_forecasts a JOIN weeks b ON a.week_id = b.id WHERE a.headcount > 0 GROUP BY a.trainin
@tamalw
tamalw / .irbrc
Created February 8, 2011 18:21
My .irbrc file
require 'rubygems'
require 'irb/ext/save-history'
IRB.conf[:SAVE_HISTORY] = 100
IRB.conf[:HISTORY_FILE] = "#{ENV['HOME']}/.irb-save-history"
IRB.conf[:AUTO_INDENT] = true
IRB.conf[:PROMPT_MODE] = :SIMPLE
begin
@tamalw
tamalw / summoning.rb
Created March 10, 2011 19:22
Old summoning calc
require 'ge'
player_name = "Firblitz"
blue_charms = 401
crimson_charms = 3510
green_charms = 1971
gold_charms = 4124
shards = 44562
@tamalw
tamalw / battlestaves2.rb
Created March 10, 2011 19:25
How many bstaffs can be bought from Zaff & the GE without losing money
require 'runescape'
days = 1
amount_per_day = 64
ge_limit_per_day = 600
bstaff_shop_cost = 7000
bstaff_alch_amt = 9300
battlestaff = Runescape::Item.new(1391)
@tamalw
tamalw / soulver.rb
Created March 10, 2011 20:27
Loads GE prices into Soulver's variables
require 'rubygems'
require 'open-uri'
require 'plist'
require 'hpricot'
variables_path = "#{ENV['HOME']}/Library/Application Support/Soulver/Variables.plist"
items = {
1391 => "Battlestaff",
573 => "Air orb",
@tamalw
tamalw / gist:1027536
Created June 15, 2011 16:53
PostgreSQL COUNT(*) performance
EXPLAIN ANALYZE
SELECT
COUNT(*)
FROM jivemessage
Row QUERY PLAN
1 Aggregate (cost=1085701.27..1085701.28 rows=1 width=0) (actual time=111295.699..111295.699 rows=1 loops=1)
2 -> Seq Scan on jivemessage (cost=0.00..1052949.61 rows=13100661 width=0) (actual time=10.628..108926.771 rows=13100661 loops=1)
3 Total runtime: 111295.761 ms
@tamalw
tamalw / js_key_example.html
Created September 14, 2011 04:51
JavaScript key bindings
<html>
<head>
<title>JS Key Example</title>
<script type="text/javascript">
addEventListener("keydown", function (e) {
var output = document.getElementById('output');
if (e.keyCode == 37) {
output.innerHTML = "You pressed left."
}
@tamalw
tamalw / dice.rb
Created July 15, 2012 06:52
Drop table calculator
class Item
attr_accessor :name, :odds
def initialize(name, odds)
@name = name
@odds = odds
end
end
class Dice