Skip to content

Instantly share code, notes, and snippets.

View mkdynamic's full-sized avatar

Mark Dodwell mkdynamic

View GitHub Profile
@mkdynamic
mkdynamic / .irbrc.rb
Created August 19, 2010 20:10
my .irbrc file
# rubygems
require 'rubygems'
# active_support from rails
require 'active_support' unless ENV['RAILS_ENV']
# wirble -- colors + more
require 'wirble'
module Wirble::Colorize::Color
class << self
# rubygems
require 'rubygems'
# active_support from rails
require 'active_support' unless ENV['RAILS_ENV']
# wirble -- colors + more
require 'wirble'
module Wirble::Colorize::Color
class << self
class User < ActiveRecord::Base
end
# doesn't work:
class Item < ActiveRecord::Base
belongs_to :user
accepts_nested_attributes_for :user
end
@mkdynamic
mkdynamic / gist:674798
Created November 12, 2010 22:17
List branches with date of last commit (via git irc, @SethRobertson)
git for-each-ref --format="%(refname)" refs/heads | while read f; do echo -n $f " "; git log -n 1 --pretty=tformat:%cd; done
# Time loading files
if ENV["TIMING"] == "1"
require 'benchmark'
module Kernel
class << self
def require_with_timing(file)
puts Benchmark.measure("require #{file}") {
require_without_timing(file)
}.format("%n: %t %r")
end
@mkdynamic
mkdynamic / bench.rb
Created October 28, 2011 23:57
Rack Approach Benchmark: Class vs. Block vs. Method
require 'benchmark'
class App
def call(env)
[200, {'Content-Type' => 'text/html'}, ['ohai']]
end
end
@object = App.new
@lambda = lambda do |env|
#!/bin/bash
kill $*
[selection sortedArrayUsingComparator:^(MKShape *a, MKShape *b) {
float leftEdgeA = NSMinX([a frame]);
float leftEdgeB = NSMinX([b frame]);
if (leftEdgeA < leftEdgeB) {
return (NSComparisonResult)NSOrderedAscending;
} else if (leftEdgeA > leftEdgeB) {
return (NSComparisonResult)NSOrderedDescending;
} else {
return (NSComparisonResult)NSOrderedSame;
@mkdynamic
mkdynamic / bookmarklet.js
Created January 18, 2012 07:50
Bookmarklet to remove Wikipedia SOPA blackout
javascript:(function()%7Bdocument.getElementById('content').style.display='block';document.getElementById('mw-sopaOverlay').style.display='none'%7D)()
# Don't hide branches in your logic, like this:
def foo
return bar if thing
stuff
end
# Do this instead:
def foo
if thing
bar