Skip to content

Instantly share code, notes, and snippets.

View jpr5's full-sized avatar
💭
committing badassery

Jordan Ritter jpr5

💭
committing badassery
View GitHub Profile
# 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)
#!/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
# 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'
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"
^
@jpr5
jpr5 / 1_DM_refcode_type.rb
Created September 24, 2010 19:59
DM1 example of using RefCode DM custom property (useful for avoiding outside exposure of internal ids) w/ RetrySaveMixin
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
@jpr5
jpr5 / DefaultKeyBinding.dict
Created October 14, 2010 18:57
My OSX system-wide keybinding overrides (readline/emacs bindings)
{
"~f" = "moveWordForward:";
"~b" = "moveWordBackward:";
"~<" = "moveToBeginningOfDocument:";
"~>" = "moveToEndOfDocument:";
"~v" = "pageUp:";
"^v" = "pageDown:";
"~d" = "deleteWordForward:";
"~^h" = "deleteWordBackward:";
"~\Uf728" = "deleteWordForward:";
@jpr5
jpr5 / 1_sample_database.yml
Created November 22, 2010 18:33
example of how you'd specify multiple repos in a database.yml for DataMapper
development:
repositories:
default: &balls_defaults
adapter: mysql
host: localhost
database: balls
username: root
password: ""
dongs: &dongs_defaults
adapter: mysql
@jpr5
jpr5 / 1_notes.txt
Created December 17, 2010 22:10
Nested-Transactional Cukes in DataMapper
Depends on:
- https://github.com/datamapper/do/commit/74645c46ac9b210c5e4029853b8a23fe02defd71
- https://github.com/datamapper/dm-transactions/commit/242e60473a341a151df62ea707264f06f418b077
@jpr5
jpr5 / 1_example.rb
Created January 5, 2011 00:27
DM example of M:M through join table using two relationships.
class DocumentSet
include ::DataMapper::Resource
property :id, Serial
# First, define the immediate (intermediate) relationship.
has n, :document_maps, :child_key => [:ds_id]
# Then make another relationship that bounces through that relationship
# (:through), arriving at model Document.
@jpr5
jpr5 / 1_no_workie.rb
Created January 17, 2011 20:52
[ruby 1.8.7] nested namespaces need physical nesting for const_missing? to work
#!/usr/bin/ruby
class Balls
BALLS = 1
end
class Balls::Dongs
def doit
puts "balls = #{BALLS}"
end