Skip to content

Instantly share code, notes, and snippets.

@tony612
tony612 / gist:3780202
Created September 25, 2012 05:50 — forked from dhh/gist:1014971
Use concerns to keep your models manageable
# autoload concerns
module YourApp
class Application < Rails::Application
config.autoload_paths += %W(
#{config.root}/app/controllers/concerns
#{config.root}/app/models/concerns
)
end
end
@tony612
tony612 / crawler_big_bang_scripts.rb
Last active December 17, 2015 19:59
A crawler used to grab all the scripts of big bang
require 'rubygems'
require 'mechanize'
agent = Mechanize.new
page = agent.get('http://bigbangtrans.wordpress.com/')
page.links.select {|l| l.text =~ /^Series/}.each do |link|
puts link.text
sub_page = link.click
@tony612
tony612 / io_exercises.io
Last active December 18, 2015 01:39
Some exercises using io-lang
// Fabonacci using recursion and non-recursion
fib := method(k,
first := 0
sum := 1
for(i, 1, k - 1, tmp := sum;sum := sum + first;first := tmp)
sum
)
for(i, 1, 10, fib(i) println)
"" println
@tony612
tony612 / gist:6208033
Created August 12, 2013 03:17
brew install macvim(7.4) on OSX 10.9 DP5 and xcode5 DP5
{tony}[1.9.3] ~ ➭ HOMEBREW_MAKE_JOBS=1 VERBOSE=1 brew install macvim 2>&1
==> Downloading https://github.com/b4winckler/macvim/archive/snapshot-70.tar.gz
Already downloaded: /Library/Caches/Homebrew/macvim-7.4-70.tar.gz
tar xf /Library/Caches/Homebrew/macvim-7.4-70.tar.gz
==> ./configure --with-features=huge --enable-multibyte --with-macarchs=x86_64 --enable-perlinterp --enable-rubyinterp --enable-tclinterp --with-ruby-command=/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby --with-tlib=ncurses --with-compiledby=Homebrew --with-local-dir=/usr/local --enable-cscope --enable-pythoninterp=yes
./configure --with-features=huge --enable-multibyte --with-macarchs=x86_64 --enable-perlinterp --enable-rubyinterp --enable-tclinterp --with-ruby-command=/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby --with-tlib=ncurses --with-compiledby=Homebrew --with-local-dir=/usr/local --enable-cscope --enable-pythoninterp=yes
configure: creating cache auto/config.cache
checking whether make set
@tony612
tony612 / chrome_shortcuts.js
Created August 12, 2013 04:35
chrome shortcuts
// https://developers.google.com/chrome-developer-tools/docs/shortcuts
// Control
Inspect elements: command+option+i
Inspect elements and open console: command+option+j
Select element: command+shift+c
Next panel: command+]
Previous panel: command+[
// Search
brew update
brew versions FORMULA
cd `brew --prefix`
git checkout HASH Library/Formula/FORMULA.rb # use output of "brew versions"
brew install FORMULA
brew switch FORMULA VERSION
git checkout -- Library/Formula/FORMULA.rb # reset formula
## Example: Using Subversion 1.6.17
#
@tony612
tony612 / middleware-rails
Last active December 21, 2015 17:09
middlewares of rails
$ rake middleware
use ActionDispatch::Static
- servers static files under "public" directory
use Rack::Lock
- locks the rest of the application to a single thread
use #<ActiveSupport::Cache::Strategy::LocalCache::Middleware:0x007fcc36ff3c00>
- flushes memory based store used internally by Rails.cache
# #!/usr/bin/env ruby
snippet #!
#!/usr/bin/env ruby
# New Block
snippet =b
=begin rdoc
${1}
=end
snippet y
@tony612
tony612 / snippet-erb
Created August 27, 2013 02:51
snippet-erb
# .erb and .rhmtl files
# Includes html.snippets
# Rails *****************************
snippet rc
<% ${1} %>
snippet rce
<%= ${1} %>${2}
snippet %
@tony612
tony612 / add_column_migration.rb
Created August 27, 2013 07:43
use Model.reset_column_information to let the modification work, and use say_with_time to explain the action..
class AddAddressToEvent < ActiveRecord::Migration
def up
add_column :events, :address, :string, :after => :lat
Event.reset_column_information
say_with_time "Update each event, which will result in all events to update their address" do
Event.find_each { |event| event.save! }
end
end