Skip to content

Instantly share code, notes, and snippets.

View alvinang's full-sized avatar

Alvin Ang alvinang

View GitHub Profile
@alvinang
alvinang / js_fundamentals
Last active August 29, 2015 13:57
Fundamentals of Javascript - function definition and "this"
// IMPORTANT: "this" is set when a function is CALLED, not defined.
// It also depends on how it is called.
// There are 4 ways to define a function (directly affect "this" as well)
// 1. Constructor
// "this" -> new object {}
var func = new User();
// 2. Method
// "this" -> receiver (func)
@alvinang
alvinang / custom_gemfile
Last active August 29, 2015 13:56
Rails Template Generator - Starter Template
# This starter templates adds gems to your gemfile when creating a new rails app
# Usage:
# rails new <app name> -m <this gist's url>/raw
gem_group :development, :test do
gem 'rspec-rails'
gem 'better_errors'
gem 'binding_of_caller'
gem 'quiet_assets'
gem 'annotate'
@alvinang
alvinang / towers-of-hanoi.rb
Created September 16, 2013 03:07
Towers of Hanoi is a popular programming question used in practice or interviews. This question is located in appacademy's mini-curriculum on "Arrays". See this link for the question. https://github.com/appacademy/prep-work/blob/master/mini-curriculum/data-structures/array.md To run this file, download gem 'pry' (gem install pry). Then, cd into …
class TowersOfHanoi
def self.start
@n = 0
puts "------------------------------------------------------------------------"
puts "Towers of HanooOoiiiii"
puts " "
puts "Your goal is to move all disk to peg 'c' in order. i.e. \"c\" => [3,2,1]"
puts " "
@alvinang
alvinang / letters-to-numbers.rb
Last active December 23, 2015 02:39
Phone Number's Letters to Number Conversion
# Found question from Best of Ruby Quiz - modified and created the following.
# Library to convert letters to phone numbers
@numbers_library = { "A" => 2, "B" => 2, "C" => 2, "D" => 3, "E" => 3, "F" => 3, "G" => 4,
"H" => 4, "I" => 4, "J" => 5, "K" => 5, "L" => 5, "M" => 6, "N" => 6,
"O" => 6, "P" => 7, "Q" => 7, "R" => 7, "S" => 7, "T" => 8, "U" => 8,
"V" => 8, "W" => 9, "X" => 9, "Y" => 9, "Z" => 9
}