Skip to content

Instantly share code, notes, and snippets.

View matthewford's full-sized avatar

Matthew Ford matthewford

View GitHub Profile
@woahdae
woahdae / tire_ext.rb
Created January 18, 2012 17:36
On-the-fly index rotation
module Tire
def self.inverted_aliases
aliases.inject({}) do |acc, (index, aliases)|
aliases.each do |als|
acc[als] ||= SortedSet.new
acc[als] << index
end
acc
end
end
require 'sinatra'
require 'pp'
require 'redis'
require 'json'
configure do
redis = JSON.parse(ENV['VMC_SERVICES']).select {|srvc| srvc['name'] =~ /redis-.*?/ }.first['options']
redis_conf = {:host => redis['hostname'], :port => redis['port'], :password => redis['password']}
@@redis = Redis.new redis_conf
@technoweenie
technoweenie / step.coffee
Created August 26, 2010 22:26
Step.js ported to coffeescript, with fewer features
# Step(
# () -> redis.select 15, @
# () -> redis.flushdb @
# () -> redis.rpush 'fakelist', '1', @
# () -> redis.rpush 'fakelist', '2', @
# () -> redis.rpush 'fakelist', '3', @
# () -> redis.lrange 'fakelist', 0, 1, @
# (err, arr) ->
# console.log arr.length
# console.log arr[0].toString()
@defunkt
defunkt / ipad.js
Created May 31, 2010 00:53
Show or hide a sidebar in JS on iPad orientation change
window.onorientationchange = function() {
if (window.orientation == 0) {
$('#sidebar').fadeOut()
} else {
$('#sidebar').fadeIn()
}
}
@defunkt
defunkt / layout.rb
Created May 27, 2010 01:41
Dirt cheap layouts with Mustache.
require 'mustache'
class Layout < Mustache
self.template = "Header
{{{yield}}}
Footer"
end
class Index < Mustache
self.template = "The Index."
@defunkt
defunkt / ii.rb
Created May 24, 2010 23:33
{{.}} in mustache.rb
require 'mustache'
Mustache::Parser::ALLOWED_CONTENT = /(\w|[?!\/.-])*/
class ImplicitIterator < Mustache
define_method "." do
self[:to_s]
end
def names
@defunkt
defunkt / sep.rb
Created May 18, 2010 01:19
Section separators in mustache.rb
require 'mustache'
require 'yaml'
class Sep < Mustache
def last?
self[:to_s] == self[:names].last.to_s
end
end
template = <<template