Skip to content

Instantly share code, notes, and snippets.

config.action_controller.asset_host = Proc.new do |source, request|
non_ssl_host = "http://asset#{source.hash % 4}.backpackit.com"
ssl_host = "https://asset1.backpackit.com"
if request.ssl?
case
when source =~ /\.js$/
ssl_host
when request.headers["USER_AGENT"] =~ /(Safari)/
non_ssl_host
@trevorturk
trevorturk / no_www.rb
Created November 3, 2009 05:03
no-www rack middleware
class NoWWW
STARTS_WITH_WWW = /^www\./i
def initialize(app)
@app = app
end
def call(env)
if env['HTTP_HOST'] =~ STARTS_WITH_WWW
require 'mongoid'
require 'rspec'
Mongoid.configure do |config|
config.master = Mongo::Connection.new.db('testing')
config.autocreate_indexes = true
end
class User
include Mongoid::Document
@snuggs
snuggs / .vimrc
Last active April 4, 2021 05:59
VIM "$ mkdir ~/.tmp # ensure directory exists first
set encoding=utf-8
" Author: Ahmid-Ra (github.com/snuggs)
" Screencasts: http://vimcasts.org
" Gist: https://gist.github.com/snuggs/612093
" Tutorial: http://learnvimscriptthehardway.stevelosh.com
@dnagir
dnagir / rspec-syntax-cheat-sheet.rb
Created November 5, 2010 09:29
RSpec 2 syntax cheat sheet by example
# RSpec 2.0 syntax Cheet Sheet by http://ApproachE.com
# defining spec within a module will automatically pick Player::MovieList as a 'subject' (see below)
module Player
describe MovieList, "with optional description" do
it "is pending example, so that you can write ones quickly"
it "is already working example that we want to suspend from failing temporarily" do
pending("working on another feature that temporarily breaks this one")
@jittuu
jittuu / gist:792715
Created January 24, 2011 02:19
Test Omniauth Facebook Callback Controllers in Devise with rspec
require 'spec_helper'
describe Users::OauthCallbacksController, "handle facebook authentication callback" do
describe "#annonymous user" do
context "when facebook email doesn't exist in the system" do
before(:each) do
stub_env_for_omniauth
get :facebook
@txus
txus / delegate_matcher.rb
Created February 2, 2011 09:19
RSpec matcher for delegations
# RSpec matcher to spec delegations.
#
# Usage:
#
# describe Post do
# it { should delegate(:name).to(:author).with_prefix } # post.author_name
# it { should delegate(:month).to(:created_at) }
# it { should delegate(:year).to(:created_at) }
# end
@mrinterweb
mrinterweb / _explaination.txt
Created March 15, 2011 19:51
Mongoid example of using references_many with an embedded class
I found this challenging to figure out so I thought I would share:
This shows how you can establish a references_many relationship to an embedded class. The limitation of course in my example is that when retrieving the ClientApplication's access_grants, it ends up retrieving User records. I believe this is a limitation of MongoDB in that MongoDB can not retrieve just embedded objects. It is not hard to accessing the embedded objects from the embedding class after retrieval.
I access users like this:
@client_app.users
This is an example of the mongo query:
hub_test['users'].find({"access_grants.client_application_id"=>BSON::ObjectId('4d7fbead9ebea474c0000012')}, {})
@snuggs
snuggs / metaprogramming_for_dummies.rb
Created March 24, 2011 21:31
Meta Programming Made Easy
# Yehuda Katz - (It's all about the self)
# http://yehudakatz.com/2009/11/15/metaprogramming-in-ruby-its-all-about-the-self/
#######################################################################################
# All classes are objects themselves
#######################################################################################
# Defining a class using the "class" keyword is merely syntactic sugar.
# All class definitions are actually instances of the Class object.
@iwarshak
iwarshak / devise_migration.rb
Created August 24, 2011 16:02 — forked from Bertg/devise_migration.rb
Migrating to a new password encryption in devise, coming from authlogic
class MigrateUserToDevise < ActiveRecord::Migration
def self.up
change_table :users do |t|
t.string :encrypted_password, :null => false, :limit => 128
# ...
end
end
def self.down
end