Skip to content

Instantly share code, notes, and snippets.

class App < Sinatra::Base
include Jazzband
get '/' do
session['username'] = params['username']
haml session['username'] ? :chat : :select_username
end
get '/send' do
return 403 unless session['username']
@buhrmi
buhrmi / gist:1344659
Created November 7, 2011 10:51
Sublime Text 2 Git Annotation Colors
<dict>
<key>name</key>
<string>Git Modified Line</string>
<key>scope</key>
<string>git.changes.x</string>
<key>settings</key>
<dict>
<key>background</key>
<string>#272852</string>
</dict>
@buhrmi
buhrmi / gist:801746
Created January 29, 2011 10:57
Pessimistic Locking Strategy support for DataMapper (FOR UPDATE)
# This Patch makes it possible to retrieve row-locked records from data-objects repositories
# Sample Usage: User.locked.get(1)
# #=> SELECT [...] WHERE `id` = 1 ORDER BY `id` LIMIT 1 FOR UPDATE
# In user.rb
def self.locked
all(:with_locking => true)
end
# The actual patch
@buhrmi
buhrmi / gist:800007
Created January 28, 2011 08:48
A haml filter that let's you call client javascript in ruby, utilizing Rjs
# In config/initializers/haml_filters.rb
module Haml
module Filters
module Client
include Base
def compile(precompiler, text)
return if precompiler.options[:suppress_eval]
precompiler.instance_eval do
push_silent <<-FIRST.gsub("\n", ';') + text + <<-LAST.gsub("\n", ';')
@buhrmi
buhrmi / gist:763374
Created January 3, 2011 11:32
A hacky DataMapper monkey patch to mark properties as dirty even if they have not changed
module DataMapper
module Resource
def taint! property
self.persisted_state = State::Dirty.new(self) unless self.persisted_state.kind_of?(State::Dirty)
self.persisted_state.original_attributes[properties[property]] = Object.new
end
end
end
# Example: