Skip to content

Instantly share code, notes, and snippets.

View indirect's full-sized avatar

André Arko indirect

View GitHub Profile
@indirect
indirect / mcd.bash
Created April 22, 2010 22:46 — forked from eventualbuddha/mcd.fish
make and then cd to a directory
# make and cd to a directory
function mcd {
mkdir -p $1
cd $1
}
@indirect
indirect / gist:382451
Created April 28, 2010 17:54
structs initialized from a hash
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")
@indirect
indirect / gist:388981
Created May 4, 2010 05:03
ruby hashes like JS objects
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
@indirect
indirect / gist:434208
Created June 11, 2010 07:47 — forked from blaine/gist:428898
Text size based on physical letter size
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;';
@indirect
indirect / Gemfile.rb
Created June 18, 2010 19:05
Platform-specific Gemfile example
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
@indirect
indirect / application_helper.rb
Created June 20, 2010 07:38
resource-aware breadcrumbs
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 << " &raquo; ".html_safe
end
@indirect
indirect / bundler.rb
Created July 29, 2010 16:02
cap tasks to invoke bundler
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
@indirect
indirect / checkout-plugins.rb
Created July 30, 2010 23:40
check out every repo from plexinc-plugins and plexinc-agents
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)
@indirect
indirect / make_repo.rb
Created July 30, 2010 23:41
create a github repo from ruby
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
@indirect
indirect / install.rb
Created August 10, 2010 21:01
Launch SickBeard at startup
#!/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