Skip to content

Instantly share code, notes, and snippets.

View canuk's full-sized avatar

Reuben Thiessen canuk

  • Stanford University
  • Greater San Diego, CA
  • 14:18 (UTC -07:00)
  • LinkedIn in/reubenthiessen
View GitHub Profile
count = PFQuery.queryWithClassName("Noun").countObjects
query = PFQuery.queryWithClassName("Noun")
query.limit = 1
query.skip = rand(count) # for the non-Rubyists, this just finds a random int between 0 and `count`
query.findObjects.first
@kamens
kamens / knowledgemap.js
Created July 23, 2012 16:25
Knowledge Map file for Constellation Knowledge blog post
function KnowledgeMapInitGlobals() {
window.KnowledgeMapGlobals = {
colors: {
blue: "#0080C9",
green: "#8EBE4F",
red: "#E35D04",
gray: "#FFFFFF"
},
@mattbornski
mattbornski / timezone.md
Created March 29, 2012 22:36
Determine timezone from lat/long

Goal: To take this: https://graph.facebook.com/105464892820215 And derive this: America/Los Angeles From which we can then derive UTC-0800 or UTC-0700, as appropriate under the daylight madness scheme in effect on the date of interest.

It seems oddly hard to figure out what timezone a given point in space is located in. Looking around, there are only a few APIs which provide this information (http://www.earthtools.org/webservices.htm#timezone and http://www.worldweatheronline.com/time-zone-api.aspx), and only a few datasets which seem to contain it; most of them are in serious GIS formats, and expect you to query them in some manual fashion using a proprietary GIS tool.

I'm not really interested in that; I want a piece of code I can just ask "what timezone is this in" and get an answer, without installing some huge piece of software I don't have a license to or worrying about rate limits from somebody's API. So I'm going to take a shapefile I found here (http://efele.net/maps/tz/world/) and see if we can

@dblock
dblock / api_page_helper.rb
Created November 2, 2011 23:08
pagination helper with Grape
module ApiPageHelper
PAGINATE_OPTIONS = {
:default_page_size => 10
}
PAGINATE_PARAMS = [ "page", "offset", "size" ]
def paginate(coll, options = {})
options = PAGINATE_OPTIONS.merge(options)
if params[:page]
page = params[:page].to_i
size = (params[:size] || options[:default_page_size]).to_i