Skip to content

Instantly share code, notes, and snippets.

View rmetzler's full-sized avatar
💭
Recruiters should mention the role and salary range if you spam me.

Richard Metzler rmetzler

💭
Recruiters should mention the role and salary range if you spam me.
View GitHub Profile
@rmetzler
rmetzler / natural_dates.rb
Created November 5, 2012 22:47 — forked from remi/natural_dates.rb
Natural Dates in Ruby
#!/usr/bin/env ruby
require "date"
class Fixnum
Date::MONTHNAMES[1..-1].each_with_index do |month, index|
define_method month.downcase do |year|
Date.new(year, index+1, self)
end
end
end
@rmetzler
rmetzler / gist:3075517
Created July 9, 2012 09:58 — forked from adamcharnock/gist:389875
redis fulltext indexing from playnice.ly
import re
# http://atomboy.isa-geek.com/plone/Members/acoil/programing/double-metaphone
from metaphone import dm as double_metaphone
# get the Redis connection
from jellybean.core import redis
import models
# Words which should not be indexed
@rmetzler
rmetzler / compl1.rb
Created July 8, 2012 14:33 — forked from antirez/compl1.rb
Redis autocomplete example
# compl1.rb - Redis autocomplete example
# download female-names.txt from http://antirez.com/misc/female-names.txt
require 'rubygems'
require 'redis'
r = Redis.new
# Create the completion sorted set
if !r.exists(:compl)
@rmetzler
rmetzler / redis_autocomplete.py
Created July 8, 2012 14:31 — forked from shon/redis_autocomplete.py
Redis | Searching names
# Search usernames that begins with given phrase
#
# usernames: (username1, username2, ..)
# userscore:<username>: float
# user:obj: { id: int, username: string }
usernames_zset = "usernames"
def my_ord(c):
return "%03d" % ord(c)
@rmetzler
rmetzler / gist:3066779
Created July 7, 2012 15:01 — forked from CastIrony/gist:3056322
hack to test you UI for rumored 7.8" iPads
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.viewController = [[JBViewController alloc] initWithNibName:@"JBViewController" bundle:nil];
self.window.rootViewController = self.viewController;
// ADD THIS LINE:
[self.window setTransform:CGAffineTransformMakeScale(0.81, 0.81)];
@rmetzler
rmetzler / gist:3035331
Created July 2, 2012 19:58 — forked from jrochkind/gist:2636355
reddit 'hot' algorithm, in ruby, with typo fixed
require 'date'
# Actually doesn't matter WHAT you choose as the epoch, it
# won't change the algorithm. Just don't change it after you
# have cached computed scores. Choose something before your first
# post to avoid annoying negative numbers. Choose something close
# to your first post to keep the numbers smaller. This is, I think,
# reddit's own epoch.
$our_epoch = Time.local(2005, 12, 8, 7, 46, 43).to_time
@rmetzler
rmetzler / app.rb
Created July 2, 2012 09:58 — forked from scttnlsn/app.rb
Sinatra/Mongoid RESTful resource
require 'mongoid'
require 'sinatra'
require_relative 'resource'
class Example
include Mongoid::Document
field :name
field :created, :type => DateTime
@rmetzler
rmetzler / backbone-jsonp.js
Created May 3, 2012 10:40
inherited jsonp support for backbone
// here is a simple example of overriding the base backbone collection class to enable default jsonp support
// i am using the github api as an example. you can obviously modify (or not) the url to suit your needs
var username = 'catshirt';
Backbone.Collection = Backbone.Collection.extend({
sync: function(method, model, options) {
options.dataType = 'jsonp';
options.url = _.sprintf('https://api.github.com%s', this.url);
return Backbone.sync(method, model, options);
@rmetzler
rmetzler / hackathons101.md
Created April 30, 2012 11:46 — forked from csanz/hackathons101.md
Hackathons 101

Summary

Just some quick notes on how to create a hackathon, super simple really.

Sponsors & Judges

  • Prepare one page summary of the event (Name, venue, audience numbers)
  • Reach out to tech evangelist from various companies, offer 10 minutes to pitch their APIs (skype or in person)
  • Reach out to influential hackers to be judges and includes sponsors
@rmetzler
rmetzler / uri.js
Created April 21, 2012 10:09 — forked from jlong/uri.js
URI Parsing with Javascript
var parser = document.createElement('a');
parser.href = "http://example.com:3000/pathname/?search=test#hash";
parser.protocol; // => "http:"
parser.host; // => "example.com"
parser.port; // => "3000"
parser.pathname; // => "/pathname/"
parser.search; // => "?search=test"
parser.hash; // => "#hash"