Skip to content

Instantly share code, notes, and snippets.

View sri's full-sized avatar

Sriram Thaiyar sri

  • Bay Area, CA
View GitHub Profile
@sri
sri / gist:971922
Created May 14, 2011 04:35
mongo db
http://www.10gen.com/video/mongosv2010/intro
mongo - shell
mongod, mongos - db w/ sharding
db has collection of documents
bson for fast scanability - think 2mb json string
bson can store binary data (no need to do base64)
@sri
sri / gist:971925
Created May 14, 2011 04:41
sort confreaks events by most views
require 'open-uri'
event = ARGV[0] || "rubyconf2010"
open("http://confreaks.net/events/#{event}").
read.
scan(/<div class='main-info'>.*?<div class='clear'><\/div>/im).
map { |x|
url, title = x.scan(/<div class='title'>.*?<a href="([^"]*)">([^<]*)<\/a>/im).flatten
presenters = x.scan(/<div class='presenters'>.*?<\/div>/im)[0].gsub(/<[^>]*>/, '').
gsub(/\n/, '')
views = x.scan(/Views:.*?([\d,]+)/im).flatten[0].gsub(/,/, '').to_i
@sri
sri / gist:973965
Created May 16, 2011 05:09
mv_ldown.js -- port of mv_ldown.rb to Node javascript
#! /usr/bin/env node
var path = require('path'),
fs = require('fs')
var userhome = process.env['HOME'],
downloadsDir = path.join(userhome, 'Downloads'),
downloads = fs.readdirSync(downloadsDir),
all = []
@sri
sri / gist:2512600
Created April 27, 2012 20:20
Find the distance between two addresses (uses Google Maps API)
#! /usr/bin/env coffee
Http = require 'http'
Number::toRad = -> this * (Math.PI / 180)
# http://www.movable-type.co.uk/scripts/latlong.html
haversine = (p, q) ->
R = 6371
latDist = (q.lat - p.lat).toRad()
@sri
sri / gist:5305691
Last active December 15, 2015 18:39
Clojure RPN version
(ns user (:use clojure.pprint))
(def all-known-operators {})
(defn op-known? [op]
(contains? all-known-operators op))
(defn op-eval [op stack size]
(let [fn (get all-known-operators op)]
(when fn
@sri
sri / tour_69.go
Last active December 15, 2015 22:59
// sri's solution for http://tour.golang.org/#69
// Exercise: Equivalent Binary Trees
package main
import (
"code.google.com/p/go-tour/tree"
"fmt"
)
#!/usr/bin/java -Xmx2G -jar
# Self executing Jar file
[JAR FILE]
;; Whitespace
(setq whitespace-style
(remove 'newline
(remove 'newline-mark whitespace-style)))
;; Selective Display:
;; http://www.gnu.org/software/emacs/manual/html_node/emacs/Selective-Display.html#Selective-Display
@sri
sri / gist:6802525
Last active December 24, 2015 13:09
Emacs Search & Replace
Emacs Buffer Search
==================================================
Incremental Search Forward - (default C-s; C-f for me)
Incremental Search Backward - (default C-r; C-f C-r for me)
Regexp Incremental Search Forward (default C-M-s)
Regexp Incremental Search Backward (default C-M-s)
Occur (default M-s o):
Search lines in a buffer matching a pattern and output in another buffer.