Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
committing badassery

Jordan Ritter jpr5

💭
committing badassery
View GitHub Profile
@jpr5
jpr5 / 1_sample_database.yml
Created Nov 22, 2010
example of how you'd specify multiple repos in a database.yml for DataMapper
View 1_sample_database.yml
development:
repositories:
default: &balls_defaults
adapter: mysql
host: localhost
database: balls
username: root
password: ""
dongs: &dongs_defaults
adapter: mysql
@jpr5
jpr5 / DefaultKeyBinding.dict
Created Oct 14, 2010
My OSX system-wide keybinding overrides (readline/emacs bindings)
View DefaultKeyBinding.dict
{
"~f" = "moveWordForward:";
"~b" = "moveWordBackward:";
"~<" = "moveToBeginningOfDocument:";
"~>" = "moveToEndOfDocument:";
"~v" = "pageUp:";
"^v" = "pageDown:";
"~d" = "deleteWordForward:";
"~^h" = "deleteWordBackward:";
"~\Uf728" = "deleteWordForward:";
@jpr5
jpr5 / 1_DM_refcode_type.rb
Created Sep 24, 2010
DM1 example of using RefCode DM custom property (useful for avoiding outside exposure of internal ids) w/ RetrySaveMixin
View 1_DM_refcode_type.rb
require 'digest/sha1'
class RefCode < ::DataMapper::Property::String
required true
unique_index true
default proc { |_, prop| prop.class.generate(prop.length) }
# Setting :format before passing on the initialization chain will cause
# dm-validations (if present) to auto-add a format validation for us.
# For some reason setting :length is not doing the same, so our format
View NewRelic 2.13.1 + Rails 2.3.3 exception
2010-09-20 15:29:33 INFO [127.0.0.1] >> "GET /newrelic/threads HTTP/1.0"
2010-09-20 15:29:33 FATAL /!\ FAILSAFE /!\ Mon Sep 20 15:29:33 -0700 2010
Status: 500 Internal Server Error
compile error
(erb):17: syntax error, unexpected ';'
...with_index do | thread, i | -; frobnitz.concat "\n<tr class=...
^
(erb):27: syntax error, unexpected ';'
; end -; frobnitz.concat "\n"
^
View Pathname problems
# The last one is the important lesson -- if *any* component of the path has a
# symlink in it (not just the *last* component), Pathname#relative_path_from can
# still produce the wrong outcome.
#
# Admittedly, the example here would actually work because both the real dir and
# symlinked dir are both at the same level of path nesting. This example is just
# to demonstrate that Pathname#symlink? is an insufficient test in determining
# whether or not to call Pathname#realpath.
irb(main):001:0> require 'pathname'
View complete_and_utter_ruby_fail.rb
#!/usr/bin/ruby
s = "I really think this regexp engine sucks, why don't they just use PCRE?"
re = /((\w+\s*)+ regexp)$/
re.match(s)
puts "NIH, muthafuckaz, NIH!!!!!!!!" # p.s you'll never see this line
View 1_results @ dm-core 62ab0044, dm-types 98593c07
# With Enum
creating 20 models took: 0.830000 0.010000 0.840000 ( 0.833432)
user system total real
Enum: 0.080000 0.000000 0.080000 ( 0.082003)
Decimal: 0.050000 0.000000 0.050000 ( 0.050160)
DateTime: 0.040000 0.000000 0.040000 ( 0.046490)
String: 0.080000 0.000000 0.080000 ( 0.077332)
Integer: 0.030000 0.000000 0.030000 ( 0.033848)
Boolean: 0.060000 0.000000 0.060000 ( 0.052100)
View monkey.rb
# The default DM property doesn't support serials, so we add it in here
module DataMapper
class Property
class String
accept_options :serial
end
end
end
module DataMapper::Salesforce
View 1_output.txt
# dm-core 0.10.2 <- our current point
creating 20 models took: 0.890000 0.250000 1.140000 ( 1.147287)
# dm-core v1.0.0
creating 20 models took: 1.350000 0.440000 1.790000 ( 1.791719)
# dm-core e7b5f186 <- somewhere after 1.0.0, time is climbing
creating 20 models took: 1.540000 0.520000 2.060000 ( 2.061627)
# dm-core ad298724 <- git bisect tells me this is the bad one
View gist:455046
require 'thread'
m = Mutex.new
m.lock
wt2 = Thread.new do
m.lock
sleep 2
m.unlock
end