This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Currently, you have to roll your own associations if you want to chain scopes through collections. | |
# I'm interested to see if there is an existing (generalised) way to do this with AR. | |
# If not, feedback on the value and interface (method chaining?) for collection associations would be appreciated. | |
# gem install activerecord | |
# gem install sqlite3 | |
require 'active_record' | |
ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => ':memory:') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TagMigrator | |
class << self | |
def list_tags(search_term = nil) | |
puts Tag.where('name like ?', "%#{search_term}%").order(:name).map(&:name) | |
end | |
def migrate!(old_name, new_name) | |
if old_name.downcase == new_name.downcase | |
rename!(old_name, new_name) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1.upto(254).map.with_object({}) { |i, o| n = `dig -x 192.168.1.#{i} +short`; o[i] = n unless n.empty? } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def http_authenticate | |
user, pass = ENV['USERNAME'], ENV['PASSWORD'] | |
if request | |
basic = ActionController::HttpAuthentication::Basic | |
request.env['HTTP_AUTHORIZATION'] = basic.encode_credentials(user, pass) | |
end | |
page.driver.browser.authorize user, pass | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.highlight .err { | |
color: #a61717; | |
background-color: #e3d2d2; | |
} | |
.highlight .k { | |
font-weight: bold; | |
} | |
.highlight .o { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Heroku doesn't get on too well with Pygments: | |
# LoadError: Could not open library '/usr/local/lib/libpython2.7.a': /usr/local/lib/libpython2.7.a: invalid ELF header | |
# To fix: | |
# Gemfile | |
gem 'rubypython', '=0.5.1' | |
# config/initializers/pygments.rb | |
RubyPython.configure :python_exe => 'python2.6' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def my_action | |
response.headers['Cache-Control'] = 'no-store' if request.xhr? | |
# ... | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var MyApp = {}; | |
MyApp.memoizer = function (memo, formula) { | |
var recur, result; | |
recur = function (n) { | |
result = memo[n]; | |
if (typeof result !== 'number') { | |
result = formula(recur, n); | |
memo[n] = result; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Dependencies: jQuery | |
// Declare a namespace object for your application to avoid clobbering global variables. | |
var MyNamespace = {}; | |
// Define a 'loader' method that attaches modular functions to DOM elements. | |
MyNamespace.loader = function (el) { | |
$('[data-module]', el).each(function () { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
on run {input, parameters} | |
if (count of input) > 0 then | |
tell application "System Events" | |
set runs to false | |
try | |
set p to application process "iTerm" | |
set runs to true | |
end try | |
end tell | |
tell application "iTerm" |