Skip to content

Instantly share code, notes, and snippets.


Marc-André Lafortune marcandre

View GitHub Profile

Sets need ♥️

When looking at RuboCop's code, I noticed a big number of frozen arrays being used only to later call include? on them. This is O(n) instead of O(1).

Trying to convert them to Sets causes major compatibility issues, as well as very frustrating situations (See set.join and array + set) and where the fact that they are now Sets makes them much less efficient (See array & set).

Here are the improvements that would improve Sets:


marcandre / require_changer.rb
Created Oct 6, 2018
require -> require_relative
View require_changer.rb
require 'pathname'
Pathname('./lib') do |name|
Dir["./lib/#{name}/**/*.rb"].each do |path|
code =
code.gsub!(%r{^(\s*)require (['"])#{name}/([\w/]*)['"]}) do
relative_path = Pathname("./lib/#{name}/#{$3}.rb").relative_path_from(Pathname(path).dirname)
%Q{#{$1}require_relative #{$2}#{relative_path.to_s[0..-4]}#{$2}}
File.write(path, code)
marcandre / # postgresql - 2013-06-18_03-25-11.txt
Created Sep 12, 2018
postgresql on macOS 10.11.6 - Homebrew build logs
View # postgresql - 2013-06-18_03-25-11.txt
Homebrew build logs for postgresql on macOS 10.11.6
Build date: 2013-06-18 03:25:11
marcandre / compare_reverse_sort.rb
Created May 18, 2013
Comparing how to do a reverse sort
View compare_reverse_sort.rb
require 'fruity'
a = (1..100).to_a.shuffle
compare do
sort { a.sort{|x, y| y <=> x} }
sort_by { a.sort_by{|x| -x} }
reverse { a.sort.reverse }
reverse! { a.sort.reverse! }
marcandre / plupload_bug
Last active Dec 17, 2015
Show bug with plupload's html5 runtime with IE10 when using colorbox
View plupload_bug
<script type="text/javascript" src=""></script>
<!-- Load plupload and all it's runtimes and finally the jQuery queue widget -->
<script type="text/javascript" src=""></script>
<script type="text/javascript" src=""></script>
<script type="text/javascript">
marcandre / make.log
Created Mar 12, 2013
more /Users/mal/.rvm/log/ruby-2.0.0-p0/make.log
View make.log
[2013-03-12 18:04:05] make
current path: /Users/mal/.rvm/src/ruby-2.0.0-p0
command(2): make -j2
CC = clang
LD = ld
LDSHARED = clang -dynamiclib
CFLAGS = -O3 -ggdb3 -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wunused-variable -Werror=pointer-arith -Werror=write-strings -Werror=declaration-after-statement -Werror=shorten-64-to-32 -Werror=implicit-function-declaration -fno-common -pipe
XCFLAGS = -include ruby/config.h -include ruby/missing.h -D_FORTIFY_SOURCE=2 -fstack-protector -fvisibility=hidden -DRUBY_EXPORT
CPPFLAGS = -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -I/usr/local/opt/libyaml/include -I/usr/local/opt/readline/include -I/usr/local/opt/libxml2/include -I/usr/local/opt/libxslt/include -I/usr/local/opt/libksba/include -I/usr/local/opt/openssl/include -I/usr/local/opt/sqlite/include -I. -I.ext/include/x86_64-darwin10.8.0 -I./include -I.
marcandre / log
Created Mar 12, 2013
rvm install 2.0.0 --trace
View log
[18:03][/usr/local(master)]$ rvm install 2.0.0 --trace
2.0.0 --trace
rvm 1.18.19 (master) by Wayne E. Seguin <>, Michal Papis <> []
+ 1363125790.N /scripts/cli : __rvm_parse_args() 755 > [[ -n '' ]]
+ 1363125790.N /scripts/cli : __rvm_parse_args() 757 > set -o errtrace
+ 1363125790.N /scripts/cli : __rvm_parse_args() 758 > export 'PS4=+ $(date "+%s.%N") ${BASH_SOURCE##${rvm_path:-}} : ${FUNCNAME[0]:+${FUNCNAME[0]}()} ${LINENO} > '
+ 1363125790.N /scripts/cli : __rvm_parse_args() 758 > PS4='+ $(date "+%s.%N") ${BASH_SOURCE##${rvm_path:-}} : ${FUNCNAME[0]:+${FUNCNAME[0]}()} ${LINENO} > '
+ 1363125790.N /scripts/cli : __rvm_parse_args() 790 > [[ -z install ]]
View rs.rb
# Change:
ruby_version_is '' ... '1.9' do
it "raises a TypeError on a frozen array" do
lambda { ArraySpecs.frozen_array << 5 }.should raise_error(TypeError)
ruby_version_is '1.9' do
it "raises a RuntimeError on a frozen array" do
marcandre / caller_locations_benchmark.rb
Last active Dec 14, 2015
benchmarking the new `caller_locations` against `caller`
View caller_locations_benchmark.rb
require 'fruity'
def whoze_there_using_caller
caller[0][/`([^']*)'/, 1]
def whoze_there_using_locations
View gist:5028319
$ rvm install rbx --debug
rbx - install
Searching for binary rubies, this might take some time.
Remote file does not exist
Remote file does not exist
Remote file does not exist
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.
You can’t perform that action at this time.