Skip to content

Instantly share code, notes, and snippets.

View kingcu's full-sized avatar

Cullen King kingcu

View GitHub Profile
@kingcu
kingcu / gist:1133688
Created August 9, 2011 09:50
Proper POST with bad form data
0000 00 22 15 85 ca b9 00 0e a6 99 ed 22 08 00 45 20 ."...... ..."..E
0010 01 43 4f 1e 40 00 36 06 9a c9 d8 da c0 22 c0 a8 .CO.@.6. ....."..
0020 00 08 b9 bd 0b b8 2a ff 69 78 ff fc 27 b3 80 18 ......*. ix..'...
0030 00 2e c2 f0 00 00 01 01 08 0a c6 b9 26 72 0f 47 ........ ....&r.G
0040 d9 8c 50 4f 53 54 20 2f 75 73 65 72 73 2e 6a 73 ..POST / users.js
0050 6f 6e 20 48 54 54 50 2f 31 2e 31 0d 0a 55 73 65 on HTTP/ 1.1..Use
0060 72 2d 41 67 65 6e 74 3a 20 63 75 72 6c 2f 37 2e r-Agent: curl/7.
0070 32 31 2e 30 20 28 78 38 36 5f 36 34 2d 70 63 2d 21.0 (x8 6_64-pc-
0080 6c 69 6e 75 78 2d 67 6e 75 29 20 6c 69 62 63 75 linux-gn u) libcu
0090 72 6c 2f 37 2e 32 31 2e 30 20 4f 70 65 6e 53 53 rl/7.21. 0 OpenSS
@kingcu
kingcu / gist:1088586
Created July 18, 2011 05:03
simple kmeans clusterer for geo objects
class KMeans
attr_reader :clusters
def initialize(max=nil)
@max_iterations = max
end
def build(points, number_of_clusters)
@points = []
points.each do |pt|
@kingcu
kingcu / gist:1036943
Created June 21, 2011 00:19
Ugh, ghetto
def potentially_convert_pois_to_coursepoints_if_necessary(track)
return if track[:pois].nil? or track[:pois].length == 0
#if we have both POI and coursepoints, we can assume the POI
#are legitimate, else they would have been parsed as coursepoints
return if track[:course_points] && tracl[:course_points].length > 0
eps = 0.0001 #11 feet
to_keep = []
track[:pois].each do |poi|
next if poi[:n].blank? && poi[:d].blank?
@kingcu
kingcu / gist:1036565
Created June 20, 2011 20:58
Mailinator - email processing server, listens for emails pipes over socket, enqueues email to Resque to be processed
require 'logger'
require 'socket'
require 'tempfile'
require 'rubygems'
require 'bundler/setup' #so we can require gems in the Gemfile
require 'resque' #in Gemfile, allowed to require by bundler/setup
require 'app/workers/email_worker'
@num_workers = 2
@sleep_time = 10
@kingcu
kingcu / gist:1030604
Created June 16, 2011 23:55
Handy Ruby I18n style javascript interpolation class
Translations = {
translations: {},
load: function(trans) {
this.translations = this.translations || {};
for(attr in trans) { this.translations[attr] = trans[attr] }
},
t: function(key, interp) {
var t = this.translations[key];
if(interp === undefined) return t;
if(typeof t == "string") return this.interpolate(t, interp);
if route.save
#add already saved photos to the route
if params[:new_planner]
to_parse = []
if route_data['course_points'] and route_data['course_points'].length > 2
to_parse << JSON.parse(route_data['course_points'])
end
if route_data['points_of_interest'] and route_data['points_of_interest'].length > 2
to_parse << JSON.parse(route_data['points_of_interest'])
end
rwgps.Icon = function() {}
rwgps.Icon.prototype = {
icon: null,
shadow: null,
marker: null,
init: function(latlng, map) {
this.marker = new google.maps.Marker({
position: latlng,
map: map.gmap,
def self.add_online_user(id)
@redis ||= Redis.new
@redis.set("user:id:#{id}:last_activity", Time.now.to_i)
@redis.set_add("onlineusers", id);
end
def self.remove_online_user(id)
@redis ||= Redis.new
@redis.del("user:id:#{id}:last_activity")
@redis.set_rem("onlineusers", id)