Skip to content

Instantly share code, notes, and snippets.

if building command-line @posterous clients, write "signature" feature which links to the blog auto-posted from (make it visible only on @posterous by including simple JavaScript)
@gilesbowkett
gilesbowkett / foo.rake
Created April 16, 2011 00:56
please correct me
namespace :myapp do
def invoke(tasks) # did I really need to write this method? aargh
tasks.each {|t| Rake::Task[t].invoke}
end
desc "dump everything (in order to re-seed)"
task :renew do
invoke(%w{db:drop db:create db:migrate})
end
end
@gilesbowkett
gilesbowkett / twitter.com.js
Created April 25, 2011 01:24
hide lame stuff on twitter.com
$().ready(function() {
$("<style type='text/css'>.trends-inner{ display: none }</style>").appendTo("head");
$("<style type='text/css'>p.promo{ display: none }</style>").appendTo("head");
});
@gilesbowkett
gilesbowkett / gem_src.bash
Created May 1, 2011 21:43
easily hop into your gems directory for whichever gemset you're currently running
gem_src() {
pushd ~/.rvm/gems/`rvm-prompt | sed -e s/\@/\\\\\@/`/gems
}
@gilesbowkett
gilesbowkett / journal_today.rb
Created May 2, 2011 03:43
real writers journal in vim
#!/opt/local/bin/ruby
# supa primitive script to access today's journal entry text file
now = Time.now
month = now.month.to_s
month = "0" + month if month.to_i < 10
day = now.mday.to_s
day = "0" + day if day.to_i < 10
date = month + day + now.year.to_s[2,3]
@gilesbowkett
gilesbowkett / user.rb
Created May 16, 2011 22:23
it doesn't have to be complicated
1 class User < ActiveRecord::Base
2 attr_accessible :password, :password_confirmation
3
4 def passwd=(new_pass)
5 self.password = self.password_confirmation = new_pass
6 end
7 end
8
~
@gilesbowkett
gilesbowkett / wtf.rb
Created May 25, 2011 21:16
Comment out one line to avoid RubyGems nonsense
49 def deprecate name, repl, year, month
50 class_eval {
51 old = "_deprecated_#{name}"
52 alias_method old, name
53 define_method name do |*args, &block| # TODO: really works on 1.8.7?
54 klass = self.kind_of? Module
55 target = klass ? "#{self}." : "#{self.class}#"
56 msg = [ "NOTE: #{target}#{name} is deprecated",
57 repl == :none ? " with no replacement" : ", use #{repl}",
58 ". It will be removed on or after %4d-%02d-01." % [year, month],
@gilesbowkett
gilesbowkett / twitter.com.js
Created June 10, 2011 17:28
twitter.com web version, minus the bullshit
1 $().ready(function() {
2 // don't show me trending topics
3 $("<style type='text/css'>.trends-inner{ display: none }</style>").appendTo("head");
4
5 // don't show me promoted tweets
6 $("<style type='text/css'>p.promo{ display: none }</style>").appendTo("head");
7
8 // don't recommend that I follow anybody
9 $("<style type='text/css'>.user-rec-component{ display: none }</style>").appendTo("head");
10
@gilesbowkett
gilesbowkett / shell.txt
Created June 10, 2011 23:10
bundler documentation imperfection
<airbook:giles> [06-10 16:05] ruby-1.8.7-p334
↪ bundle install
You can no longer specify a git source by itself. Instead,
either use the :git option on a gem, or specify the gems that
bundler should find in the git source by passing a block to
the git method, like:
git 'git://github.com/rails/rails.git' do
gem 'rails'
end
@gilesbowkett
gilesbowkett / example.rb
Created June 11, 2011 04:16
How I'm circumventing Rails STI stuff in Trucker
1 class LegacyParent < LegacyBase
2 set_table_name :widgets
3
4 # in order to differentiate subclasses in the migrations, we need to be able to get at them
5 # via ActiveRecord finders and their "type" attributes. that means we have to tell ActiveRecord
6 # that the type attribute isn't off-limits, which it seems we have to do by telling it we
7 # have some other attribute used for STI inheritance instead
8 set_inheritance_column :fake_column_name
9 def map
10 puts :wtf