Skip to content

Instantly share code, notes, and snippets.

View bullfight's full-sized avatar
🚀

Patrick Schmitz bullfight

🚀
View GitHub Profile
@ches
ches / gist:243611
Created November 26, 2009 19:09 — forked from lukesutton/gist:107966
basic example of Warden authentication with Sinatra
Warden::Manager.serialize_into_session{|user| user.id }
Warden::Manager.serialize_from_session{|id| User.get(id) }
Warden::Manager.before_failure do |env,opts|
# Sinatra is very sensitive to the request method
# since authentication could fail on any type of method, we need
# to set it for the failure app so it is routed to the correct block
env['REQUEST_METHOD'] = "POST"
end
@matthutchinson
matthutchinson / fakeout.rake
Created February 10, 2010 16:49
fakeout.rake - a simple/configurable rake task that generates some random fake data for the app (using faker) at various sizes
# a simple/configurable rake task that generates some random fake data for the app (using faker) at various sizes
# NOTE: requires the faker or ffaker gem
# sudo gem install faker - http://faker.rubyforge.org
# OR
# sudo gem install ffaker - http://github.com/EmmanuelOga/ffaker
require 'faker'
class Fakeout
@jeffrafter
jeffrafter / factory_girl attachments for paperclip
Created May 30, 2010 13:26
factory_girl attachments for paperclip
require 'action_controller/test_process'
# Paperclip attachments in factories, made easy based on technicalpickles
Factory.class_eval do
def attach(name, path, content_type = nil)
if content_type
add_attribute name, ActionController::TestUploadedFile.new("#{RAILS_ROOT}/#{path}", content_type)
else
add_attribute name, ActionController::TestUploadedFile.new("#{RAILS_ROOT}/#{path}")
end
require "rubygems"
require "net/http"
require "open-uri"
data = open("http://cdo.ncdc.noaa.gov/climatenormals/clim84/IL/IL110055.txt").map
#data = open("http://cdo.ncdc.noaa.gov/climatenormals/clim84/IL/IL112679.txt").map
metric = {}
metric[:station_coop_id] = data[4][44..49]
@cblunt
cblunt / factories.rb
Created October 15, 2010 14:01 — forked from technicalpickles/factories.rb
Simulate paperclip attachments with FactoryGirl in Rails 3
Factory.define :application do |factory|
factory.attachment :sample, "public/samples/sample.doc", "application/msword"
end
@rwz
rwz / doesnt.rb
Created December 13, 2010 06:50
state_machine + delayed_job wtf
# doesn't fucking work
class Logo < ActiveRecord::Base
state_machine :state, :initial => :initial do
# here vvv
after_transition :initial => :used, :do => :test_callback
anonymous
anonymous / directory_web_service.rb
Created January 29, 2011 00:18
require 'mechanize'
require 'nokogiri'
require 'sinatra'
get '/:psuid' do
find_name params[:psuid]
end
def find_name(psuid)
@gunn
gunn / directory_web_service.rb
Created January 29, 2011 10:44 — forked from anonymous/directory_web_service.rb
Refactor of some code from a blog post.
require 'mechanize'
require 'nokogiri'
require 'sinatra'
get '/:psuid' do
find_name params[:psuid]
end
def find_name(psuid)
@wbailey
wbailey / databases.rake
Created February 11, 2011 08:58
ActiveRecord migrations outside of Rails
require 'yaml'
require 'logger'
require 'active_record'
namespace :db do
def create_database config
options = {:charset => 'utf8', :collation => 'utf8_unicode_ci'}
create_db = lambda do |config|
ActiveRecord::Base.establish_connection config.merge('database' => nil)
@kmile
kmile / xml_parser.rb
Created February 15, 2011 12:53
A small nokogiri xml reader DSL.
# A small DSL for helping parsing documents using Nokogiri::XML::Reader. The
# XML Reader is a good way to move a cursor through a (large) XML document fast,
# but is not as cumbersome as writing a full SAX document handler. Read about
# it here: http://nokogiri.org/Nokogiri/XML/Reader.html
#
# Just pass the reader in this parser and specificy the nodes that you are interested
# in in a block. You can just parse every node or only look inside certain nodes.
#
# A small example:
#