Skip to content

Instantly share code, notes, and snippets.

View hosh's full-sized avatar

Ho-Sheng Hsiao hosh

  • Remine
  • Phoenix, AZ
View GitHub Profile
# Mock, this isn't real
$ rake db:schema:version
-> saves to db/schema/schema-20100403232.rb
# Now you don't have the problem with the timestamp embedded
# into the db/schema.rb every time you do a db:schema:dump
module Animal
def self.included(base)
base.extend(ClassMethods)
end
module ClassMethods
def say
"animal"
end
end
@hosh
hosh / person.rb
Created April 20, 2010 14:49
Sample Remarkable Macros
# In app/models/person.rb
class Person < ActiveRecord::Base
belongs_to :organization
validates_presence_of :name
validates_presence of :email
validates_uniqueness_of :email
end
require 'machinist/active_record'
require 'sham'
require 'faker'
# The one below is from an older version. In my newer version that works with rspec2,
# blueprints.rb is located in spec/support and the line below matches that. The advantage
# is that the generated spec_helper automatically loads anything under spec/support
require File.expand_path('blueprints.rb', File.dirname(__FILE__) + '/../spec/')
puts '', "Accounts ..."
I don't need this right now but I will need them for this current project over the summer.
Here's what I'm thinking:
- Build it on top of RESTClient
- On the surface, it should be compatible with ActiveResource
- Maybe take advantage of .to_model interface with ActiveORM in Rails3
- Use Addressable as Jesse suggests, to construct the URL
- Defaults to Yajl, switchable to JSON gem
- Defaults to Nokogiri + libxml2
- Pluggable backend: Net::HTTP or EventMachine's HTTP
# Package for inspecting descendents of ActiveRecord and ActionMailer in a simple tree form.
# Works with Rails 2.3.5
# INSTALL
# Drop this into lib/tasks
# USAGE
# rake stats:models
# rake stats:mailers
task :after_update_code, :roles => [:db] do
run <<-EOF
cd #{release_path} &&
rm -fr db && ln -ns #{shared_path}/db db &&
cp config/database.yml.production config/database.yml &&
git submodule update --init
EOF
end
@hosh
hosh / gist:183912
Created September 9, 2009 17:32
Useful git aliases
Some useful git aliases
[alias]
co = checkout
info = config --list
last = log -n 1
rollback = reset HEAD~1
unindex = reset HEAD
ready = "!git add -u . ; git diff --cached"
#!/usr/bin/ruby
require 'rubygems'
require 'json'
require 'pp'
pp JSON.parse(STDIN.read)
#!/bin/sh
# README:
# Having had to use MacOSX, I still prefer using Visor + MacVIM. However, Visor uses Terminal.app.
# Unlike iTerm, Terminal does not support changing the name of the tab. There are two hacks out in
# the wild:
# (1) Run a background process with the name you want to use
# (2) Hardlink ssh, then call that hardlinked ssh
#
# This script automates the method (2), however, instead of using ssh, we use screen. This has the
# additional bonus of being able to access screen's ability to detach sessions.