Skip to content

Instantly share code, notes, and snippets.

View altamic's full-sized avatar

Michelangelo Altamore altamic

View GitHub Profile
# ~/.irbrc file
# From http://giantrobots.thoughtbot.com/2008/12/23/script-console-tips
require 'rubygems'
require 'wirble'
Wirble.init
Wirble.colorize
# Easily print methods local to an object's class
class Object
initializer "time_formats.rb",
%q{def quarter(month)
(((month - 1) / 3) + 1) if (1..12).member? month
end
ActiveSupport::CoreExtensions::Time::Conversions::DATE_FORMATS[:quarter] = lambda { |time| time.strftime("Q#{quarter(time.month)}-%y") }
}
What is this life if, full of care,
We have no time to stand and stare.
-- from "Leisure," by W.H. Davies
# deploy.rb
require 'yaml'
APP_CONFIG = YAML.load(File.read(RAILS_ROOT + "/config/app_config.yml"))
default_run_options[:pty] = true
set :user, APP_CONFIG['user']
set :domain, APP_CONFIG['domain']
set :application, APP_CONFIG['application']
module DelegateAttributes
def self.included(base)
base.class_eval do
extend ClassMethods
end
end
module ClassMethods
def delegate_or_override(*methods)
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
#! /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
# 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)
# 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

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.