Skip to content

Instantly share code, notes, and snippets.

View ajsharp's full-sized avatar

Alex Sharp ajsharp

View GitHub Profile
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
Warden::Strategies.add(:bcrypt) do
def valid?
params[:username] || params[:password]
end
def authenticate!
return fail! unless user = User.first(:username => params[:username])
if user.encrypted_password == params[:password]
success!(user)
@tmm1
tmm1 / gist:450736
Created June 23, 2010 23:36
patch to add sequel support to a new rails3 app
diff --git a/app/models/model.rb b/app/models/model.rb
new file mode 100644
index 0000000..14c4620
--- /dev/null
+++ b/app/models/model.rb
@@ -0,0 +1,2 @@
+class Model < Sequel::Model
+end
\ No newline at end of file
diff --git a/config/application.rb b/config/application.rb
@nragaz
nragaz / all.god
Created July 12, 2010 03:16
God configs for starting Resque and Unicorn
PID_DIR = '/srv/myapp/shared/pids'
RAILS_ENV = ENV['RAILS_ENV'] = 'production'
RAILS_ROOT = ENV['RAILS_ROOT'] = '/srv/myapp/current'
BIN_PATH = "/home/rails/.rvm/gems/ree-1.8.7-2010.02/bin"
God.log_file = "#{RAILS_ROOT}/log/god.log"
God.log_level = :info
%w(unicorn resque).each do |config|
God.load "#{RAILS_ROOT}/config/god/#{config}.god"
require 'spec/runner/formatter/progress_bar_formatter'
class NescafeFormatter < Spec::Runner::Formatter::ProgressBarFormatter
def example_failed(example, counter, failure)
super
dump_failure(counter, failure)
end
end
#!/usr/bin/env ruby
begin
require 'rev'
rescue LoadError
puts "############## WARNING!!! ##############"
puts "You do not have the rev gem installed.\nIt is highly recommended to install this."
puts "The rev gem uses filesystem events rather than cpu polling to see if files have changed."
puts "\n"
puts "Please run `gem install rev` to install"
# require 'rubygems'
['wirble-0.1.3', 'awesome_print-0.2.1'].each do |g|
$:.unshift("/usr/local/lib/ruby/gems/1.8/gems/#{g}/lib")
end
require 'ap'
require 'wirble'
Wirble.init
Wirble.colorize
@gvarela
gvarela / Gemfile
Created May 5, 2011 16:30
web sockets with eventmachine and redis pub/sub
# A sample Gemfile
source "http://rubygems.org"
gem "redis"
gem 'eventmachine', :git => 'git://github.com/eventmachine/eventmachine.git'
gem "em-hiredis"
# gem "em-synchrony"
gem "em-websocket"
@ajsharp
ajsharp / airbrakeapp.com.js
Created August 17, 2011 23:48
DotJS script to create github issues from AirbrakeApp error pages
// NOTE: You need dotjs installed to use this: https://github.com/defunkt/dotjs
//
// You must name this file with your airbrakeapp subdomain prepended to the filename.
// Example: So myairbrakesubdomain.airbrakeapp.com.js
var login = "<GITHUB USERNAME>";
var token = "<GITHUB TOKEN>";
var title = $("#notice_heading h2").text();
var link = document.location.href;
@ajsharp
ajsharp / losangeles.craigslist.org.js
Created August 25, 2011 21:39
Craigslist live filtering
// Adds a live filter box to the results screen on craigslist
// that filters the results that are currently on the page by
// the search term. Like Cmd-F, but better.
// NOTE: Requires dotjs.
// Cmd-F live search
var searchBox = $('<input type="text" id="result-search" />')
$("h4.ban:first").before(searchBox)