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
#!/usr/bin/ruby | |
# Run in the root directory of a git repository with ruby commits.rb | |
# Depends upon the 'rmagic' and 'gruff' gems. | |
require 'rubygems' | |
require 'gruff' | |
commits = `git shortlog -ns`.split("\n").map { |e| e.strip.split("\t") }.map { |n, a| [a, n.to_i] } |
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
/* | |
Copyright (c) 2017 Chris Patuzzo | |
https://twitter.com/chrispatuzzo | |
Permission is hereby granted, free of charge, to any person obtaining a copy | |
of this software and associated documentation files (the "Software"), to deal | |
in the Software without restriction, including without limitation the rights | |
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
copies of the Software, and to permit persons to whom the Software is | |
furnished to do so, subject to the following conditions: |
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; |