Skip to content

Instantly share code, notes, and snippets.

View benschwarz's full-sized avatar
🏁
Making the web fast

Ben Schwarz benschwarz

🏁
Making the web fast
View GitHub Profile
$("form input[name=_method][value=delete]").parents("form").submit(function (event){
if(!confirm("Are you sure?")) {
event.preventDefault();
}
});
// Throw this into a rails-app with jquery present and it'll ask you before you delete something.
// I'd much rather implement a "delete, then offer undo" pattern, sometimes you have to go for the quick win though.

Poor Man's Deploy

  • Start a Sinatra server on port 4000
  • GET / to that server triggers a git pull and mod_rails restart
  • Hit port 4000 locally after pushing

Why?

Ϟ macruby demo.rb
undefined method `gem' for main:TopLevel (NoMethodError)
@benschwarz
benschwarz / stats.rb
Created September 16, 2009 01:30 — forked from mojombo/stats.rb
# Run the given block +num+ times and then print out the mean, median, min,
# max, and stddev of the run. For example:
#
# irb> stats(10) { sleep(rand / 100) }
# mean: 5.99ms
# median: 6.76ms
# min: 1.49ms
# max: 9.28ms
# stddev: 2.54ms
def stats(num)
@benschwarz
benschwarz / stats.rb
Created September 16, 2009 04:14 — forked from mojombo/stats.rb
# Run the given block +num+ times and then print out the mean, median, min,
# max, and stddev of the run. For example:
#
# irb> stats(10) { sleep(rand / 100) }
# mean: 5.99ms
# median: 6.76ms
# min: 1.49ms
# max: 9.28ms
# stddev: 2.54ms
def stats(num)
A few things left to do:
* Ability to add default options for each PDF, rather than having to pass it to each generate_* method call
* Doesn't check if the pdf already exists. By default, which should it do?
- Overwrite the existing file. Let your users decide what they'd like to do here.
* Consider the inclusion of css, or even generated css templates using pre existing libraries (lesscss or yerk – sass.)
Anything else?
bash-3.2$ rvm 1.8.7%rbx ; gem install rake --trace
ERROR: While executing gem ... (OptionParser::InvalidOption)
invalid option: --trace
bash-3.2$
http://ujihisa.blogspot.com/2009/06/rubygems-best-practice.html
uninitialized constant Encoding (NameError)
/Users/ben/.gem/ruby/1.8/gems/activesupport-2.3.4/lib/active_support/dependencies.rb:443:in `load_missing_constant'
/Users/ben/.gem/ruby/1.8/gems/activesupport-2.3.4/lib/active_support/dependencies.rb:80:in `const_missing'
/Users/ben/.gem/ruby/1.8/gems/activesupport-2.3.4/lib/active_support/dependencies.rb:92:in `const_missing'
/Users/ben/.gem/ruby/1.8/gems/sqlite3-0.0.3/lib/sqlite3/encoding.rb:9:in `find'
/Users/ben/.gem/ruby/1.8/gems/sqlite3-0.0.3/lib/sqlite3/database.rb:69:in `initialize'
/Users/ben/.gem/ruby/1.8/gems/activerecord-2.3.4/lib/active_record/connection_adapters/sqlite3_adapter.rb:13:in `new'
/Users/ben/.gem/ruby/1.8/gems/activerecord-2.3.4/lib/active_record/connection_adapters/sqlite3_adapter.rb:13:in `sqlite3_connection'
/Users/ben/.gem/ruby/1.8/gems/activerecord-2.3.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:223:in `send'
/Users/ben/.gem/ruby/1.8/gems/activerecord-2.3.4/lib/active_record/connection_adapter
# Use on_change :property { # do stuff here }
# to make changes to models after a property has been changed
module OnChange
def on_change(attribute, &block)
after_save do
block.call if send("#{attribute}_changed?")
end
end
end