Skip to content

Instantly share code, notes, and snippets.

View altamic's full-sized avatar

Michelangelo Altamore altamic

View GitHub Profile
@altamic
altamic / this is how I see it
Created December 15, 2009 23:54 — forked from anonymous/gist:257152
randpath
def rand_path(args)
path_index = (rand()*args.size).to_i
case args[path_index]
when Array then rand_path(args[path_index])
when Proc then args[path_index].call
else
puts "Discarded #{args[path_index].class} argument"
end
end
============================
= SCREEN SHARING PROCEDURE =
============================
Use (or customize) screenrc on:
http://gist.github.com/252539
Friend must have a UNIX account @hostname
reachable through ssh
= Host: user@hostname =
# /etc/screenrc
# rubynetto gnu screen sharing
shell -${SHELL}
caption always "%n(%t) : %C"
defscrollback 2048
startup_message off
hardstatus on
hardstatus alwayslastline "%-Lw%{= BW}%50>%n%f* %t%{-}%+Lw%< %=%D %M %d %c"
# ruby_koans by EdgeCase for http://rubynetto.cataniarb.org
# The path to Ruby Enlightenment starts with the following:
begin
require 'highline/import'
rescue LoadError
require 'rubygems'
require 'highline/import'
end

Martin DeMello's Gooey Challenge

Original URL: http://hackety.org/2008/06/12/martinDemellosGooeyChallenge.html

June 12th 12:57
by why

Martin DeMello:

One of the most interesting facets of a desktop GUI system is how easy it makes it to go off the beaten track, particularly how well you can add “first class” components to the system. (Using ‘first class’ here to mean ‘on an equal footing with the widgets supplied by the toolkit’). Also, as a ruby programmer, I’d naturally rather not drop down into C (or Java) to do this.

# produce an array of active record models for a ruby on rails app
# by Michelangelo Altamore
def _models
Dir.new(File.join(RAILS_ROOT, 'app', 'models')).select do |f|
f =~ /\.rb$/
end.map do |file|
model = file.gsub!(/\.rb$/, '').camelize
if model.constantize.ancestors.include?(ActiveRecord::Base)
model
# purge.rb
def delete_if_existent(file_name)
run "\[ -e #{file_name} \] && rm #{file_name}"
end
# Delete unnecessary files
%w(README public/index.html public/favicon.ico public/robots.txt public/images/rails.png).each do |file_name|
delete_if_existent(file_name)
#! /bin/bash
# erb2haml
# by Michelangelo Altamore
# Obtains a file list having an html.erb extension
# under the current dir and convert each file
# to haml format with html.haml extension.
# It requires haml gem.
for erb_file in `find . -name *.html.erb`; do
class ToHaml
def initialize(path)
@path = path
end
def convert!
Dir["#{@path}/**/*.erb"].each do |file|
`html2haml -rx #{file} #{file.gsub(/\.erb$/, '.haml')}`
end
end
module DelegateAttributes
def self.included(base)
base.class_eval do
extend ClassMethods
end
end
module ClassMethods
def delegate_or_override(*methods)