Skip to content

Instantly share code, notes, and snippets.

@madwork
madwork / travis.yml
Last active Aug 13, 2019
Percona Server for MySQL with Travis CI (trusty)
View travis.yml
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
View bench-hash.rb
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
ruby Digest::* benchmark
View bench-digest.rb
# 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 Apr 5, 2019
Compile Ruby
View .gitignore
/*
!.gitignore
!ruby-build.sh
@madwork
madwork / tree.rb
Created Mar 7, 2019
Tree with apples
View tree.rb
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 Feb 19, 2019
URI parse parameters
View bench.rb
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",
View allocator_bench.md
@madwork
madwork / stripe-1.58.0_test.rb
Created Mar 14, 2017
Self executable gist for StripeObject marshalling issue
View stripe-1.58.0_test.rb
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 Mar 10, 2017
Self executable gist
View association_ids.rb
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 Sep 24, 2015
Pry confie file
View .pryrc
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'