Skip to content

Instantly share code, notes, and snippets.

View joshteng's full-sized avatar

Joshua Teng joshteng

View GitHub Profile
@joshteng
joshteng / Deploying_rails_app.markdown
Last active August 29, 2015 13:57
Manual Server Set Up + Deploy With Capistrano (not working yet)

#Setting Up a Ubuntu Machine

####Step 1 Install all dependencies using Laptop by Thoughtbot

bash <(wget -qO- https://raw.githubusercontent.com/thoughtbot/laptop/master/linux) 2>&1 | tee ~/laptop.log

####Step 2 Restart computer

// While you can edit this file, it's best to put your changes in
// "User/Preferences.sublime-settings", which overrides the settings in here.
//
// Settings may also be placed in file type specific options files, for
// example, in Packages/Python/Python.sublime-settings for python files.
{
// Sets the colors used within the text area
"color_scheme": "Packages/Color Scheme - Default/Monokai.tmTheme",
// Note that the font_face and font_size are overriden in the platform
@joshteng
joshteng / README.txt
Created July 13, 2013 04:50 — forked from i-scorpion/README.txt
Makes your twitter bootstrap tables' header 'sticky'
Here is a simple jQuery plugin to make a table header fixed on top when window is scrolled.
Using the code from twitter bootstrap documentation page, this code is customized for table header.
Create the table with following layout -
<table class="table-fixed-header">
<thead class="header">
<tr>
<th>Column 1</th>
<th>Column 2</th>
<th>Column 3</th>
@joshteng
joshteng / .zshrc
Last active December 20, 2015 18:59
# Path to your oh-my-zsh configuration.
ZSH=$HOME/.oh-my-zsh
# Set name of the theme to load.
# Look in ~/.oh-my-zsh/themes/
# Optionally, if you set this to "random", it'll load a random theme each
# time that oh-my-zsh is loaded.
ZSH_THEME="robbyrussell"
# Example aliases
@joshteng
joshteng / rails_3_vs_4_mass_assignment_protection.rb
Created August 16, 2013 04:26
Rails 4 way of protecting from mass assignment
###############
#In Rails 3, we protect attributes that should not be mass assignable by users of the website this way:
###############
#in the model file:
class Post < ActiveRecord::Base
attr_accessible :title, :content
end
#and your controller might look something like that
# Shoulda activemodel cheatsheet
# DB
should have_db_column(:title).of_type(:string).with_options(default: 'Untitled', null: false)
should have_db_index(:email).unique(:true)
# Associations
should belong_to :company
should have_one(:profile).dependent(:destroy)
should have_many(:posts).dependent(:nullify)
@joshteng
joshteng / is_anagram.rb
Created September 11, 2013 17:57
SUTD SEPT 2013
# The method should be symmetric, i.e.,
# is_anagram?(word1, word2) == is_anagram?(word2, word1) for any two words
is_anagram?('cinema', 'iceman') # => true
is_anagram?('iceman', 'cinema') # => true
# Pedantically, a word is always an anagram of itself.
# This is called being "reflexive," i.e., is_anagram?(word, word) == true for any word
is_anagram?('pants', 'pants') # => true
# is_anagram? should be case-insensitive
@joshteng
joshteng / anagrams_for.rb
Created September 11, 2013 18:07
Ruby Basics 2
# The dictionary is just an arbitrary collection of strings.
# It need not contain English words, e.g., 'etlsm'.
dictionary = ['acres', 'cares', 'Cesar', 'races', 'smelt', 'melts', 'etlsm']
# If the input word happens to be in the dictionary, it should be in the the returned array, too.
# The list should also be case-insensitive.
anagrams_for('acres', dictionary) # => ['acres', 'cares', 'Cesar', 'races']
anagrams_for('ACRES', dictionary) # => ['acres', 'cares', 'Cesar', 'races']
anagrams_for('Cesar', dictionary) # => ['acres', 'cares', 'Cesar', 'races']
#Table Delegate
def tableView(tableView, didSelectRowAtIndexPath: indexPath)
tableView.deselectRowAtIndexPath(indexPath, animated: true)
# @alert = UIAlertView.alloc.initWithTitle("test", message:"test", delegate:nil, cancelButtonTitle:"Cancel", otherButtonTitles:"Yes").show
@alert = UIAlertView.alloc.initWithTitle("Confirm Support Request", message:"A customer service representative will give you a call", delegate: self, cancelButtonTitle: "cancel", otherButtonTitles: "Yes")
@alert.show
end