Skip to content

Instantly share code, notes, and snippets.

@AndrewO
AndrewO / gist:1168665
Created August 24, 2011 17:48
Some steps to extract a changed vendor'd plugin into a branch off of its main repo
# Following instructions found on http://stackoverflow.com/questions/359424/detach-subdirectory-into-separate-git-repository/359759#359759
# Clone your project repo (making sure to copy all files, even hard links)
git clone --no-hard-links my_app my_active_shipping
cd my_active_shipping
# In your new repo, extract only the commits related to the vendor'd plugin and move that into the new root
git filter-branch --subdirectory-filter vendor/plugins/active_shipping/ HEAD
git reset --hard
# Clean out all of the other commits
git gc --aggressive
git prune
@AndrewO
AndrewO / browser.rb
Created August 2, 2011 20:42
A small Macruby script to display HTML piped in from STDIN.
framework 'Cocoa'
framework 'WebKit'
require 'optparse'
class Browser
attr_accessor :view
def initialize
@view = WebView.alloc.initWithFrame([0, 0, 520, 520])
@AndrewO
AndrewO / macruby_js_bridge.rb
Created August 1, 2011 21:02 — forked from mattetti/macruby_js_bridge.rb
Fixed "kCGErrorInvalidConnection: CGSGetCurrentCursorLocation: Invalid connection"; turned off plugins
framework 'Cocoa'
framework 'WebKit'
class Cat
attr_accessor :name, :age
def initialize(name = 'kitty', age=42)
@name = name
@age = age
end
@AndrewO
AndrewO / gist:958039
Created May 5, 2011 21:48
A script to find approximate numbers of last names by color.
require 'open-uri'
require 'rubygems'
require 'hpricot'
LAST_NAMES = %w{
black
white
gray
green
red
@AndrewO
AndrewO / Gemfile
Created May 4, 2011 16:57
Using AwesomePrint instead of PrettyPrint in Wrong
group :development, :test do
gem 'awesome_print', :require => "ap" # Console pretty printing
end
@AndrewO
AndrewO / gist:955522
Created May 4, 2011 16:28
A formatter for Wrong that displays full error messages when an ActiveRecord instance is invalid
# Can be placed in with your test helpers. Eventually I'm hoping to package as a gem
module Wrong
class ActiveRecordErrors < FailureMessage::Formatter
register
def match?
predicate.is_a?(Predicated::Call) &&
object_is_an_active_record?(predicate.left) &&
method_runs_validations?(predicate.method_sym) &&
failed_because_of_validations?(predicate.left)
@AndrewO
AndrewO / click_me.html
Created January 14, 2011 16:32
A barebones test to confirm zombie.js is installed correctly.
<html>
<body>
<a href="click_me.html" id="click_me">Click me</a>
</body>
</html>
@AndrewO
AndrewO / gist:702039
Created November 16, 2010 16:38
Demonstration of a race condition in MongoMapper without support for multiple atomic operators.
class Company
include MongoMapper::Document
key :name, String
key :bosses, Array
key :employees, Array
def promote!(employee)
add_to_set(:bosses, employee)
@AndrewO
AndrewO / gist:671076
Created November 10, 2010 16:30
Mongo session returning unexpected results
> var loc = db.locations.findOne()
{
"_id" : "0",
"coordinates" : {
"lng" : -74.94366060659561,
"lat" : 42.05198110294361
},
...
}
> var lat = loc["coordinates"]["lat"]
<!-- Actual javascript code sample attached to resume -->`
<html>
<body>
<script type="text/javascript">
document.write("<h1>Hello World!</h1>");
</script>
</body>
</html>