Skip to content

Instantly share code, notes, and snippets.

@tamalw
tamalw / gist:3297135
Created August 8, 2012 18:07
PostgreSQL performance
EXPLAIN ANALYZE
SELECT COUNT(*) FROM j_msg
Row QUERY PLAN
1 Aggregate (cost=1360105.49..1360105.50 rows=1 width=0) (actual time=140042.984..140042.985 rows=1 loops=1)
2 -> Seq Scan on j_msg (cost=0.00..1318772.99 rows=16532999 width=0) (actual time=8.377..137051.294 rows=16532999 loops=1)
3 Total runtime: 140057.576 ms
====
@tamalw
tamalw / rank.php
Created July 29, 2012 17:14
Faster cURL action!
<?php
$searchURL = "http://services.runescape.com/m=hiscore/overall.ws";
$perPage = 22;
$namesToReturn = 1;
for ($index = 1; $index <= $namesToReturn; $index++)
{
// $search = rand(1, 500000);
@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
@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 / 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 / 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 / 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 / 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 / .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 / 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