Skip to content

Instantly share code, notes, and snippets.

View marcandre's full-sized avatar

Marc-André Lafortune marcandre

View GitHub Profile
diff --git a/lib/mspec/expectations/should.rb b/lib/mspec/expectations/should.rb
index 6a37401..6cd7030 100644
--- a/lib/mspec/expectations/should.rb
+++ b/lib/mspec/expectations/should.rb
@@ -1,8 +1,9 @@
class Object
- def should(matcher=nil)
+ NO_MATCHER_GIVEN = Object.new
+ def should(matcher=NO_MATCHER_GIVEN)
MSpec.expectation
diff --git a/array.c b/array.c
index 51d3ad2..29f2ca0 100644
--- a/array.c
+++ b/array.c
@@ -22,7 +22,7 @@
VALUE rb_cArray;
-static ID id_cmp;
+static ID id_cmp, id_div, id_power;
@marcandre
marcandre / gitlinestat.rb
Created July 13, 2012 20:17
Quick stats per user on number of lines added/removed per commit
#!/usr/bin/env ruby
# A simple script to get stats on number of lines added/removed per commit
# Accepts -v option for verbose mode
# Accepts other git options, in particular path.
#
# E.g.:
#
# linestat -v app lib
@marcandre
marcandre / gist:3422303
Created August 22, 2012 04:39
Fixx buzz battle
# Hi # Hi
# For this interview, we'd like you to
# Write fizz buzz
# Ok:
def go
fizzy = ->(n){ n % 3 == 0 }
buzzy = ->(n){ n % 5 == 0 }
fizzbuzzy = ->(n){ n % 15 == 0 }
@marcandre
marcandre / gist:3498470
Created August 28, 2012 14:25
bash config for git
# Prompt
function parse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
function proml {
local BLUE="\[\033[0;34m\]"
local RED="\[\033[0;31m\]"
local LIGHT_RED="\[\033[1;31m\]"
local GREEN="\[\033[0;32m\]"
@marcandre
marcandre / gist:3498506
Created August 28, 2012 14:30
git completion
#!bash
#
# bash/zsh completion support for core Git.
#
# Copyright (C) 2006,2007 Shawn O. Pearce <spearce@spearce.org>
# Conceptually based on gitcompletion (http://gitweb.hawaga.org.uk/).
# Distributed under the GNU General Public License, version 2.0.
#
# The contained completion routines provide support for completing:
#
@marcandre
marcandre / billion.rb
Created February 20, 2013 15:49
Google billion'th letter
# We deal with the problem by writing classes of numbers in tree form.
# Leaves can be a specific number (Centile), a generic centile (GenericValue) or a subtree (another GenericNumber).
# Each such GenericNumber can be expanded one level by replacing the leftmost GenericValue by specific values.
# This is done using GenericNumber.each; the other important method is children, which calculates recursively
# information about all the children: sum, size of strings, number.
# All language dependent constants:
TO_TWENTY = { 0 => '', 1 => 'one', 2 => 'two', 3 => 'three', 4 => 'four',
5 => 'five', 6 => 'six', 7 => 'seven', 8 => 'eight', 9 => 'nine',
10 => 'ten', 11 => 'eleven', 12 => 'twelve', 13 => 'thirteen', 14 => 'fourteen',
# Quick and dirty script to compare builtin methods between two rubyies
# Usage:
#
# ruby_old digest.rb | ruby_new digest.rb
def class_signature(klass)
Hash[
{instance: klass, singleton: klass.singleton_class}.to_a
.product([:private, :public, :protected])
.map{ |(level, obj), access| ["#{access} #{level} methods", obj.send("#{access}_instance_methods", false)] }
$ rvm install rbx --debug
rbx - install
Searching for binary rubies, this might take some time.
Remote file does not exist https://rvm.io/binaries/osx/10.6/i386/rbx-head.tar.bz2
Remote file does not exist http://jruby.org.s3.amazonaws.com/downloads/rbx-head.tar.bz2
Remote file does not exist http://binaries.rubini.us/osx/10.6/i386/rbx-head.tar.bz2
rvm_remote_server_url3 not found
No remote file name found
No binary rubies available for: osx/10.6/i386/rbx-head.
Continuing with compilation. Please read 'rvm mount' to get more information on binary rubies.
@marcandre
marcandre / caller_locations_benchmark.rb
Last active December 14, 2015 06:19
benchmarking the new `caller_locations` against `caller`
require 'fruity'
def whoze_there_using_caller
caller[0][/`([^']*)'/, 1]
end
def whoze_there_using_locations
caller_locations(1,1)[0].label
end