Skip to content

Instantly share code, notes, and snippets.

# Temporary middleware for your APIs to immediately support a /v1/some/path.json prefix to
# all route calls.
#
# When you decide to freeze a current API and provide a /v2/ route then
# you will cease using this middleware and implement /v1/ and /v2/ routing as appropriate
# to your app.
#
# This middleware provides a placeholder until then so users can be told to use /v1/some/path routes
# immediately.
#
module Rack
class NoIE
def initialize(app, options = {})
@app = app
@options = options
@options[:redirect] ||= 'http://www.microsoft.com/windows/internet-explorer/default.aspx'
@options[:minimum] ||= 7.0
end
def call(env)
@defunkt
defunkt / clients.md
Created April 18, 2010 14:09
A list of Gist clients.

Gist Clients

Want to create a Gist from your editor, the command line, or the Services menu? Here's how.

Editor Support

# In your test_helper.rb
class ActiveRecord::Base
mattr_accessor :shared_connection
@@shared_connection = nil
def self.connection
@@shared_connection || retrieve_connection
end
end
var sys = require('sys'),
spawn = require('child_process').spawn,
http = require('http');
http.createServer(function (req, res) {
var ffmpeg = spawn('ffmpeg', ['-i /path/to/file', '-f mp3', '-']);
res.writeHead(200, {'Content-Type': 'audio/mpeg'});
ffmpeg.stdout.addListener('data', function (d) {
@jnewland
jnewland / .caprc
Created August 21, 2010 17:44
toss this in your ~/.caprc, then `cap cowboy staging deploy`. Use carefully.
namespace :cowboy do
desc 'Deploy without SCM'
task :default do
deploy_stage = fetch(:stage, 'none')
set :repository, "."
set :deploy_via, :copy
set :scm, :none
set :stage, deploy_stage
set :cowboy_deploy, true
set :copy_exclude, [".git/*", ".svn/*", "log/*", "vendor/bundle/*"]
#!/usr/bin/env ruby
# encoding: UTF-8
#
# LearnRubyByExample:
#
# Ruby is a highly expressive programming language.
# Testing software is an expressive way to communicate how it works.
#
# In the middle of a night awake for allergy and insomnia, and some days after the 1st _why day,
# I've tried to combine Ruby and testing to help teaching ruby with some goals in mind:
@chooh
chooh / config.ru
Created December 28, 2010 15:48
Simple Rack web server for static files with index.html
# This is the root of our app
@root = File.expand_path(File.join(File.dirname(__FILE__), "www"))
run Proc.new { |env|
# Extract the requested path from the request
req = Rack::Request.new(env)
index_file = File.join(@root, req.path_info, "index.html")
if File.exists?(index_file)
# Rewrite to index
@JeanMertz
JeanMertz / syntax_highlighting.py
Created April 18, 2011 08:39
Ruby on Rails syntax highlight switcher for Sublime Text 2
import sublime, sublime_plugin
import os
class DetectFileTypeCommand(sublime_plugin.EventListener):
""" Detects current file type if the file's extension isn't conclusive """
""" Modified for Ruby on Rails and Sublime Text 2 """
""" Original pastie here: http://pastie.org/private/kz8gtts0cjcvkec0d4quqa """
def on_load(self, view):
filename = view.file_name()
@DAddYE
DAddYE / image_uploader.rb
Created December 30, 2011 22:57
CarrierWave on the fly resizer (work as dragonfly)
class ImageUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick
storage :file
def thumb(size)
begun_at = Time.now
size.gsub!(/#/, '!')
uploader = Class.new(self.class)
uploader.versions.clear
uploader.version_names = [size]