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 / Test.java
Created August 25, 2015 21:46
Pattern Matching in Java
class Test {
public static void main(String[] args) {
Pattern pattern = Pattern.compile( "filename\\*\\d+" );
System.out.println( pattern.matcher( "filename1" ).find() ); // false
System.out.println( pattern.matcher( "filename*1" ).find() ); // true
System.out.println( pattern.matcher( "filename*12" ).find() ); // true
System.out.println( pattern.matcher( "filename**12" ).find() ); // false
System.out.println( pattern.matcher( "filenamme*12" ).find() ); // false
System.out.println( pattern.matcher( " filename**12 =" ).find() ); // false
System.out.println( pattern.matcher( " filename**12=" ).find() ); // false
@kevinmichaelchen
kevinmichaelchen / Test.java
Created August 25, 2015 22:07
Decoding split-up email attachment filenames
class Test {
public static void main( String[] args )
{
final String contentDisposition = "name: Content-Disposition\n" +
"value: attachment;\n" +
"\tsize=1123785;\n" +
"\tmodification-date=\"Thu, 20 Aug 2015 17:27:44 GMT\";\n" +
"\tfilename*0=\"=?utf-8?B?TmltciAoNCDDlyA0KSBhbmQgKDYgw5cgNikgaGlnaCBtb2JpbGl0eS\";\n" +
"\tfilename*1=\"B2ZWhp?= cles.pdf\";\n" +
"\tcreation-date=\"Thu, 20 Aug 2015 17:27:44 GMT\"";
@kevinmichaelchen
kevinmichaelchen / headers.txt
Last active August 28, 2015 19:30
iCloud, Gmail, and Yahoo - Mail Filename Encodings
# A list of mail headers to test against
# Outlook
Content-disposition: attachment;
filename=";;;.txt"
# Outlook
Content-disposition: attachment;
filename*=UTF-8''%3B%E6%BC%A2%D8%B1%D9%82%D9%84%20%3B%3BDonaldTrump%E6%BC%A2%D8%B1%D9%82%D9%84%20%E6%BC%A2%D8%B1%D9%82%D9%84%20%E6%BC%A2%D8%B1%D9%82%D9%84%20%E6%BC%A2%D8%B1%D9%82%D9%84%20%E6%BC%A2%D8%B1%D9%82%D9%84%20%E6%BC%A2%D8%B1%D9%82%D9%84%20longTheDonald.txt
@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_