Skip to content

Instantly share code, notes, and snippets.

function thisIsATest(){
return true;
}
# Protect your locales yo! don't specify directly from user input
## Rails 2.3 ree 1.8.7
>> Symbol.all_symbols.any?{ |s| s.to_s == "weird string" }
=> false
>> I18n.locale = "weird string"
=> "weird string"
>> Symbol.all_symbols.any?{ |s| s.to_s == "weird string" }
=> true
@hassox
hassox / base_app.rb
Created February 21, 2012 10:37
Mounted sinatra apps with http_router_sinatra
require 'sinatra/base'
require 'http_router_sinatra'
# With this simplistic approach, Sinatra apps must be leaf nodes in the rack graph
# Mounter nodes may be nested arbitrarily deeply however.
# Include Warden to authenticate whole sub-branches of the graph
class Mounter < HttpRouter
def mount(path, app)
route = add(path).partial.to(app)
mounter = app.respond_to?(:url_mount) ? app : nil
@hassox
hassox / gist:1350518
Created November 9, 2011 05:35 — forked from nicholasf/gist:1350482
Seeking feedback before I post this

How to calculate an hourly rate.

Hi,

I've been watching job boards for Ruby related contracts lately and have noticed some low rates being offered with high expectations. It's happening frequently enough that I wanted to post my understanding of how to calculate an hourly rate. Setting reasonable standards of pay for the appropriate level of expertise is vital. There's a lot to say on the matter, so I've tried to be brief.

For some reason it's very easy for software developers to match their experience and knowledge to a full-time rate, but for contracting there is less awareness.

The difference between full-time employment and self employment.

class AssetServer < Sprockets::Environment
include Singleton
def initialize
super Rails.root.join('app', 'assets')
paths << 'javascripts' << 'stylesheets'
self.static_root = Rails.root.join('public', 'assets')
@hassox
hassox / gist:659298
Created November 2, 2010 06:08 — forked from ngw/gist:659296
Rails.configuration.middleware.use Warden::Manager do |config|
config.failure_app = SessionsController
config.default_strategies :facebook
end
Warden::Manager.serialize_into_session do |user|
user.id.to_s
end
Warden::Manager.serialize_from_session do |id|
class BaseParticipant
include Ruote::LocalParticipant
def consume( workitem )
@workitem = workitem
begin
_, method, *args = workitem.fields['command'].split('/')
if arg
send( method, *args )
else
module EmGlobWatcher
# Setup to watch a glob on the file system.
# If the glob is detected, the path of the matching file will be yielded to the block
# You may pass it an interval on how often to scan the directory.
# The block will be executed before the next interval is set
# @param glob - The file glob to watch for
# @param interval - The interval in seconds to poll the file system
def self.watch(glob, interval = 0.5, &blk)
raise "EventMacine must be running" unless EM.reactor_running?
watcher = nil
b = lambda {
:IMA_B_LOL
}
# A must enclose B
a = lambda {
b.call()
}
b.call() # raises nothing
Rspec::Matchers.define :match_nokogiri_selector do |selector|
match do |doc|
doc.at(selector) != nil
end
failure_message_for_should do |doc|
"expected #{selector} to be found in \n#{doc.to_xml}"
end
failure_message_for_should_not do |doc|