Skip to content

Instantly share code, notes, and snippets.

View indirect's full-sized avatar

André Arko indirect

View GitHub Profile
@indirect
indirect / .gitconfig
Created August 15, 2010 07:06
git command to track a remote branch
[alias]
track = !git branch --set-upstream "$(git name-rev --name-only HEAD)"
# Use like:
# [repo](master)$ git track origin/master
# Branch master set up to track remote branch master from origin.
@indirect
indirect / s.sh
Created August 19, 2010 22:47
one command for RSpec 1 and 2
# easy spec running
function s {
if grep -q -i "RSpec.configure do" spec/spec_helper.rb; then
# echo "rspec2!"
if [ -z "$*" ]; then
rspec -fs -c spec
else
rspec -fs -c $*
fi
else
@indirect
indirect / rc.sh
Created August 19, 2010 22:52
rails console alias for both 2 and 3
# Rails 2 and Rails 3 console
function rc {
if [ -e "./script/console" ]; then
./script/console $@
else
rails console $@
fi
}
>> Gem::Requirement.new("~>3.0.0.rc").satisfied_by? Gem::Version.new("3.0.0.a")
=> true
>> Gem::Requirement.new("~>3.0.0").satisfied_by? Gem::Version.new("3.0.0.a")
=> true
>> Gem::Requirement.new("~>3.0.0.0").satisfied_by? Gem::Version.new("3.0.0.a")
=> true
>> Gem::Requirement.new("~>3.0.0.0.0").satisfied_by? Gem::Version.new("3.0.0.a")
=> true
>> Gem::Requirement.new("~>3.0.0.0.0.0").satisfied_by? Gem::Version.new("3.0.0.a")
=> true
@indirect
indirect / gist:631628
Created October 18, 2010 02:49
improved git prompt yay
# [andre ~/.bash](master)$ # clean working directory
# [andre ~/.bash](master⚡)$ # dirty working directory
# [andre ~/.bash](master~2)$ # checked out revision not a branch
# [andre ~/.bash](branch)$ # checked out branch with same commits as master
function parse_git_dirty {
[[ $(git status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]] && echo "⚡"
}
function parse_git_branch {
@indirect
indirect / HandBrakeCLIBatch
Created December 20, 2010 18:24
a script to recursively handbrake-ify your avis and mkvs
#!/usr/bin/env ruby
require 'optparse'
options = {
:verbose => false,
:preset => "High Profile"
}
OptionParser.new do |opt|
opt.banner = "Usage: HandBrakeCLIBatch [-v | -p preset] [source] [destination]"
@indirect
indirect / gist:773910
Created January 11, 2011 02:37
remove ssh known hosts by hostname or line number
# remove ssh known host by name
# -n [num] removes by line number
function ssh-rm-host () {
if [ "$1" == "-n" ]; then
sed -i old $2d ~/.ssh/known_hosts
else
ssh-keygen -R $1
fi
}
@indirect
indirect / gist:810016
Created February 3, 2011 19:32
Bleything's IRB history hacks
# Ben Bleything's IRB history hacks
# from RubyConf 2007, 2-4 November
# Lists the last how_many lines of history (defaults to 50). Aliased to h.
def history( how_many = 50 )
history_size = Readline::HISTORY.size
# no lines, get out of here
puts "No history" and return if history_size == 0
@indirect
indirect / spark.rb
Created March 11, 2011 21:44
spark, a tiny campfire library
require 'uri'
require 'json'
require 'net/https'
# spark, a tiny Campfire library
# Usage:
# c = Spark::Campfire.new('subdomain', 'abc123')
# r = c.room_named "Room Name"
# r.say "hi there"
@indirect
indirect / snippet.rb
Created March 23, 2011 19:47
Fix Builder's attribute escaping
# Unfortunately, Builder's _attr_value method is broken. :( This means that XML
# created with Builder could very well be invalid, have gaping security holes,
# or simply lose any newline characters that happen to be in attributes. Here
# is the original method, from xmlmarkup.rb:310:
#
# def _attr_value(value)
# case value
# when Symbol
# value.to_s
# else