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
@zenkay
zenkay / gist:3237860
Created August 2, 2012 15:19
Installation tips for RVM/Ruby on OSX 10.8 Mountain Lion

Ruby, RVM and Mountain Lion

Key problems

Mountain Lion (10.8) has three main difference compared to Lion (10.7):

  • XCode 4.4 does not install Command Line Tools by default
  • X11 isn't available anymore
  • The installed version of OpenSSL has some bugs

How to work around

@dkubb
dkubb / eager_repository.rb
Last active May 13, 2019 21:10
Eager Loading DataMapper Associations
require 'memoist'
# Usage:
#
# customers = Customer.preload(Customer.orders.line_items.item)
#
# customers.each do |customer|
# customer.orders.each do |order|
# order.line_items.each do |line_item|
# line_item.item # yay, no more N+1, only 4 queries executed !
@jpr5
jpr5 / 1_bar.rb
Created February 9, 2011 05:59
bad bug in DM/DO nested transactions (FIXED in 03ae081f28a6143478e2174ccf3bd233e82cb91b)
#!/usr/bin/ruby
[
'addressable.git', 'extlib.git',
'do.git/data_objects', 'do.git/do_mysql',
'dm-core.git', 'dm-migrations.git', 'dm-transactions.git', 'dm-do-adapter.git', 'dm-mysql-adapter-1.0.0',
].each do |path|
$:.unshift "common/gems/#{path}/lib"
end
@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_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
#!/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
@jpr5
jpr5 / 1_SELECT_construction_logic.txt
Created January 14, 2010 19:19
JOIN logic assessment, logic and fails (0.9x-current)
See associated gist for simple definitions of Project, User, Task, Answer models
referenced herein.
Summary:
I believe the logic about how JOINs are constructed needs to fundamentally
change. In order to create the correct JOIN SQL, the logic needs to be
aware of and account for how an individual query param's "links" are related
to each other *only*, instead of how they the query param's themselves
relate to each other (which is how I intepret how it works now).
@jpr5
jpr5 / fucked_dm_joins.rb
Created January 14, 2010 06:14
problem with joins in DM post-0.10.2
require "do_mysql"
require "dm-core"
require 'rubygems'
require 'ruby-debug'
Debugger.start
DataMapper::Logger.new(STDOUT, :debug)
DataMapper.setup(:default, "mysql://root@localhost/foo")