Skip to content

Instantly share code, notes, and snippets.

View kingcu's full-sized avatar

Cullen King kingcu

View GitHub Profile
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)
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,
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
@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);
@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: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: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: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:1133690
Created August 9, 2011 09:53
Bad POST with no form data
0000 00 22 15 85 ca b9 00 0e a6 99 ed 22 08 00 45 20 ."...... ..."..E
0010 01 21 3a 23 40 00 2e 06 18 49 d9 a8 5e f2 c0 a8 .!:#@... .I..^...
0020 00 08 c6 b7 0b b8 a7 db c6 c5 17 34 89 79 80 18 ........ ...4.y..
0030 ff ff ba 1d 00 00 01 01 08 0a 15 2a eb 43 0f 47 ........ ...*.C.G
0040 0c de 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 48 6f 73 on HTTP/ 1.1..Hos
0060 74 3a 20 68 6f 62 62 65 7a 2e 6e 65 74 3a 33 30 t: hobbe z.net:30
0070 30 30 0d 0a 41 63 63 65 70 74 2d 45 6e 63 6f 64 00..Acce pt-Encod
0080 69 6e 67 3a 20 67 7a 69 70 0d 0a 58 2d 52 65 71 ing: gzi p..X-Req
0090 75 65 73 74 65 64 2d 57 69 74 68 3a 20 58 4d 4c uested-W ith: XML
kingcu@desktop:~/ridewithgps$ nslookup -q=txt _domainkey.ridewithgps.com
Server: 192.168.0.1
Address: 192.168.0.1#53
Non-authoritative answer:
_domainkey.ridewithgps.com text = "t=y\; o=-"
Authoritative answers can be found from:
kingcu@desktop:~/ridewithgps$ nslookup -q=txt mail._domainkey.ridewithgps.com