Skip to content

Instantly share code, notes, and snippets.

View madwork's full-sized avatar

Vincent Durand madwork

View GitHub Profile
@madwork
madwork / travis.yml
Last active August 13, 2019 09:00
Percona Server for MySQL with Travis CI (trusty)
dist: trusty
sudo: required
addons:
apt:
sources:
- sourceline: 'deb https://repo.percona.com/apt trusty main'
key_url: 'https://keyserver.ubuntu.com/pks/lookup?search=0x9334A25F8507EFA5&op=get'
packages:
- percona-server-server-5.7
- percona-server-client-5.7
require 'benchmark/ips'
Benchmark.ips do |x|
x.report("Kernel") { Hash(nil) }
x.report("Hash") { Hash.new(nil) }
end
# Warming up --------------------------------------
# Kernel 307.226k i/100ms
# Hash 117.067k i/100ms
@madwork
madwork / bench-digest.rb
Created May 7, 2019 09:10
ruby Digest::* benchmark
# gem install benchmark-ips
require 'digest/sha1'
require 'digest/sha2'
require 'benchmark/ips'
puts RUBY_DESCRIPTION
SRC = File.read '/dev/urandom', 8192
@madwork
madwork / .gitignore
Last active April 5, 2019 14:16
Compile Ruby
/*
!.gitignore
!ruby-build.sh
@madwork
madwork / tree.rb
Created March 7, 2019 17:57
Tree with apples
module Tree
# Returns list of ancestors, starting from parent until root.
#
# subchild1.ancestors # => [child1, root]
def ancestors
node, nodes = self, []
nodes << node = node.parent while node.parent
nodes
end
@madwork
madwork / bench.rb
Created February 19, 2019 17:03
URI parse parameters
require 'benchmark/ips'
require 'rack/utils'
require 'uri'
require 'cgi'
uri = URI.parse "https://reedsy.com/?foo=1&bar=2"
# [2.5.3] 0:(main) > Rack::Utils.parse_nested_query uri.query
# => {
# "foo" => "1",
@madwork
madwork / stripe-1.58.0_test.rb
Created March 14, 2017 15:51
Self executable gist for StripeObject marshalling issue
unless File.exist?('Gemfile')
File.write('Gemfile', <<-GEMFILE)
source 'https://rubygems.org'
gem 'stripe', '1.58.0'
gem 'minitest'
GEMFILE
system 'bundle'
end
@madwork
madwork / association_ids.rb
Last active March 10, 2017 11:27
Self executable gist
unless File.exist?('Gemfile')
File.write('Gemfile', <<-GEMFILE)
source 'https://rubygems.org'
#gem 'rails', github: 'rails/rails'
gem 'rails', github: 'rails/rails', branch: '4-2-stable'
gem 'sqlite3'
GEMFILE
system 'bundle'
end
@madwork
madwork / .pryrc
Created September 24, 2015 15:31
Pry confie file
require 'benchmark'
# sublime text as editor
Pry.config.editor = 'subl -w'
Pry.config.color = true
Pry.config.pager = true
# alias 'q' for 'exit'
Pry.config.commands.alias_command 'q', 'exit-all'