Skip to content

Instantly share code, notes, and snippets.

View durran's full-sized avatar

Durran Jordan durran

View GitHub Profile
@durran
durran / string.rb
Created July 5, 2012 10:42
Safe encode input strings, when they can be flagged with the wrong encoding.
class String
def force_valid_encoding
find_encoding(Encoding.list.to_enum)
end
def safe_encode(name)
force_valid_encoding
encode(name, :undef => :replace, :invalid => :replace, :replace => "")
end
@durran
durran / mongoid.rb
Created June 9, 2012 07:27
Custom database persistence.
module CustomDatabase
extend ActiveSupport::Concern
included do
store_in database: custom_database
end
module ClassMethods
def custom_database
@durran
durran / indexes.rb
Created May 31, 2012 08:37
Missing FK indexes
connection = ActiveRecord::Base.connection
connection.tables.each do |table|
columns = connection.columns(table).collect(&:name).select {|x| x.ends_with?("_id" || x.ends_with("_type"))}
indexed_columns = connection.indexes(table).collect(&:columns).flatten.uniq
unindexed = columns - indexed_columns
unless unindexed.empty?
puts "#{table}: #{unindexed.join(", ")}"
end
end
require "benchmark"
Benchmark.bm do |bm|
string = "1232wrodsfds123123"
bm.report("named char") do
10000000.times do
string =~ /[:digit:]/
end
@durran
durran / stats.txt
Created March 21, 2012 09:32
Current master stats, Mongoid.
+----------------------+-------+-------+---------+---------+-----+-------+
| Name | Lines | LOC | Classes | Methods | M/C | LOC/M |
+----------------------+-------+-------+---------+---------+-----+-------+
| Library | 23212 | 9182 | 160 | 1174 | 7 | 5 |
| Specs | 64589 | 48395 | 189 | 117 | 0 | 411 |
+----------------------+-------+-------+---------+---------+-----+-------+
| Total | 87801 | 57577 | 349 | 1291 | 3 | 42 |
+----------------------+-------+-------+---------+---------+-----+-------+
@durran
durran / ruby.txt
Created March 13, 2012 10:04
Seg faulting, Ruby style.
/Users/durran/work/origin/lib/origin.rb:2: [BUG] gc_sweep(): unknown data type 0x0(0x7ff83cd95ad0)
ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-darwin11.2.0]
-- Control frame information -----------------------------------------------
c:0020 p:---- s:0064 b:0064 l:000063 d:000063 CFUNC :require
c:0019 p:0011 s:0060 b:0060 l:000059 d:000059 TOP /Users/durran/work/origin/lib/origin.rb:2
c:0018 p:---- s:0058 b:0058 l:000057 d:000057 FINISH
c:0017 p:---- s:0056 b:0056 l:000055 d:000055 CFUNC :require
c:0016 p:0092 s:0052 b:0052 l:000051 d:000051 TOP /Users/durran/work/origin/spec/spec_helper.rb:5
c:0015 p:---- s:0050 b:0050 l:000049 d:000049 FINISH
@durran
durran / mongoid.txt
Created March 9, 2012 16:01
Mongoid spec run time.
Finished in 55.62 seconds
7407 examples, 0 failures, 3 pending
rake 48.13s user 2.03s system 82% cpu 1:00.78 total
@durran
durran / commiters.txt
Created February 27, 2012 13:32
Mongoid shortlog (committers)
@mode ➜ mongoid rvm:(-ruby-1.9.3@mongoid) git:(master) git shortlog -s -n
3153 Durran Jordan
113 Jacques Crocker
57 Chris Griego
51 Hans Hasselberg
49 Bernerd Schaefer
42 Dave Ott and Durran Jordan
41 Cyril Mougel
37 brainopia
31 Durran Jordan and Tim Pope
@durran
durran / sm.txt
Created February 23, 2012 22:41
Callback printout
#<ActiveSupport::Callbacks::Callback:0x007fe6fd1e6748 @klass=Document, @kind=:around, @chain=[#<ActiveSupport::Callbacks::Callback:0x007fe6fd3306f8 @klass=Document, @kind=:around, @chain=[#<ActiveSupport::Callbacks::Callback:0x007fe6fd3306f8 ...>], @per_key={:if=>[], :unless=>[]}, @options={:prepend=>true, :if=>[], :unless=>[]}, @raw_filter=#<StateMachine::Machine:0x007fe6fd33d5d8 @integration=StateMachine::Integrations::Mongoid, @name=:status, @attribute=:status, @events=#<StateMachine::EventCollection:0x007fe6fd33a5b8 @machine=#<StateMachine::Machine:0x007fe6fd33d5d8 ...>, @nodes=[#<StateMachine::Event name=:status_progress transitions=[:waiting_assignment => :in_progress]>], @index_names=[:name, :qualified_name], @indices={:name=>{:status_progress=>#<StateMachine::Event name=:status_progress transitions=[:waiting_assignment => :in_progress]>}, :name_to_s=>{"status_progress"=>#<StateMachine::Event name=:status_progress transitions=[:waiting_assignment => :in_progress]>}, :name_to_sym=>{:status_progress=>#<S
@durran
durran / travis.txt
Created February 22, 2012 11:51
No output on travis...
http://travis-ci.org/#!/mongoid/mongoid/jobs/720136
http://travis-ci.org/#!/mongoid/mongoid/jobs/720137
http://travis-ci.org/#!/mongoid/mongoid/jobs/720138
Only affects MRI, the JRuby output is fine for me...