Skip to content

Instantly share code, notes, and snippets.

Devise::ALL.dup.each do |name|
class_name = name.to_s.classify
to_class = WebsiteAccount
to_instance = :website_account
class_eval <<-METHODS, __FILE__, __LINE__ + 1
module Devise::Models::Delegated#{class_name}
extend ActiveSupport::Concern
included do
@qoobaa
qoobaa / gist:737443
Created December 11, 2010 16:11
Serve local directory using Rack::Static
use Rack::Static, :urls => [""]; run nil
@qoobaa
qoobaa / gist:744775
Created December 17, 2010 10:54
Simple Rack application for JavaScript I18n
require "json"
class JavaScriptI18n
def self.call(env)
locale = env["PATH_INFO"][1..-4]
if translations.key?(locale)
[200, {"Content-Type" => "text/javascript"}, new(translations[locale])]
else
[404, {}, "Not found"]
end
@qoobaa
qoobaa / gist:754948
Created December 25, 2010 16:58
Using ActionMailer for internal messaging
class UserNotifier < ActionMailer::Base
# sample message
def some_message(user)
from %Q{"Internal Messaging System"}
recipients user.email
subject "This is internal message"
body :user => user
end
# sample message notification
@qoobaa
qoobaa / gist:754950
Created December 25, 2010 17:01
Ruby and Rails on Ubuntu 9.10 Karmic Koala
sudo apt-get install ruby rubygems libssl-dev libreadline-dev zlib1g-dev libsqlite3-dev curl
sudo gem install rvm
/var/lib/gems/1.8/bin/rvm-install
@qoobaa
qoobaa / gist:754952
Created December 25, 2010 17:03
Patching Rails and gems locally
namespace :patch do
desc "Applies patches to Rails frozen in vendor"
task :rails do
rails_dir = Rails.root.join("vendor", "rails")
Rails.root.join("patch", "rails").children.each do |patch|
patch(patch, rails_dir)
end
end
desc "Applies patches to gems frozen in vendor"
@qoobaa
qoobaa / gist:755030
Created December 25, 2010 20:11
Magic
gem install magic
gem install s3
YUI.add "card", (Y) ->
Card = Y.Base.create "card", Y.Widget, [Y.WidgetChild],
BOUNDING_TEMPLATE: "<li></li>"
CONTENT_TEMPLATE: "<div></div>"
renderUI: ->
@_renderCard()
table1 = {
table: {
"id": 1,
"version": 5,
"players": [
{ "id": 1, name: "user N", direction: "N" },
{ "id": 2, name: "user E", direction: "E" },
{ "id": 3, name: "user S", direction: "S" },
{ "id": 4, name: "user W", direction: "W" }
],