| # In response to: | |
| # http://mlomnicki.com/ruby/tricks-and-quirks/2011/02/10/ruby-tricks2.html | |
| # Ruby 1.9.2 has some neat stuff that lets us make a readable | |
| # alternative case statement that calls each method in turn. | |
| # 1.9.2 features used: | |
| # * hashes are ordered in 1.9.2 | |
| # * cool JSON-style hash syntax | |
| # * concise lambda syntax |
| require 'omniauth/core' | |
| require 'digest/md5' | |
| require 'rest-client' | |
| require 'multi_json' | |
| module OmniAuth | |
| module Strategies | |
| class Lastfm | |
| include OmniAuth::Strategy |
| module System | |
| extend self | |
| def cpu_count | |
| return Java::Java.lang.Runtime.getRuntime.availableProcessors if defined? Java::Java | |
| return File.read('/proc/cpuinfo').scan(/^processor\s*:/).size if File.exist? '/proc/cpuinfo' | |
| require 'win32ole' | |
| WIN32OLE.connect("winmgmts://").ExecQuery("select * from Win32_ComputerSystem").NumberOfProcessors | |
| rescue LoadError | |
| Integer `sysctl -n hw.ncpu 2>/dev/null` rescue 1 | |
| end |
| # Hoptoad integration example. | |
| task "deploy:before" => "isolate:dotgems" do | |
| if /\.gems/ =~ `git status` | |
| abort "Changed gems. Commit '.gems' and deploy again." | |
| end | |
| ENV["TO"] = Deploy.env | |
| end |
| easterEgg.BadWorder.list={ | |
| "4r5e":1, | |
| "5h1t":1, | |
| "5hit":1, | |
| a55:1, | |
| anal:1, | |
| anus:1, | |
| ar5e:1, | |
| arrse:1, | |
| arse:1, |
| #!/bin/bash -e | |
| # | |
| # This script will empty all RVM default gemsets in parallel. | |
| # | |
| rubies=($(rvm list strings)) | |
| echo "Emptying default gemsets for rubies: ${rubies[*]}"; | |
| for ruby in "${rubies[@]}" |
Rails 3.2 ships with a simple FileWatcher that only reloads your app if any of the files changed.
Besides, it also provides a mechanism to hook up your own file watcher mechanism, so we can use tools like FSSM that hooks into Mac OS X fsevents. This is an example on how to hook your own mechanism (you need Rails master, soon to be Rails 3.2):
-
Copy the
2_file_watcher.rbfile below tolib/file_watcher.rb -
Add the following inside your Application in
config/application.rb
if Rails.env.development?
This installs a patched ruby 1.9.3-p327 with various performance improvements and a backported COW-friendly GC, all courtesy of funny-falcon.
You will also need a C Compiler. If you're on Linux, you probably already have one or know how to install one. On OS X, you should install XCode, and brew install autoconf using homebrew.
| #!/usr/bin/env ruby | |
| require 'fiber' | |
| # A resumable, recursive descent JSON parser, using Fibers. | |
| # http://www.negativecode.com/posts/2012/03/26/fibers-resumable-recursive-descent-json-parsing/ | |
| class Parser | |
| Result = Struct.new(:value) | |
| def initialize |