Skip to content

Instantly share code, notes, and snippets.

View trhura's full-sized avatar

Thura Hlaing trhura

View GitHub Profile
#! /usr/bin/env python3
# How to run this program: python3 twittersort.py tweet1.py tweet2.py
# Implementation for CS150 project 2 (http://troll.cs.ua.edu/cs150/projects/index.html)
__author__ = "Thura Hlaing <[email protected]>"
import sys
from collections import namedtuple
from scanner import Scanner
from pprint import pprint
@trhura
trhura / startup-crawler.py
Created November 8, 2013 05:42
script to parse startup infos from https://angel.co and save it into a csv file.
# Author: Thura Hlaing <[email protected]>
# Time-stamp: <2013-11-08 12:11:30 (trhura)>
# script to parse startup infos from https://api.angel.co/1/startups?filter=raising and
# save it into a csv file.
__author__ = "Thura Hlaing <[email protected]>"
import csv
import requests
@trhura
trhura / combinations.clj
Created December 26, 2013 09:06
Combinations generator in Clojure
(defn combinations [lst k]
(letfn [(combinator [x xs]
(if (= (count x) k)
[x]
(when (not (empty? xs))
(concat (combinator (concat x [(first xs)]) (rest xs))
(combinator x (rest xs))))))]
(combinator nil lst)))
;; user> (combinations (range 1 6) 2)
(defn palindrome? [string]
"Check whether a given string is a palindrome."
(loop [string string
start 0
end (dec (count string))]
(cond
;;compare string's start and string's end
(not (= (get string start) (get string end))) false
;; return true after checking middle char
(<= end start) true
public class Main {
private static boolean isPalindrome (String string) {
String reversedString = new StringBuilder(string).reverse().toString();
for (int i =0; i < string.length() / 2; i++) {
if (string.charAt(i) != reversedString.charAt(i))
return false;
}
@trhura
trhura / ooredoo-topupcard-reader.py
Created October 4, 2014 21:11
Python script which scan ooredoo topup cards and extract the topup code using opencv+tesseract
#! /usr/bin/env python2
import cv2
import numpy as np
from collections import deque
orig_image = None
gray_image = None
threshold_image = None
edge_image = None
@trhura
trhura / cvpicker.py
Created October 12, 2014 03:40
opencv color picker
#! /usr/bin/env python2
import cv2
import numpy as np
colors = []
def on_mouse_click (event, x, y, flags, frame):
if event == cv2.EVENT_LBUTTONUP:
colors.append(frame[y,x].tolist())
-- Assuming a and b are not negative
multiply a 0 = 0
multiply a 1 = a
multiply a b = a + multiply a (b-1)
-- Assuming e is not negative
power b 0 = 1
power b 1 = b
power b e = multiply b $ power b (e-1) -- aka multiply b (power b e-1)
def multiply(a, b):
# Assuming a and b are not negative
if b == 0: return 0
if b == 1: return a
return a + multiply(a, b-1)
def power(b, e):
# Assuming e is not negative
if e == 0: return 1
if e == 1: return b
-module (calculator).
-export ([exponential/2, multiply/2]).
multiply(_, 0) -> 1;
multiply(Num, 1) -> Num;
multiply(Num, Exp) -> Num + multiply(Num, Exp-1).
exponential(_, 0) -> 1;
exponential(Base, 1) -> Base;
exponential(_, Exp) when(Exp < 0) -> throw("Bad argument");