This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 40+ newbie rails mistakes | |
| themes: | |
| Build for failure | |
| expect services to be slow | |
| expect services to be unavailable | |
| Build so components can be easily replaced | |
| Build so code can be easily reused | |
| mistakes: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function do_nothing() { | |
| return false; | |
| } | |
| // prevent a second click for 10 seconds. :) | |
| $('.prevent_doubleclick').live('click', function(e) { | |
| $(e.target).click(do_nothing); | |
| setTimeout(function(){ | |
| $(e.target).unbind('click', do_nothing); | |
| }, 10000); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| dictionary = File.read('/usr/share/dict/words').split("\n") | |
| dictionary = dictionary.select { |word| | |
| word.length > 3 && word.length < 7 | |
| } | |
| word_picked = dictionary[rand(dictionary.size)] | |
| system %(say "#{word_picked}") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Use "bundle install --path vendor/bundler" | |
| source :rubygems | |
| gem 'mysql' | |
| gem 'rails', '~> 3.0' # rails 3! | |
| gem 'hoptoad_notifier' | |
| gem 'app_settings', :git => 'git://github.com/ssoroka/app_settings.git' | |
| gem 'ignore_nil' # eg: ignore_nil { user.account.config.name.strip } | |
| gem 'less' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $:<< '../lib' << 'lib' | |
| require 'rubygems' | |
| require 'eventmachine' | |
| require 'em-synchrony' | |
| EM.run { | |
| EM.synchrony { | |
| loop do | |
| begin |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Rubinius Crash Report #rbxcrashreport | |
| Error: signal SIGSEGV | |
| [[Backtrace]] | |
| 0 rbx 0x00000001000212e0 _ZN8rubiniusL12segv_handlerEi + 160 | |
| 1 libSystem.B.dylib 0x00007fff8044866a _sigtramp + 26 | |
| 2 ??? 0x00007fff5fbf3490 0x0 + 140734799754384 | |
| 3 rbx 0x00000001001c8d93 _ZN8rubinius12ObjectWalker4nextEv + 51 | |
| 4 rbx 0x00000001001276f6 _ZN8rubinius6System14vm_find_objectEPNS_2VMEPNS_5ArrayEPNS_6ObjectEPNS_9CallFrameE + 422 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Use feature, background, and scenario blocks to write acceptance tests in test/unit | |
| # which are really just integration tests. include capybara or webrat or something and voila. | |
| # test/acceptance_helper.rb | |
| require 'test_helper' | |
| module ActionDispatch | |
| class AcceptanceTest < ActionDispatch::IntegrationTest | |
| class << self | |
| alias :background :setup |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module ActiveRecord | |
| class SQLCounter | |
| IGNORED_SQL = [/^PRAGMA (?!(table_info))/, /^SELECT currval/, /^SELECT CAST/, /^SELECT @@IDENTITY/, /^SELECT @@ROWCOUNT/, /^SAVEPOINT/, /^ROLLBACK TO SAVEPOINT/, /^RELEASE SAVEPOINT/, /^SHOW max_identifier_length/] | |
| # FIXME: this needs to be refactored so specific database can add their own | |
| # ignored SQL. This ignored SQL is for Oracle. | |
| IGNORED_SQL.concat [/^select .*nextval/i, /^SAVEPOINT/, /^ROLLBACK TO/, /^\s*select .* from all_triggers/im] | |
| def initialize | |
| $queries_executed = [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env ruby | |
| # ONE-LINE INSTALL INSTRUCTIONS: | |
| # wget --no-check-certificate https://raw.github.com/gist/1065081/git-compare; chmod u+x git-compare; mv git-compare `which git-status | ruby -e "puts STDIN.read.split(/\//)[0..-2].join('/')"`/ | |
| $remote = 'origin' | |
| def usage | |
| puts %( | |
| opens commits in github's compare feature. Commits must be pushed (remote "origin" is default) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'objectdb' | |
| db = ObjectDB.new | |
| user = {:name => 'steve', :domain => 'go_fish.com', :customer_since => Time.now.to_s} | |
| db.set('[email protected]', user) | |
| db.get('[email protected]') | |
| => {"name"=>"steve", "domain"=>"go_fish.com", "customer_since"=>"Sun Jul 31 02:19:51 -0500 2011"} |