Skip to content

Instantly share code, notes, and snippets.

View slawosz's full-sized avatar

Sławosz Sławiński slawosz

View GitHub Profile
@slawosz
slawosz / gist:840677
Created February 23, 2011 16:39 — forked from rkh/gist:791974
@slawosz
slawosz / extend_hooks.rb
Created May 20, 2011 12:00
Playing with modules with extend
class Module
def method_added(name)
p "#{name},#{caller[0..1]}"
end
end
class TestClass
def foo
p 'pure foo'
@slawosz
slawosz / anon_methods.scala
Created May 21, 2011 20:34
Scala examples for studies presentation
var someAnonMethod = (s:String) => println(s)
// Unit is Scala void
def execute(paramMethod: (String) => Unit) {
println("do hard stuff")
paramMethod("our function")
println("close hard stuff")
}
def nonAnonMethod(s:String) {
@slawosz
slawosz / symbol_expressions.rb
Created May 25, 2011 11:36 — forked from pjb3/symbol_expressions.rb
Symbol Expressions Simplified
class Symbol
def |(*args)
@args = args
self
end
def to_proc
Proc.new { |obj|
obj.send *[self] + (@args || [])
}
@slawosz
slawosz / shared_connection.rb
Created June 21, 2011 11:18 — forked from josevalim/shared_connection.rb
share connection for selenium driver
# In your test_helper.rb
class ActiveRecord::Base
mattr_accessor :shared_connection
@@shared_connection = nil
def self.connection
@@shared_connection || retrieve_connection
end
end
gem 'guard'
gem 'guard-rspec'
gem 'libnotify'
gem 'rb-fsevent'
@slawosz
slawosz / gist:1109241
Created July 27, 2011 12:21
Run single rspec spec in vim
map <F2> :<C-U>!bundle exec rspec <C-R>=expand("%:p") <CR> --drb -l <C-R>=line("'.") <CR> <CR>
map <C-F11> :call RunCurrentTest()<CR>
nmap <F11> :call RunLastTest()<CR>
nmap <F12> :!rspec <C-R>% --drb<CR>
function RunLastTest ()
if exists('w:current_test')
exe '!rspec ' . w:current_test . ' --drb'
else
device = Factory :device
device.should_receive(:notify)
# event will got object with expactations:
Factory :event, :device => device
@slawosz
slawosz / test.rb
Created October 15, 2011 21:13 — forked from paneq/test.rb
Which version do you prefere?
require 'test/unit'
class KeyTest < Test::Unit::TestCase
def test_key
object = Object.new
assert_equal(:submit, object_key(object))
def object.persisted?; true end
assert_equal(:update, object_key(object))
#include <cstdio>
using namespace std;
class Container;
class Element;
class Container {
private:
Element *container[100];
int i;