Skip to content

Instantly share code, notes, and snippets.

View philou's full-sized avatar
😀

Philippe Bourgau philou

😀
View GitHub Profile
@philou
philou / Rakefile
Last active August 29, 2015 13:56
Add keywords to your existing octopress posts
desc "add keywords to posts"
task :add_keywords do
Dir.glob(File.join(File.dirname(__FILE__),"source/_posts/*.markdown")) do |file|
yaml = YAML.load_file(file)
keywords = yaml['categories'] || []
title = yaml['title']
keywords += title.scan(/'.*'/).map {|kw| kw.gsub("'",'')}
keywords += title.scan(/\S+[\sv~>]+?\d+\.\d+\.?\d*/)
@philou
philou / matchers_combinators.rb
Last active December 22, 2015 19:49
Rspec matchers combinators
# Matcher to verify that all items match something else
RSpec::Matchers.define :all_ do |item_matcher|
match do |actual_items|
actual_items.all? { |item| item_matcher.matches?(item)}
end
description do
"#{item_matcher.description} to be true for all the items"
end
@philou
philou / rspec_proxies.rb
Created June 30, 2013 06:46
Proxies à la rr with rspec
class Object
# Will call the given block with it's result every time the method
# returns
def on_result_from(method_name)
stock_response = self.original_response(method_name)
self.stub(method_name) do |*args, &block|
result = stock_response.call(*args, &block)
yield result
@philou
philou / memory_profiling_spec.rb
Last active December 12, 2015 02:08
The poor man's memory profiling
it "should use constant memory" do
warm_up_measure = memory_usage_for_items(1)
small_inputs_memory = memory_usage_for_items(1)
large_inputs_memory = memory_usage_for_items(200)
large_inputs_memory.should be <= small_inputs_memory * 1.05
end
def memory_usage_for_items(item_count)
@philou
philou / rbenv-patch
Created January 9, 2013 11:43
This script uses a patch from the rvm repo to patch a ruby-build package before installing it with rbenv. It uses ruby 1.9.3-p125 with gcdata patch, but it should work with any ruby / patch as long as they are compatible.
#!/bin/sh
mkdir /tmp/ruby-build-patch
cd /tmp/ruby-build-patch
# download and patch the ruby sources
wget http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p125.tar.gz
tar xzf ruby-1.9.3-p125.tar.gz
cd ruby-1.9.3-p125
curl https://raw.github.com/wayneeseguin/rvm/master/patches/ruby/1.9.3/p125/gcdata.patch | patch -p1
@philou
philou / EggCooker.java
Created December 16, 2011 10:15
Randori Egg Cooker @ Key Consulting 15/12/2011
import java.util.Timer;
import java.util.TimerTask;
public class EggCooker {
private View view;
private long remainingTime;
private ITimer timer;
public EggCooker(View view, ITimer timer) {
@philou
philou / Converter.java
Created December 16, 2011 09:04
Randori Arab to romans @ Key Consulting 13/12/2011
public class Converter {
public static String toRomans(int i) {
return getMultipleM(i/1000) + toRomans(i/100,"C","D","M") + toRomans(i/10, "X", "L", "C") + toRomans(i%10, "I", "V", "X");
}
private static String toRomans(int i, String symbolI, String symbolV, String symbolX) {
int moduloRest10 = i%10;
if ( moduloRest10 == 0) {
return "";
}
@philou
philou / Game.java
Created December 9, 2011 09:02
Kata Bowling @ Key Consulting 8-12-2011
import java.util.ArrayList;
import java.util.List;
public class Game {
class Frame {
final int firstRoll;
final int secondRoll;
@philou
philou / BowlingTest.java
Created December 9, 2011 08:57
La solution que j'avais réalisée avant
package test;
import static org.junit.Assert.*;
import main.Game;
import org.junit.Before;
import org.junit.Test;
public class BowlingTest {