Skip to content

Instantly share code, notes, and snippets.

View tpae's full-sized avatar

Terence Pae tpae

  • San Francisco, CA
  • X @tpae
View GitHub Profile
@tpae
tpae / jquery ie placeholder fix
Created November 5, 2012 02:39
jQuery IE Placeholder fix
$('input,textarea').each(function() {
// set this attr placeholder into val, if ie.
if ($.browser.msie) {
if ($(this).val() == '') {
$(this).val($(this).attr('placeholder'));
}
}
}).focus(function() {
if ($.browser.msie) {
if ($(this).val() == $(this).attr('placeholder')) {
/*
* Enhances 'require' from RequireJS with Promises API while preserving its original semantics.
*/
(function() {
if (!Promise || !require) {
return;
}
@tpae
tpae / Rakefile.rb
Last active November 10, 2016 05:29
Bumping version on a podspec when using CocoaPods
task default: %w[version]
version_sizes = ["major", "minor", "patch"]
task :version, [:version_size] do |t, args|
args.with_defaults(:version_size => "patch")
version_size = args.version_size
unless version_sizes.include?(version_size)
fail "invalid version size, please use: major, minor, or patch"
@tpae
tpae / LinkedListMerge.swift
Last active November 10, 2016 05:28
Merging two LinkedLists in Swift
import Foundation
class Node {
var val: Int
var next: Node?
init(val: Int) {
self.val = val
@tpae
tpae / Trie.swift
Last active May 9, 2021 20:59
Swift implementation of Trie Data Structure
import Foundation
class Node {
var val: String?
var parent: Node?
var children: [String: Node] = [:]
@tpae
tpae / BSTree.swift
Last active May 8, 2018 16:51
Swift implementation of Binary Search Tree
import Foundation
class Node {
var val: Int
var left: Node?
var right: Node?
@tpae
tpae / minHeap.js
Last active February 15, 2024 08:00
JavaScript implementation of Min Heap Data Structure
// Implement a min heap:
// -> insert, extract_min
// property:
// - elements are in ascending order
// - complete binary tree (node is smaller than it’s children)
// - root is the most minimum
// - insert takes O(logn) time
// - insert to the bottom right
@tpae
tpae / stack.js
Last active November 10, 2016 05:25
JavaScript implementation of Stack Data Structure
// Implement a stack using LinkedLists.
// Operations:
// -> push
// -> pop
// -> peek
function StackNode(val) {
this.val = val;
this.next = null;
@tpae
tpae / queue.js
Last active August 13, 2021 07:04
JavaScript implementation of Queue Data Structure
// Implement a Queue using LinkedLists
// we know that queue is LIFO
// operations: enqueue, dequeue
function QueueNode(val) {
this.val = val;
this.next = null;
}
function Queue() {
@tpae
tpae / graph.js
Last active February 14, 2024 23:29
JavaScript implementation of Graph Data Structure
// Implement a Graph
// basic operations:
// - add vertex (node)
// - add edge (node -> node)
function GraphNode(val) {
this.val = val;
this.edges = {};
}