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
# make and cd to a directory | |
function mcd { | |
mkdir -p $1 | |
cd $1 | |
} |
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 Foo < Struct.new(:foo, :bar) | |
def self.from_hash(hash) | |
new(*new.members.map{|a| hash[a] }) if hash | |
end | |
end | |
Foo.from_hash("bar" => "bagels", "foo" => "cream cheese") |
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 Hash | |
def method_missing( msg, *args ) | |
super unless args.empty? | |
if has_key?(msg) | |
[msg] | |
elsif has_key?(msg.to_s) | |
[msg.to_s] | |
else | |
nil | |
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 setTextMeasure = function (contentElement, targetMeasure, maxSize, minSize) { | |
if (!contentElement) contentElement = document.createElement('p'); | |
if (!targetMeasure) targetMeasure = 66; | |
if (!maxSize) maxSize = 16; | |
if (!minSize) minSize = 9; | |
var sizer = contentElement.cloneNode(); | |
sizer.style.cssText = 'margin: 0; padding: 0; color: transparent; background-color: transparent; position: absolute;'; |
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
source :gemcutter | |
platforms :ruby_18, :ruby_19, :rbx do | |
gem 'fast-xml-parser', :require => 'xml_parser' | |
end | |
platforms :jruby do | |
gem 'xml-parser', :require => 'xml_parser' | |
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
class ApplicationHelper | |
def breadcrumbs | |
result = "".html_safe | |
association_chain.each_with_index do |item, index| | |
# note that .name works for both classes and objects | |
result << link_to(item.name.humanize.titlecase, association_chain[0..index]) | |
result << " » ".html_safe | |
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
namespace :bundler do | |
task :create_symlink, :roles => :app do | |
set :bundle_dir, File.join(release_path, 'vendor/bundle') | |
shared_dir = File.join(shared_path, 'bundle') | |
run "rm -rf #{bundle_dir}" # in the event it already exists..? | |
run("mkdir -p #{shared_dir} && ln -s #{shared_dir} #{bundle_dir}") | |
end | |
task :bundle_new_release, :roles => :app do |
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
require 'rubygems' | |
require 'open-uri' | |
require 'json' | |
def repo_page(username, page_num = 1) | |
url = "http://github.com/api/v2/json/repos/show/#{username}?page=#{page_num}" | |
JSON.parse(open(url).read)["repositories"] | |
end | |
def repo_urls(username) |
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
github_user = "indirect" | |
github_token = "sekrit" | |
def make_repo(repo_name) | |
Net::HTTP.post_form URI.parse('http://github.com/repositories'), | |
'login' => github_user, | |
'token' => github_token, | |
'repository[name]' => repo_name | |
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
#!/usr/bin/env ruby | |
require 'fileutils' | |
`curl -s -O http://gist.github.com/raw/517993/e74c2d1c101a617201c0ded8880d9740faba588b/name.indirect.sickbeard.plist` | |
plist = File.read("name.indirect.sickbeard.plist") | |
File.open("name.indirect.sickbeard.plist", "w") do |f| | |
sb_path = File.exist?("Sick-Beard") ? File.join(Dir.pwd, "Sick-Beard") : Dir.pwd | |
f.write plist.gsub("/Users/andre/sw/Sick-Beard", sb_path) | |
end |