Skip to content

Instantly share code, notes, and snippets.

Avatar

Daniel (Guo-Jheng) Lin dangjlin

View GitHub Profile
View postgresl_hints.sql
-- show tables
\dt
-- create a new database
# CREATE DATABASE mydb;
-- create user
# CREATE USER abhinay with password 'secret';
View rbenv_init.sh
#source ~/.bashrc
# please manually run source ~/.bashrc to load environmnet variables and path
#type rbenv
git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
rbenv install 2.3.0
rbenv global 2.3.0
ruby -v
View init_install.sh
#!/usr/bin/env bash
# usage: curl -L https://gist.githubusercontent.com/dangjlin/2dd09f80d114e54b54be89ce8b9c6336/raw/b5eb841f9989609c1c6d19c1b47cdca416435509/init_install.sh | sh
# Pre-requisites
sudo apt-get -y update
sudo timedatectl set-timezone Asia/Taipei
sudo apt-get --no-install-recommends -y install git-core zlib1g zlib1g-dev libxml2-dev libxslt-dev libc6-dev ncurses-dev automake libtool subversion pkg-config
#from digital ocean suggestion
sudo apt-get --no-install-recommends -y install autoconf bison build-essential libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libncurses5-dev libffi-dev libgdbm3 libgdbm-dev
View validation_sample.rb
module ActiveModel
module Validations
extend ActiveSupport::Concern
# ...
module ClassMethods
def validate(*args, &block)
# ...
View sample_concern.rb
module M2
extend ActiveSupport::Concern
included do
my_attr_reader :age
end
end
module M1
extend ActiveSupport::Concern
View concern3.rb
module ActiveSupport
module Concern
def append_features(base)
if base.instance_variable_defined?(:@_dependencies)
base.instance_variable_get(:@_dependencies) << self
return false
else
return false if base < self
@_dependencies.each { |dep| base.send(:include, dep) }
super
View concern2.rb
module ActiveSupport
module Concern
def append_features(base)
# ...
View append_features.rb
module M
def self.append_features(base); end
end
class C
include M
end
C.ancestors
# => [C, Object, Kernel, BasicObject]
View concern.rb
module ActiveSupport
module Concern
class MultipleIncludedBlocks < StandardError #:nodoc:
def initialize
super "Cannot define multiple 'included' blocks for a Concern"
end
end
def self.extended(base) base.instance_variable_set(:@_dependencies, [])
end
View using_concern.rb
require 'active_support'
module MyConcern
extend ActiveSupport::Concern
def an_instance_method; "an instance method"; end
module ClassMethods
def a_class_method; "a class method"; end
end
end