Skip to content

Instantly share code, notes, and snippets.

View kevinmichaelchen's full-sized avatar
🎯
Focusing

Kevin Chen kevinmichaelchen

🎯
Focusing
View GitHub Profile
@kevinmichaelchen
kevinmichaelchen / tabata.sh
Created May 16, 2014 01:50
Tabata Script
while true; do for i in `seq 1 30`; do echo $i; sleep 1; done; tput bel; tput bel; done
@kevinmichaelchen
kevinmichaelchen / rebase.py
Created August 15, 2014 19:08
Outputs a Git command to rebase linear feature branches
#! /usr/bin/env python
# input: branches.txt lists feature branches
# branches MUST be on their own line
# branches MUST be ordered NEWEST to OLDEST
# output: the git command to rebase linear branches onto 'develop'
import sys
BRANCH = 'develop'
@kevinmichaelchen
kevinmichaelchen / install_facebook_aar.py
Created September 1, 2014 17:12
Outputs command to install AAR of Facebook Android SDK
#! /usr/bin/env python
# python install_facebook_aar.py 3.17
# if you want to install version 3.17 of the Facebook Android SDK
if __name__ == "__main__":
import sys
if len(sys.argv) is not 2:
print "Example run command:"
print "python install_facebook_aar.py 3.17"
else:
version = sys.argv[1]
@kevinmichaelchen
kevinmichaelchen / remove_duplicates_from_array.rb
Created October 14, 2014 16:00
Remove duplicates from array in linear time
#!/usr/bin/ruby
# Remove duplicates from array in linear time
arr = [6,2,4,2,4,6]
puts "#{arr.size} elements in original array:"
puts arr.inspect
# keep track of what we see
seen = {}
@kevinmichaelchen
kevinmichaelchen / detect_balanced_parens.rb
Created October 15, 2014 15:14
Detect if a string has balanced parens
#!/usr/bin/ruby
def isBalanced(string)
stack = []
string.split("").each do |i|
if i == '('
stack.push i
elsif i == ')'
popped = stack.pop
return false if popped == nil
@kevinmichaelchen
kevinmichaelchen / detect_max_heap_property.rb
Last active August 29, 2015 14:07
Detect if the max heap property is violated in a binary tree
#!/usr/bin/ruby
# Detect if property of max heap is violated.
# Heap is a tree-based data structure.
# Here we use a binary tree.
# Must be monotonically decreasing from parent to child.
class Node
def initialize(value, left, right)
@value = value
@kevinmichaelchen
kevinmichaelchen / reshape.do
Created October 30, 2014 13:48
Reshape wide format to long format (Stata)
#delimit ;
cap log close;
cd "~/Dropbox/econ381_project";
log using "project.log", text replace;
insheet using "health_status.csv", comma;
reshape long
all_ne_evg_ all_ne_g_ all_ne_fp_
all_mw_evg_ all_mw_g_ all_mw_fp_
all_s_evg_ all_s_g_ all_s_fp_
@kevinmichaelchen
kevinmichaelchen / test.rb
Created December 5, 2014 02:25
Detecting balanced parens and braces
def balanced?(string)
braces = 0
parens = 0
string.split("").each do |i|
if i == "("
parens += 1
elsif i == ")"
parens -= 1
elsif i == "["
braces += 1
package com.niupiao.niupiao.utils;
import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
import org.joda.time.format.ISODateTimeFormat;
/**
* Created by kevinchen on 2/23/15.
*/
@kevinmichaelchen
kevinmichaelchen / BasicStack.java
Created April 2, 2015 18:49
Basic Stack Implementation (Java)
public class BasicStack {
private Object[] array = null;
private boolean debug = false;
public BasicStack() {
this(10);
}
public BasicStack(int capacity) {