Skip to content

Instantly share code, notes, and snippets.

View wconrad's full-sized avatar

Wayne Conrad wconrad

View GitHub Profile
@wconrad
wconrad / big_pattern_matcher.rb
Created July 7, 2012 13:37
big_pattern_matcher
# -*- coding: utf-8 -*-
# Given multiple regular expressions and a string to match them
# against, call a method on a receiver that corresponds to the matched
# expression.
#
# see example.rb
class BigPatternMatcher
@wconrad
wconrad / bundler_environment
Last active December 28, 2015 03:29
Script to demonstrate [an alleged bug in bundler, in that requiring bundler/setup can modify the Gemfile.lock. See: https://github.com/bundler/bundler/issues/2710
Note: This is the output of "bundle env" _after_ the test script has run. The Gemfile and Gemfile.lock therefore show the modified state of those two file, not their original state.
Bundler 1.3.5
Ruby 1.9.3 (2013-06-27 patchlevel 448) [i686-linux]
Rubygems 2.0.7
rvm 1.22.9 (stable)
GEM_HOME /home/wayne/.rvm/gems/ruby-1.9.3-p448
GEM_PATH /home/wayne/.rvm/gems/ruby-1.9.3-p448:/home/wayne/.rvm/gems/ruby-1.9.3-p448@global
Bundler settings
@wconrad
wconrad / remove_some_colons_spec.rb
Created July 18, 2014 15:16
Test case for a question asked in the SO ruby chat room
describe "#remove_some_colons" do
it "should preserve an empty string" do
expect(remove_some_colons("")).to eq ""
end
it "should remove a lone colon" do
expect(remove_some_colons(":")).to eq ""
end
@wconrad
wconrad / unindent.rb
Last active August 29, 2015 14:06 — forked from avdi/unindent.rb
TEXT = <<EOF
See, the interesting thing about this text
is that while it seems like the first line defines an indent
it's actually the last line which has the smallest indent
there are also some blank lines
both with and without extra spaces in them
and it just goes on and on
@wconrad
wconrad / extra_query_when_part_of_pk_not_selected.rb
Last active August 29, 2015 14:15
Composite_primary_key issue: extra query when part of primary key not selected
gem "composite_primary_keys", "7.0.13"
gem 'activerecord', '4.1.9'
gem 'sqlite3'
require "composite_primary_keys"
require 'active_record'
require 'logger'
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
ActiveRecord::Base.logger = Logger.new(STDOUT)
@wconrad
wconrad / Gemfile
Last active August 29, 2015 14:15
Show stack trace when more than 1000 expression in "in" clause. Arel 5 + oracle
source "https://rubygems.org"
gem "activerecord", "4.1.9"
gem "activerecord-oracle_enhanced-adapter", "1.5.5"
gem "ruby-oci8"
gem "arel", "5.0.1.20140414130214"
@wconrad
wconrad / Gemfile
Created February 23, 2015 14:37
reproduce oracle-enhanced-adapter issue i546 (rails42: missing right paren when creating table with timestamp)
source "https://rubygems.org"
gem "activerecord", "~> 4.2.0"
gem "activerecord-oracle_enhanced-adapter",
git: '[email protected]:rsim/oracle-enhanced.git',
branch: 'rails42',
ref: '518dc3cf6a1f6e3593751d30d392518dc69d1a3a'
gem "ruby-oci8"
gem "arel", "~> 6.0.0"
@wconrad
wconrad / parser.rb
Created June 30, 2015 17:50
recursive descent expression parser
# expr ::= factor ( addop factor ) *
# addop ::= '+' | '-'
# factor ::= signed_term ( mulop signed_term ) *
# mulop ::= '*' | '/'
# signed_term = '-' ? term
# term ::= number | '(' expr ')'
# number ::= /[+-]\d+(\.\d*)?/
require "strscan"
@wconrad
wconrad / stdout
Created July 31, 2015 11:47
gitalytics run on large repo
wayne@treebeard:~/work1$ time gitalytics
Carl McNealy has made 1690 commits between 286 days. He/she did something useful on 221 of those days.
Production has made 2461 commits between 2274 days. He/she did something useful on 107 of those days.
Wayne Conrad has made 8505 commits between 2265 days. He/she did something useful on 1153 of those days.
Brian Stemshorn has made 358 commits between 361 days. He/she did something useful on 132 of those days.
Julie Peters has made 17 commits between 274 days. He/she did something useful on 7 of those days.
Sam Kellogg has made 33 commits between 238 days. He/she did something useful on 23 of those days.
Production User has made 1 commits between 1 days. He/she did something useful on 1 of those days.
brians has made 4 commits between 2 days. He/she did something useful on 2 of those days.
devel has made 17 commits between 391 days. He/she did something useful on 5 of those days.
@wconrad
wconrad / gist:094c2adc97f88f8352d2
Created October 14, 2015 13:45
Monkey-patching an ActiveRecord connection to test a query optimization
it "does only one query" do
connection = Dest::Base.connection
def connection.query_count
@query_count || 0
end
def connection.exec_query(*args)
@query_count ||= 0
@query_count += 1
super
end