Skip to content

Instantly share code, notes, and snippets.

@martinos
martinos / stats.thor
Created May 17, 2011 15:18
Stats module for thor
module Count
def count_by
self.inject({}) do |memo, elem|
key = yield elem
memo[key] ||= 0
memo[key] += 1
memo
end
end
end
@martinos
martinos / integer_cast_error.rb
Created January 7, 2011 17:26
Strange behaviour of the Integer kernel method.
irb(main):002:0> Integer("01")
=> 1
irb(main):003:0> Integer("02")
=> 2
irb(main):004:0> Integer("03")
=> 3
irb(main):005:0> Integer("05")
=> 5
irb(main):006:0> Integer("06")
=> 6
@martinos
martinos / Rakefile
Created December 31, 2010 03:52
Gem rake file with bacon support
desc "Run all the tests"
task :default => [:test]
desc "Test"
task :test do
output = 'SpecDoxOutput'
Bacon.extend Bacon.const_get(output) rescue abort "No such formatter: #{output}"
Bacon.summary_on_exit
files = []

(a gist based on the old toolmantim article on setting up remote repos)

To collaborate in a distributed development process you’ll need to push code to remotely accessible repositories.

This is somewhat of a follow-up to the previous article setting up a new rails app with git.

For the impatient

Set up the new bare repo on the server:

@martinos
martinos / vi_sudo_when_needed.sh
Created November 26, 2010 20:41
Auto sudo vi
function vi {
LIMIT=$#
local otherfile=0
for (( i=1; i<=$LIMIT; i++ ))
do
eval file='$'$i
if [[ -e $file && ! -O $file ]]
then
otherfile=1
fi
@martinos
martinos / .autotest
Created November 11, 2010 16:11
My autotest file
require 'autotest/growl'
require 'autotest/fsevent' #osx specific file changed event notification
require 'redgreen/autotest'
Autotest::Growl::show_modified_files = true #which changes prompted the autospec run
Autotest::Growl::remote_notification = true #networked growl, to work-around disappearing notifications
Autotest.add_hook :initialize do |at|
%w{.git .svn .hg .DS_Store ._* log}.each {|exception|at.add_exception(exception)}
end
@martinos
martinos / coco.rb
Created November 4, 2010 16:12
This is a test
def coco
puts "tata"
end
require 'rubygems'
require 'sinatra'
require 'grit'
require 'ruby-debug'
include Grit
class GitFilePublisher < Sinatra::Base
def initialize(repo_path, *args)
@repo = Repo.new repo_path
super(args)
include AWS::S3
bucket = Bucket.find("RemoteClipboard")
obj = bucket["jenesaispas.txt"]
obj.metadata[:subject] = "This is the subject"
obj.store
GIT_REV = `git rev-parse HEAD`
Rails.logger.info("%%%%%%%%% Starting Rails with PID: #{Process.pid}, process name: #{$0} #{ARGV.join(" ")} and git sha #{GIT_REV}")