Skip to content

Instantly share code, notes, and snippets.

View davidcelis's full-sized avatar
Verified account

David Celis davidcelis

Verified account
View GitHub Profile
{
  nested: {
    check: "out this sweet nested hash"
  },
  something: "awesome",
  digit: 0.531
}
@davidcelis
davidcelis / not_class.rb
Last active February 27, 2020 22:31
NotClass
class Object
def not
NotClass.new(self)
end
end
class NotClass < BasicObject
instance_methods.grep(/^[^_]/).each { |m| undef_method m }
def initialize(object)
@davidcelis
davidcelis / gist:3012391
Created June 28, 2012 16:38 — forked from edhedges/gist:2995805
Sublime Text 2 - Useful Shortcuts (Mac OS X)

Sublime Text 2 – Useful Shortcuts (Mac OS X)

General

⌘T go to file
⌘⌃P go to project
⌘R go to methods
⌃G go to line
⌘KB toggle side bar
⌘⇧P command prompt
@davidcelis
davidcelis / lyrics
Created June 29, 2012 22:52 — forked from jhob/lyrics
Adds Rdio and Spotify support
#!/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"`
@davidcelis
davidcelis / user.rb
Created July 10, 2012 21:06
as_json override
class User < ActiveRecord::Base
has_many :friends
def as_json(options={})
options.reverse_merge! { :include => [:friends] }
super(options)
end
end
@davidcelis
davidcelis / routes.rb
Created July 11, 2012 00:32
Dynamic root routes based on whether or not a user is logged in
MyApp::Application.routes.draw do
root :to => 'pages#home', :constraints => lambda { |request| request.cookies['auth_token'] }
root :to => 'user_sessions#login'
end
@davidcelis
davidcelis / after.rb
Created July 11, 2012 17:04
define_method in a controller
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
@davidcelis
davidcelis / inflections.rb
Created July 18, 2012 17:43
Snapshot of ActiveSupport::Inflections
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')
@davidcelis
davidcelis / inflections.rb
Created July 19, 2012 16:22
Better Rails Inflections
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')
@davidcelis
davidcelis / gist:3147089
Created July 19, 2012 21:50
database.yml loads as ERb lulz
$ 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)