Skip to content

Instantly share code, notes, and snippets.

View vangberg's full-sized avatar

Harry Vangberg vangberg

View GitHub Profile
@vangberg
vangberg / inbound.rb
Created November 18, 2009 22:21
freeswitcher: inbound/outbound event listener
require 'fsr'
require 'fsr/listener/inbound'
class MyInbound < FSR::Listener::Inbound
# `on_event` is called every time an event is received.
def on_event
# Be sure to check out the content of `event`. It has all the good stuff.
FSR::Log.info "Got event: #{event.content[:event_name]}"
end
case headers['Accept']
when 'application/json':
...
when 'text/html':
...
end
vs
respond_to do |format|
$ ruby setter-return.rb
Loaded suite setter-return
Started
F
Finished in 0.008396 seconds.
1) Failure:
test_return_value_of_setter(TestFoo) [setter-return.rb:17]:
<4> expected but was
<2>.
class BlackHole
instance_methods.each { |m| undef_method m unless m =~ /^__/ }
def method_missing(*a) self end
end
BlackHole.new.doesnt.care("much").about(:anything, :you, :do).okay?
def not_allowed(route, methods)
methods.each do |method|
send method do
halt 405
end
end
end
not_allowed '/get', :put, :delete
>> h = Hash.new([])
=> {}
>> h[:foo] = "some value"
=> "some value"
>> h[:bar]
=> []
>> h[:bar] << "an item"
=> ["an item"]
>> h
=> {:foo=>"some value"}
require 'hashidator'
schema = {
:name => String,
:age => (13..25),
:mail => /^\S+@\S+\.\S+$/,
:admin => Boolean
}
valid = {
## app.rb
class SomeModule < Sinatra::Base
get '/some' do
..
end
end
class MyApp < Sinatra::Base
use SomeModule
@vangberg
vangberg / DWM-ON-OS-X.md
Created February 22, 2010 19:24
dwm on os x [work in progress!]

Installing and configuring dwm on OS X

  1. Install XQuartz (http://xquartz.macosforge.org) which is the development version of the X11.app that ships with OS X, which means it is way more up to date. I have had some weird issues with X11.app v. 2.3-something. XQuartz 2.5.0 fixed that.

  2. Install dwm from Homebrew, brew install dwm. This makes a bunch of necessary tweaks to the DWM configuration.

  3. Add the following script to $PATH, name it dwm-launch and chmod 755:

    cd ~
    

while true

diff --git a/lib/mongo_mapper.rb b/lib/mongo_mapper.rb
index eee7291..81bfd8a 100644
--- a/lib/mongo_mapper.rb
+++ b/lib/mongo_mapper.rb
@@ -5,7 +5,7 @@ require 'set'
# so i want to make sure that if you are using gems you do in fact have the correct versions
# if there is a better way to do this, please enlighten me!
if self.class.const_defined?(:Gem)
- gem 'activesupport', '>= 2.3'
+ gem 'activesupport', '= 2.3.5'