Skip to content

Instantly share code, notes, and snippets.

#include <cstdio>
template <typename T>
class Array {
T _data[10];
size_t _length;
public:
size_t length() const { return _length; }
T& operator[](const size_t i) { return _data[i]; }
@helino
helino / utf8_write.py
Created May 17, 2013 07:21
Writing utf-8 char to file in Python
import codecs
import sys
fname = sys.argv[1]
f = codecs.open(fname, 'w', 'utf-8')
f.write(u'\xed')
f.close()
@helino
helino / Output
Created December 1, 2010 05:38
Output from rspec spec --backtrace
I'm being run before each 'it'
.I'm being run before each 'it'
.I'm being run once before the 'it's in my scope
FFF
Failures:
1) Router#handle runs the correct handler when multiple handlers have been added returns 1 for /
Failure/Error: @router.get '/' do 1 end
undefined method `get' for nil:NilClass
# ./spec/router_spec.rb:21:in `block (3 levels) in <top (required)>'
@helino
helino / router.rb
Created December 1, 2010 05:37
My first class when learning Ruby...
class Router
def initialize
@routes = {}
end
def get(str, &block)
@routes[str] = block
end
def handle(req)
@helino
helino / router_spec.rb
Created December 1, 2010 05:30
How does scoped before works in rspec?
require_relative '../router'
describe Router, "#handle" do
before do
puts "I'm being run before each 'it'"
@router = Router.new
end
it "raises an ArgumentError on empty request string" do
lambda{@router.handle("")}.should raise_error(ArgumentError)