Skip to content

Instantly share code, notes, and snippets.

Brad Gessler bradgessler

Block or report user

Report or block bradgessler

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@bradgessler
bradgessler / cors_policy.rb
Last active Dec 11, 2015
An idea for a Rails CORS policy DSL implementation.
View cors_policy.rb
# Configuration DSL, probably in config/initializers/cors.rb
CORS::Policy.configure do
policy :polleverywhere do
origins 'pollev.com', 'www.polleverywhere.com'
# I think allowable request method can be inferred by Rails routing.
# methods :get, :put, :post, :delete, :patch
headers 'X-Custom-Request-Header'
expose 'X-Custom-Response-Header'
end
@bradgessler
bradgessler / phone_numbers.rb
Created Nov 7, 2012
A list of all US and Canadian phone numbers
View phone_numbers.rb
#!/usr/bin/env ruby
("000-000-0000").upto("999-999-9999").each do |number|
puts number
end
@bradgessler
bradgessler / blinksale_report.rb
Created Nov 7, 2012
Generate a report by month for the amount of payment received in Blinksale
View blinksale_report.rb
require 'open-uri'
require 'nokogiri'
require 'filecache'
require 'logger'
require 'date'
require 'pry'
# When do you want to grab invoices? Default is 90 days ago.
@since = ENV.include?('SINCE') ? Date.parse(ENV['SINCE']) : Date.today - 90
# Blinksale username
@bradgessler
bradgessler / posterous-importer.php
Created Jul 27, 2012
Posterous WordPress importer (this one makes sure that the links don't break)
View posterous-importer.php
<?php
/*
Plugin Name: Posterous Importer
Plugin URI: http://wordpress.org/extend/plugins/posterous-importer/
Description: Import posts, comments, tags, and attachments from a Posterous.com blog.
Author: Automattic, Brian Colinger, Peter Westwood, Daryl L. L. Houston
Author URI: http://automattic.com/
Version: 0.10
License: GPL v2 - http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
*/
@bradgessler
bradgessler / forkin_manifest.rb
Created Apr 18, 2012
A faster Sprockets compiler that breaks apart the job into subprocesses
View forkin_manifest.rb
require 'sprockets'
module Sprockets
module Forkin
class Manifest < ::Sprockets::Manifest
attr_reader :workers
# The last argument should be the number of workers
def initialize(environment, path, workers=1)
@workers = workers
View gist:2357908
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 Feb 15, 2012
Say any URL on a Mac
View tell.sh
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 Sep 23, 2011
Fiber seg fault
View crash.rb
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 Sep 14, 2011
Async Thin web server app for testing timeouts
View asink.rb
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 Jul 29, 2011
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.
View .rvmrc
#!/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"
You can’t perform that action at this time.