Skip to content

Instantly share code, notes, and snippets.

View suminb's full-sized avatar

Sumin Byeon suminb

View GitHub Profile
@suminb
suminb / lunch.py
Created October 3, 2011 18:19
A near-trivial Python script to decide to where to go for a lunch...
from random import choice
candidates = ('Chipotle', 'Panda Express', 'Burger King', 'Gentle Ben\'s', 'Miss Saigon')
print choice(candidates)
@suminb
suminb / freq.py
Created October 6, 2011 13:55
Counting word frequency
import codecs
import re
f = codecs.open('freq.txt', 'r', 'utf-8')
data = f.read()
f.close()
freq = {}
for word in re.findall(r'\w+', data, re.UNICODE):
if not word in freq:
@suminb
suminb / gist:1267455
Created October 6, 2011 13:57
Pseudoinverse of a matrix
from numpy import inv, transpose
def pseudoinverse(U):
return inv(transpose(U) * U) * transpose(U)
@suminb
suminb / hello_c++0x.cpp
Created October 23, 2011 00:29
My First C++0x (C++11) Program
#include <iostream>
#include <list>
using namespace std;
template <class T>
list<T> filter(bool (*f)(T x), list<T>* l) {
list<T> result;
typename list<T>::iterator it = l->begin();
while(it != l->end()) {
@suminb
suminb / hello_c++0x.cpp
Created October 23, 2011 00:54 — forked from dahlia/hello_c++0x.cpp
My First C++0x (C++11) Program
#include <iostream>
#include <iterator>
#include <list>
using namespace std;
list<int> map(int (*f)(int x), list<int>* l) {
list<int> result;
list<int>::iterator it = l->begin();
@suminb
suminb / exercise1.rb
Created August 28, 2012 07:53
Ruby Programming Exercise
unsorted_list = [5, 8, 1, 2, 4, 9, 7, 6, 3]
sorted_list1 = [2, 3, 5, 7, 11, 13, 17, 19]
sorted_list2 = [2, 4, 8, 10, 12, 14, 16, 18]
def min(list)
# Google for 'ruby ternary operator'
return list.reduce { |x, y| x < y ? x : y }
end
def max(list)
@suminb
suminb / Exercise1.java
Created August 28, 2012 19:54
Basic Java programming exercise
import java.util.Arrays;
import java.util.List;
/**
* This is a basic Java programming exercise. Fill out all unimplemented class
* methods.
*
* @author Sumin Byeon <[email protected]>
*
*/
#!/usr/bin/env python
import re
import sys
content = sys.stdin.read()
for p in re.findall(r"(\d+.\d+.\d+.\d+)\s+(\d+)", content):
print "http://%s:%s" % p
@suminb
suminb / SampleActivity.java
Created September 18, 2012 00:02
Playing notification sound in Android
@Override
protected void onResume() {
super.onResume();
Uri alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
MediaPlayer mp = MediaPlayer.create(this, alert);
mp.start();
}
@suminb
suminb / example.py
Created October 24, 2012 09:18
Binomial Likelihood Function
#
# Example from: http://warnercnr.colostate.edu/~gwhite/fw663/BinomialLikelihood.PDF
#
from math import factorial
# Number of flips
n = 11
# Number of heads