Skip to content

Instantly share code, notes, and snippets.

View dboyliao's full-sized avatar

dboyliao dboyliao

View GitHub Profile
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import print_function
import os
import sys
import subprocess
import argparse
def main(work_dir, target_ext, from_encoding, to_encoding):
for current_dir, dirnames, fnames in os.walk(work_dir):
@dboyliao
dboyliao / gist:6a8f237dda95d7541ab96a616ddeb770
Created December 6, 2016 02:04 — forked from tmoertel/gist:5798134
How to transform the vanilla recursive fib function into the iterative DP version through a series of mechanical steps.
# Transforming the vanilla recursive fib into the iterative DP version
# through a series of mechanical steps.
#
# For more on converting recursive algorithms into iterative ones, see:
# http://blog.moertel.com/posts/2013-05-11-recursive-to-iterative.html
# original function
def fib(n):
@dboyliao
dboyliao / fib.py
Last active December 9, 2016 00:13
def fib(n):
if n < 2:
return 1
return fib(n-1) + fib(n-2)
def tail_fib(n, a=1, b=1):
if n < 2:
return b
@dboyliao
dboyliao / prime.py
Last active December 19, 2016 12:34
def isPrime(n):
"""
naive prime number checker
return True if `n` is a prime number, False otherwise
"""
if n < 2:
return False
for i in range(2, n-1):
@dboyliao
dboyliao / py3_futures_example.py
Created February 20, 2017 07:32
python3 futures module example
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Example of `futures` module in python3
"""
from __future__ import print_function
import sys
from time import time
# check version
-- http://learnyouahaskell.com/functionally-solving-problems
-- Reverse Polish notation calculator
import System.IO (hFlush, stdout)
import Text.Read (readMaybe)
main :: IO()
main = do
putStr "Enter an expression "
hFlush stdout
userInput <- getLine
@dboyliao
dboyliao / example_copy.py
Last active March 7, 2017 10:12
example of shallow copy and deep copy
from __future__ import print_function
from copy import copy, deepcopy
l = [[1, 2, 3], [3, 4, 5],[4, 5, 6]]
shallow_l = copy(l)
deep_l = deepcopy(l)
l[0].append(4)
print(shallow_l)
# >> [[1, 2, 3, 4], [3, 4, 5], [4, 5, 6]]
@dboyliao
dboyliao / hist_eqalize.py
Created March 10, 2017 17:09
Histogram Equalization with Python
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import division, print_function
import sys
import os
import cv2
import numpy as np
def hist_eq(img):
data = img.copy().flatten()
@dboyliao
dboyliao / dlib_ios.h
Last active October 27, 2017 05:34
Header for convert UIImage to dlib image (2d pixel array) and vise versa
//
// dlib_ios.h
// TryDlibVideoStream
//
// Created by DboyLiao on 13/03/2017.
//
#ifndef dlib_ios_h
#define dlib_ios_h
@dboyliao
dboyliao / dlib_ios.mm
Last active April 5, 2020 11:37
Implementation of converting UIImage to dlib image (2d pixel array) and vise versa
//
// dlib_ios.m
// TryDlibVideoStream
//
// Created by DboyLiao on 13/03/2017.
//
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#include "dlib_ios.h"