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 Hash | |
def deep_has_key?(key) | |
self.has_key?(key) || any? {|k, v| v.deep_has_key?(key) if v.is_a? Hash} | |
end | |
alias :deep_include? :deep_has_key? | |
alias :deep_key? :deep_has_key? | |
alias :deep_member? :deep_has_key? | |
def deep_has_value?(value) | |
self.has_value?(value) || any? {|k,v| v.deep_has_value?(value) if v.is_a? Hash} |
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
# Create a role user (no perms). Fire up the console rails c | |
$> Role.create(:title=>'User') | |
# In your Gemfile add | |
gem 'oa-oauth', :require => 'omniauth/oauth' | |
# At the beginning of devise.rb. You can also create a yaml file and instantiate when Rails begin | |
# For shake of simplicity I added the credentials at devise.rb | |
Facebook = Rails.env.development? ? {:app_id => 2621xxx, :secret => 'e81f33d042xxxxx'} : | |
{:app_id => 1749xxx9, :secret => '13c11be6628dc1xxxx'} |
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
# mkdir -p lib/templates/rails/scaffold_controller/ | |
# Put this under lib/templates/rails/scaffold_controller/controller.rb | |
class <%= controller_class_name %>Controller < ApplicationController | |
respond_to :html, :json | |
<% unless options[:singleton] -%> | |
expose(:<%= table_name %>) { <%= orm_class.all(class_name) %> } | |
<% end -%> | |
expose(:<%= file_name %>) |
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
#!/usr/bin/ruby | |
require 'rss' | |
# Usage | |
# $ ./railscasts.rb http://railscasts.com/subscriptions/YOURRAILSCASTRSS/\/ | |
# episodes.rss | |
# OR | |
# $ ./railscasts.rb | |
p 'Downloading rss index' |
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
# Install rvm system-wide | |
bash -s stable < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer ) | |
# Update the packages | |
apt-get update | |
apt-get upgrade | |
apt-get install build-essential | |
# get the packages required by ruby | |
rvm pkg install zlib |
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
source :rubygems | |
gem 'rspec' | |
gem 'capybara' | |
gem 'json' |
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
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | |
" /etc/vim/vimrc.local V1.1.12 2019-07-30 https://gist.github.com/mikehaertl/1612035 | |
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | |
" | |
" A Vundle based Vim configuration with globally shared plugins on Ubuntu. | |
" | |
" This is a Vundle based Vim setup that keeps all plugins in a global | |
" directory, namely /etc/vim/bundle. It's trimmed towards PHP development | |
" with Yii. | |
" |
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
# State - allow an object to alter its behaviour when its internal state | |
# changes. The object will appear to change its class. | |
# Key idea - introduce an abstract class called SomethingState to represent the | |
# states of the object. Subclasses of the abstract class implement | |
# state-specific behaviour. | |
class Person | |
attr_accessor :state, :name |
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
rails g scaffold Book title:string description:text | |
rails g scaffold Pubhouse title:string address:text | |
rails g model BookPubhouse book_id:integer pubhouse_id:integer | |
rake db:migrate |
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
set :shared_children, shared_children << 'tmp/sockets' | |
namespace :deploy do | |
desc "Start the application" | |
task :start, :roles => :app, :except => { :no_release => true } do | |
run "cd #{current_path} && RAILS_ENV=#{stage} bundle exec puma -b 'unix://#{shared_path}/sockets/puma.sock' -S #{shared_path}/sockets/puma.state --control 'unix://#{shared_path}/sockets/pumactl.sock' >> #{shared_path}/log/puma-#{stage}.log 2>&1 &", :pty => false | |
end | |
desc "Stop the application" | |
task :stop, :roles => :app, :except => { :no_release => true } do |
OlderNewer