Skip to content

Instantly share code, notes, and snippets.

View marcandre's full-sized avatar

Marc-André Lafortune marcandre

View GitHub Profile
# 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)
end
end
ruby_version_is '1.9' do
it "raises a RuntimeError on a frozen array" do
@marcandre
marcandre / log
Created March 12, 2013 22:06
rvm install 2.0.0 --trace
[18:03][/usr/local(master)]$ rvm install 2.0.0 --trace
2.0.0 --trace
rvm 1.18.19 (master) by Wayne E. Seguin <wayneeseguin@gmail.com>, Michal Papis <mpapis@gmail.com> [https://rvm.io/]
+ 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 ]]
@marcandre
marcandre / make.log
Created March 12, 2013 22:07
more /Users/mal/.rvm/log/ruby-2.0.0-p0/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
marcandre / plupload_bug
Last active December 17, 2015 02:48
Show bug with plupload's html5 runtime with IE10 when using colorbox
<html>
<head>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<!-- Load plupload and all it's runtimes and finally the jQuery queue widget -->
<script type="text/javascript" src="http://www.plupload.com/plupload/js/plupload.full.js"></script>
<script type="text/javascript" src="http://www.jacklmoore.com/colorbox/jquery.colorbox.js"></script>
<script type="text/javascript">
@marcandre
marcandre / compare_reverse_sort.rb
Created May 18, 2013 14:28
Comparing how to do a reverse sort
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! }
end
@marcandre
marcandre / # postgresql - 2013-06-18_03-25-11.txt
Created September 12, 2018 13:27
postgresql on macOS 10.11.6 - Homebrew build logs
Homebrew build logs for postgresql on macOS 10.11.6
Build date: 2013-06-18 03:25:11
@marcandre
marcandre / require_changer.rb
Created October 6, 2018 03:19
require -> require_relative
require 'pathname'
Pathname('./lib').children.select(&:directory?).map(&:basename).each do |name|
Dir["./lib/#{name}/**/*.rb"].each do |path|
begin
code = File.read(path)
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}}
end
File.write(path, code)
@marcandre
marcandre / Set.md
Last active August 24, 2020 18:50

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:

Set#join

# gem install 'benchmark-ips'
require 'benchmark/ips'
long = ' ' * 1_000_000 + 'x'
REGEXP = /\A[[:space:]]*\z/
[' ', 'hello', long].each do |str|
Benchmark.ips do |x|
x.report('with_regexp') { REGEXP.match? str }
@marcandre
marcandre / miller_rabin_bench.rb
Last active December 5, 2020 10:57
Miller Rabin prime test
<<~RESULT
Testing 10..100
current: 389.3 i/s
faster_prime: 269.8 i/s - 1.44x (± 0.00) slower
miller_rabin: 226.5 i/s - 1.72x (± 0.00) slower
Testing 100..1000
current: 323.4 i/s
faster_prime: 254.4 i/s - 1.27x (± 0.00) slower
miller_rabin: 213.0 i/s - 1.52x (± 0.00) slower