Skip to content

Instantly share code, notes, and snippets.

View paulkaplan's full-sized avatar

Paul Kaplan paulkaplan

View GitHub Profile
@paulkaplan
paulkaplan / font-scaling.js
Created August 4, 2011 00:13
Scaling $(body) font-size to window size
$(document).ready(function() {
var $body = $('body'); //Cache this for performance
var setBodyScale = function() {
var scaleSource = $body.width(),
scaleFactor = 0.9,
maxScale = 1000,
minScale = 30;
var fontSize = scaleSource * scaleFactor;
@paulkaplan
paulkaplan / gist:1203651
Created September 8, 2011 15:19
Don't render layout on ajax call (for fancybox or the like
layout proc {|controller| controller.request.xhr? ? false : "application" }
@paulkaplan
paulkaplan / email_to_name.rb
Created October 5, 2011 04:05
API for accessing full names from CNet ID's
require 'nokogiri'
cnet = ARGV[0]
raw = `curl -d "cnetid=#{cnet}&commit=Search" http://directory.uchicago.edu/`
doc = Nokogiri::HTML( raw )
name = doc.xpath('//td[@headers="fullname"]').text
puts name
@paulkaplan
paulkaplan / name_histogram.rb
Created October 5, 2011 04:07
Get alphabetical histogram from census data (census.gov/genealogy/name
f = File.open("dist.all.last", 'r')
full = []
h = {}
last = 0
while( line = f.gets )
data = []
line.split(" ").each {|x| data << x}
full << data
@paulkaplan
paulkaplan / tranloc.rb
Created October 30, 2011 03:39
Track UChicago local bus system using defined 'stops'
# TODO html/jquery for getting all the points on the route
require 'yaml'
require 'json'
require 'open-uri'
require 'redis'
ROUTE = 1000299
ERROR = 0.0001 #This is radial wiggle room for arriving buses, in lat/lng
@paulkaplan
paulkaplan / get_map_points.html
Created October 30, 2011 05:49
Google Map click generates marker and yaml with coordinates
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<style type="text/css">
html { height: 100% }
body { height: 100%; margin: 0; padding: 0 }
#map_canvas { height: 100% }
</style>
<script type="text/javascript"
@paulkaplan
paulkaplan / reminder_time.rb
Created November 1, 2011 03:37
Hash features of a natural language time declaration
class String
def scan_first(pattern)
a = self.scan(pattern)
a = a.first while a.is_a? Array unless a.empty?
return a
end
end
time_tokens = {}
given = ARGV[0]
@paulkaplan
paulkaplan / listing.c
Created November 22, 2011 19:39
Requesting and parsing json data from rails app in objective-c
+(NSMutableArray *) loadRemoteListings {
NSMutableArray *listings = [NSMutableArray arrayWithCapacity:20];
NSURL *url = [[NSURL alloc] initWithString:@"http://localhost:3000"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
NSURLResponse *response;
NSError *error;
@paulkaplan
paulkaplan / listing.c
Created November 22, 2011 19:39
Requesting and parsing json data from rails app in objective-c
+(NSMutableArray *) loadRemoteListings {
NSMutableArray *listings = [NSMutableArray arrayWithCapacity:20];
NSURL *url = [[NSURL alloc] initWithString:@"http://localhost:3000"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
NSURLResponse *response;
NSError *error;
@paulkaplan
paulkaplan / listing.c
Created November 22, 2011 19:43
Post listing to rails app with Devise token-authenticable from Objective-C
// QUESTION: For some reason Devise only sees auth token when passed through url not as param
// WHY? this seems really insecure...
-(NSString *) concatURL {
NSString *base = @"http://localhost:3000";
NSString *auth = [[NSUserDefaults standardUserDefaults] objectForKey:@"token"];
return [NSString stringWithFormat:@"%@?auth_token=%@", base, auth];
}
-(NSDictionary *) postListing {