Skip to content

Instantly share code, notes, and snippets.

@krames
krames / git Prompt
Last active September 24, 2015 21:37
function parse_git_dirty {
[[ $(git status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]] && echo "*"
}
function parse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/[\1$(parse_git_dirty)]/"
}
function proml {
case $TERM in
xterm*)
@krames
krames / Python Ruby Style!
Created March 17, 2011 13:31
This script makes your mac read Monty Python and the Holy Grail using ruby
require 'open-uri'
DEBUG = true
abort("Come back when you get a mac!") unless RUBY_PLATFORM =~ /darwin/
abort("The actors have come down with a bad case of laryngitis") unless system("which -s say")
class Actor
attr_reader :voice
def initialize(voice)
@krames
krames / gist:1060577
Created July 2, 2011 14:43
Rcov rake task
namespace :test do
desc "Generate code coverage with rcov"
task :coverage do
rm_rf "doc/coverage/coverage.data"
rm_rf "doc/coverage"
mkdir "doc/coverage"
rcov = %(rcov --rails --aggregate doc/coverage/coverage.data --exclude gems --text-summary -Ilib:test --html -o doc/coverage test/**/*_test.rb)
system rcov
system "open doc/coverage/index.html" if PLATFORM['darwin']
end
@krames
krames / location.rb
Created July 15, 2011 17:22
Playing around with Geocoder
require 'rubygems'
require 'sinatra'
require 'geocoder'
get '/' do
view
end
post '/locate' do
result = nil
@krames
krames / say_tweets.rb
Created September 30, 2011 18:39
Read My Tweets
#!/usr/bin/env ruby
require "rubygems"
require "twitter"
abort("I can't let you do that Dave!") unless RUBY_PLATFORM =~ /darwin/
def remove_urls(tweet)
tweet.text.gsub(/http:\/\/[^ ]+/, '')
end
@krames
krames / railsconf.rb
Created April 18, 2012 13:20
Parse RailsConf calendar into iCal format
#!/usr/bin/env ruby
require 'rubygems'
require 'nokogiri'
require 'open-uri'
require 'icalendar'
require 'date'
@krames
krames / servers.rb
Created December 12, 2012 21:15
This is an example of the current functionality of the Rackspace Cloud Server Version 2 API
#!/usr/bin/env ruby
require 'rubygems'
require 'fog'
RACKSPACE_USERNAME = "racker"
RACKSPACE_API_KEY = "23423423"
#create connection
connection = Fog::Compute.new({
:provider => 'Rackspace',
@krames
krames / rackspace_db_patch.rb
Last active December 14, 2015 09:39
This gist contains a patch to fix Rackspace Database support in Fog 1.9.0. Please refer to https://github.com/fog/fog/pull/1615 for more information.
if Fog::VERSION == "1.9.0"
Fog::Logger.warning "PATCHING Fog::Rackspace::Databases to include latest endpoints and fix request issue"
require 'rubygems'
require 'fog'
Fog::Rackspace::Databases.send :remove_const, :DFW_ENDPOINT
Fog::Rackspace::Databases.send :remove_const, :LON_ENDPOINT
Fog::Rackspace::Databases.send :remove_const, :ORD_ENDPOINT
@krames
krames / python_traceback
Last active December 14, 2015 12:18
#This ruby code causes the attached python stacktrace require 'fog' #using Fog 1.9.0 connection = Fog::Rackspace::Databases.new :rackspace_endpoint => 'https://dfw.databases.api.rackspacecloud.com/v1.0' response = connection.list_instances
Traceback (most recent call last):
File \"/usr/lib/python2.6/dist-packages/eventlet/wsgi.py\", line 336, in handle_one_response
result = self.application(self.environ, start_response)
File \"/usr/lib/python2.6/dist-packages/newrelic-1.9.0.21/newrelic/api/web_transaction.py\", line 563, in __call__
result = application(environ, _start_response)
File \"/usr/lib/python2.6/dist-packages/newrelic-1.9.0.21/newrelic/api/object_wrapper.py\", line 220, in __call__
self._nr_instance, args, kwargs)
File \"/usr/lib/python2.6/dist-packages/newrelic-1.9.0.21/newrelic/api/function_trace.py\", line 81, in literal_wrapper
return wrapped(*args, **kwargs)
File \"/usr/lib/python2.6/dist-packages/reddwarf/common/wsgi.py\", line 147, in __call__
@krames
krames / fog_ssh_patch.rb
Created March 20, 2013 13:44
This patch makes ssh timeout configurable. Example: require 'fog' require 'fog_ssh_patch.rb' ssh = Fog::SSH.new HOST, USERNAME, :timeout => 60
if Fog::VERSION == "1.10.0"
Fog::Logger.warning "PATCHING Fog::SSH::Real so that the timeout is user configurable"
require 'rubygems'
require 'fog'
module Fog
module SSH
class Real