Skip to content

Instantly share code, notes, and snippets.

View mirzalazuardi's full-sized avatar
🙃

Mirzalazuardi Hermawan mirzalazuardi

🙃
View GitHub Profile
@jodosha
jodosha / hash.rb
Created February 4, 2009 18:37
Ruby's Hash deep search
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}
@PanosJee
PanosJee / refinery_omniauth.rb
Created March 17, 2011 22:58
Login / Register to Refinery with Omniauth (facebook, twitter, openid, etc)
# 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'}
@haldun
haldun / gist:997752
Created May 29, 2011 12:48
Controller template for decent exposure
# 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 %>)
@samqiu
samqiu / railscasts.rb
Last active December 9, 2022 03:49
Download free Railscast video
#!/usr/bin/ruby
require 'rss'
# Usage
# $ ./railscasts.rb http://railscasts.com/subscriptions/YOURRAILSCASTRSS/\/
# episodes.rss
# OR
# $ ./railscasts.rb
p 'Downloading rss index'
@bradmontgomery
bradmontgomery / rvm_apache_passenger.txt
Created January 10, 2012 04:45
RVM + Apache + passenger setup for Ubuntu
# 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
@timurvafin
timurvafin / Gemfile
Created January 12, 2012 01:32
Integration tests with rspec, capybara and selenium
source :rubygems
gem 'rspec'
gem 'capybara'
gem 'json'
@mikehaertl
mikehaertl / vimrc.local
Last active February 18, 2021 14:44
A global vim configuration on Ubuntu that uses Vundle. Just put it in /etc/vim/vimrc.local and follow the instructions
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" /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.
"
@travisjeffery
travisjeffery / state_pattern.rb
Created March 11, 2012 01:08
State Pattern in Ruby
# 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
@Mikke
Mikke / 01_step.sh
Created March 13, 2012 20:35
Rails 3 has_many use checkboxes and multiple select in the form
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
@joelmoss
joelmoss / gist:2470666
Created April 23, 2012 12:37
Capistrano recipe for Puma start/stop/restarts
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