Skip to content

Instantly share code, notes, and snippets.

View matthewford's full-sized avatar

Matthew Ford matthewford

View GitHub Profile
@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
@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 / 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 / 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()
}
}
@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()
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
@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
<style>
span.title {
display: block;
text-align: center;
margin-top: 10px;
margin-bottom: 20px;
}
</style>
<div data-role="page" id="sitetips" data-title="Dialog Tips">
@piscisaureus
piscisaureus / pr.md
Created August 13, 2012 16:12
Checkout github pull requests locally

Locate the section for your github remote in the .git/config file. It looks like this:

[remote "origin"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	url = git@github.com:joyent/node.git

Now add the line fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to this section. Obviously, change the github url to match your project's URL. It ends up looking like this:

@astrauka
astrauka / clone_rackspace_cloud_files.rb
Last active December 30, 2015 21:59
Ruby on Rails - clone Rackspace cloud files from one container to another. Supports different rackspace users. Add the file contents to app/tasks/clone_rackspace_cloud_files.rb and launch CloneRackspaceCloudFiles.new.run via console. Can use as non-rails script, but then need to make sure require "fog" finds the file required. Environment variab…
require "fog"
require "net/http"
class CloneRackspaceCloudFiles
def service
@service ||= Fog::Storage.new({
:provider => 'Rackspace',
:rackspace_username => ENV["RACKSPACE_USER_NAME"],
:rackspace_api_key => ENV["RACKSPACE_API"],
:rackspace_auth_url => Fog::Rackspace::UK_AUTH_ENDPOINT,