Skip to content

Instantly share code, notes, and snippets.

View bradgessler's full-sized avatar

Brad Gessler bradgessler

View GitHub Profile
A [common criticism](http://news.ycombinator.com/item?id=3737272) of building applications outside of Rails is the loss of a great, integrated tool chain.
> You don't pick Rails as the engine for powering your API simply for the asset pipeline, you pick it for all the other stuff @macaw pointed out! If you hook up Sinatra and Sprockets, you are without Rails' ORM, migrations, generators, routing, test infrastructure, plugin ecosystem, and arguably most importantly, the conventions and agility.
There is some truth to that, but it doesn't have to be that way.
I'm going to pick on ActiveRecord. The internet is [littered](http://community.active.com/blogs/productdev/2011/02/28/using-activerecord-3-without-rails) [with](http://exposinggotchas.blogspot.com/2011/02/activerecord-migrations-without-rails.html) [posts](https://github.com/thuss/standalone-migrations) about using ActiveRecord outside of Rails. Most solutions involve hacking together a Rake file that deals with this stuff. Its a pain.
Rails has alread
@bradgessler
bradgessler / tell.sh
Created February 15, 2012 01:11
Say any URL on a Mac
curl -s http://en.wikipedia.org/wiki/Rocket | sed -n -e 's/.*<p>\(.*\)<\/p>.*/\1/p' | sed -e "s/<[^>]*>//g" | say
@bradgessler
bradgessler / crash.rb
Created September 23, 2011 20:25
Fiber seg fault
require 'rubygems'
require 'eventmachine'
require 'fiber'
EM.run{ Fiber.new{}.resume }
__END__
/Users/bgessler/Desktop/crash.rb:6: [BUG] Segmentation fault
ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-darwin11.1.0]
@bradgessler
bradgessler / asink.rb
Created September 14, 2011 04:59
Async Thin web server app for testing timeouts
require 'rubygems'
require 'thin'
# curl "http://localhost:10001/?wait=5&status=500"
# ---
# wait - How many seconds should I wait before returning the status?
# status - HTTP return code
Thin::Server.start('127.0.0.1', 10001, Proc.new{|env|
req = Rack::Request.new(env)
@bradgessler
bradgessler / .rvmrc
Created July 29, 2011 01:40
rvmrc file that controls the version of Ruby, the Gemset, Rubygems, and Bundler. Use this if you want to control this stuff in your development workflow.
#!/usr/bin/env bash
# Bare minimum Gems that are needed to keep a Ruby development environment in sync. This assumes
# that you use bundler in your workflow to control the installation of all other gems. If you need
# to bump the bundler or rubygem version across your team, change that here, then run bundler and
# and keep going.
RVMRC=1.9.2@my_gem_set
RUBYGEM_VERSION="1.6.2"
BUNDLER_VERSION="1.0.15"
def configuration_class(*keys)
Class.new do
attr_accessor *keys
def self.keys=(keys)
@keys = keys
end
def self.keys
@keys
@bradgessler
bradgessler / twitter_profile_image.js
Created December 14, 2010 20:10
Pass a size into this thing and it will give you the images size
// How does it work? Hit it with /?username=bradgessler&size=reasonably_small
// and you get your URL (and redirect). Need more documentation? RTFSC.
var http = require('http');
http.createServer(function(request, response){
var query = require('url').parse(request.url, true).query;
if(!query || !query.username){
response.writeHead(412, {'Content-Type': 'text/plain'});
# What would you call it?
module Enumerable
# Do a map and select at the same time. Chuck Norris!
def chuck_norris(&block)
self.inject([]) do |collection, *args|
if result = block.call(*args)
collection.push result
end
collection
end
POST /sms/a8d9808243301811b94f4df3f911026d.sms HTTP/1.0
Host: localhost:8765
Connection: close
User-Agent: Java/1.5.0_22
Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
Content-type: application/x-www-form-urlencoded
Content-Length: 217
CustomerNickname=CAST&ResponseType=NORMAL&Keyword=&Option=&Data=ping&Message=Cast%20ping&OriginatorAddress=17783212541&ServerAddress=32075&AcceptedTime=29Aug,10%2017:41:38&DeliveryType=SMS&Carrier=fido&NetworkType=gsm
# This is half the implementation in the problem given to applicants...
class Tab
attr_accessor :url, :name
attr_reader :tabs
include ActionController::UrlWriter
def initialize(name=nil, url=nil, &block)
@name, @url = name, url
@tabs = []