{
nested: {
check: "out this sweet nested hash"
},
something: "awesome",
digit: 0.531
}
This file contains 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
class Object | |
def not | |
NotClass.new(self) | |
end | |
end | |
class NotClass < BasicObject | |
instance_methods.grep(/^[^_]/).each { |m| undef_method m } | |
def initialize(object) |
This file contains 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
#!/bin/bash | |
services=(iTunes Rdio Spotify) | |
for service in "${services[@]}"; do | |
if ps axco pid,command | grep -v grep | egrep "$service\$" > /dev/null; then | |
state=`osascript -e "tell application \"$service\" to get player state as string"` | |
if [ "$state" = "playing" ] ; then | |
artist_name=`osascript -e"tell application \"$service\" to get artist of current track"` | |
song_title=`osascript -e"tell application \"$service\" to get name of current track"` | |
artist=`echo $artist_name | sed "s/[[:space:]]/%20/g"` |
This file contains 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
class User < ActiveRecord::Base | |
has_many :friends | |
def as_json(options={}) | |
options.reverse_merge! { :include => [:friends] } | |
super(options) | |
end | |
end |
This file contains 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
MyApp::Application.routes.draw do | |
root :to => 'pages#home', :constraints => lambda { |request| request.cookies['auth_token'] } | |
root :to => 'user_sessions#login' | |
end |
This file contains 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
class BeersController < ApplicationController | |
before_filter :authorize, :except => :show | |
respond_to :json | |
# GET /beers/:id.json | |
def show | |
@beer = Beer.find params[:id] | |
respond_with @beer, :api_template => :public | |
end |
This file contains 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 'active_support/inflector/inflections' | |
module ActiveSupport | |
Inflector.inflections do |inflect| | |
inflect.plural(/$/, 's') | |
inflect.plural(/s$/i, 's') | |
inflect.plural(/^(ax|test)is$/i, '\1es') | |
inflect.plural(/(octop|vir)us$/i, '\1i') | |
inflect.plural(/(octop|vir)i$/i, '\1i') | |
inflect.plural(/(alias|status)$/i, '\1es') |
This file contains 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
ActiveSupport::Inflector.inflections do |inflect| | |
inflect.clear | |
inflect.plural(/$/, 's') | |
inflect.plural(/[sxz]|[cs]h$/i, 'es') | |
inflect.plural(/[^aeiouy]o/i, 'es') | |
inflect.plural(/([^aeiouy])y/i, '\1ies') | |
inflect.singular(/s$/i, '') | |
inflect.singular(/(ss)$/i, '\1') |
This file contains 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
$ cat config/database.yml | |
<% puts "Hello from database.yml" %> | |
development: | |
adapter: sqlite3 | |
database: db/development.sqlite3 | |
pool: 5 | |
timeout: 5000 | |
$ rails console | |
Hello from database.yml | |
Loading development environment (Rails 3.2.6) |