Skip to content

Instantly share code, notes, and snippets.

@jsundram
jsundram / create.txt
Created October 15, 2011 18:47
Create Table
CREATE TABLE sqf_2010
(
id serial,
year text,
pct text,
ser_num text,
datestop text,
timestop text,
recstat text,
inout text,
@jsundram
jsundram / sqrt.cpp
Created November 5, 2011 16:19
Newton-Raphson square root implementation
double root_NR(double n, double epsilon=.0000000001)
{
if (n < 0) return 0.0; // throw?
// http://mathworld.wolfram.com/SquareRootAlgorithms.html
// Both Bhaskara-Brouncker and Newton's iteration use
// (1 + n) / 2 instead of just guessing n/2.
double r = 0.5 + 0.5 * n;
double f = r*r - n;
while (epsilon < abs(f))
// code taken from here:
// http://www.analogpixel.org/blog/2011/09/13/msced-148-boxy-lady-take-2/#more-764
// and formatted for readability.
PImage pic1;
PGraphics pg;
boolean grow;
int box_size;
int MAXS = 40;
int MINS = 1;
@jsundram
jsundram / read.py
Created February 26, 2012 19:21
Read a shapefile and find out which shape contains a given lat-lng
import json
from collections import defaultdict
from itertools import izip
from rtree import index
import shapefile
def read_shapefile(shape_dir):
sf = shapefile.Reader(shape_dir)
shapes = {}
for (s, sr) in izip(sf.shapes(), sf.shapeRecords()):
@jsundram
jsundram / parse.clj
Last active October 1, 2015 14:38
transaction parser
(ns transparse.core
(:import [clojure.java.io])
;;(:import [java.lang.Float])
(:require [clojure.string :as string])
(:require [clj-time.format :as form])
(:gen-class))
(defn to-fields [line]
(string/split
(string/trim line) #"\\t"))
@jsundram
jsundram / clock.pjs
Created March 12, 2012 17:37
draw numbers on the face of a clock (text rotation, basically)
// see it live here: http://sketchpad.cc/wkAzMXfKbD
PFont font;
void setup()
{
size(600, 600);
font = loadFont("Courier", 22);
noLoop();
}
@jsundram
jsundram / text.py
Created March 30, 2012 14:53
print wordle.net-type output for some input sentences
import string
import nltk
from collections import defaultdict
stopwords = set(nltk.corpus.stopwords.words('english'))
def get_sentences():
sentences = []
with open('/Volumes/data-1/files/topicana/cs_nps_comments_cat.txt') as f:
for line in f:
sentences.append(line.split('\t')[-1])
@jsundram
jsundram / colors.pjs
Created April 3, 2012 22:11
D3 colors for processing.js
color[] d3_10 = [#1f77b4, #ff7f0e, #2ca02c, #d62728, #9467bd, #8c564b, #e377c2, #7f7f7f, #bcbd22, #17becf];
color[] d3_20 = [#1f77b4, #aec7e8, #ff7f0e, #ffbb78, #2ca02c, #98df8a, #d62728, #ff9896, #9467bd, #c5b0d5, #8c564b, #c49c94, #e377c2, #f7b6d2, #7f7f7f, #c7c7c7, #bcbd22, #dbdb8d, #17becf, #9edae5];
color[] d3_20b = [#393b79, #5254a3, #6b6ecf, #9c9ede, #637939, #8ca252, #b5cf6b, #cedb9c, #8c6d31, #bd9e39, #e7ba52, #e7cb94, #843c39, #ad494a, #d6616b, #e7969c, #7b4173, #a55194, #ce6dbd, #de9ed6];
color[] d3_20c = [#3182bd, #6baed6, #9ecae1, #c6dbef, #e6550d, #fd8d3c, #fdae6b, #fdd0a2, #31a354, #74c476, #a1d99b, #c7e9c0, #756bb1, #9e9ac8, #bcbddc, #dadaeb, #636363, #969696, #bdbdbd, #d9d9d9];
@jsundram
jsundram / videocolorbars.py
Created April 14, 2012 16:54
Adapt Benoit Romito's video color bars (described here: http://bromito.perso.info.unicaen.fr/wiki/index.php/wiki/page/barcodes) to work with ffmpeg thumbnailer
#!/usr/bin/python
#-*- coding: utf-8 -*-
# This script computes a the Color Bars of a video.
# Copyright (C) 2011 Benoit Romito
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
@jsundram
jsundram / find_password_hash.py
Created June 6, 2012 16:08
Check if your password is in the linkedin password dump.
"""
Check if your password is in the linkedin password dump.
You'll need to download the dump from here:
https://disk.yandex.net/disk/public/?hash=pCAcIfV7wxXCL/YPhObEEH5u5PKPlp+muGtgOEptAS4=
and unzip it to combo_not.txt
"""
import hashlib
# TODO: May want to use getpass if someone might be reading over your shoulder