Skip to content

Instantly share code, notes, and snippets.


Clarence Leung clarle

View GitHub Profile

Keybase proof

I hereby claim:

  • I am clarle on github.
  • I am clarle ( on keybase.
  • I have a public key ASAh6aiLWK3_56wuoAALnjzZykl57rHw4osXrK4yYTmG4wo

To claim this, I am signing this object:

clarle / denoising.ipynb
Last active Aug 18, 2018
Image Denoising with OpenCV
View denoising.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
clarle /
Created Mar 2, 2018 — forked from anonymous/
Patched alignment and merging scripts including the option for masking via the detected face points, seamless clone and erosion and blurring of the masks.
import argparse
import cv2
import dlib
import json
import numpy
import skimage
from pathlib import Path
from tqdm import tqdm
from umeyama import umeyama
clarle /
Created Jun 23, 2017
Pedestrian Detection
%matplotlib inline
import numpy as np
import cv2
import imutils
from matplotlib import pyplot as plt
from imutils.object_detection import non_max_suppression
hog = cv2.HOGDescriptor()
clarle / SignupViewModel.m
Created Aug 7, 2016
Sign up a user with a unique username in Firebase
View SignupViewModel.m
- (void)signUpUser:(NSString *)username password:(NSString *)password email:(NSString *)email completion:(void (^)(FIRUser *user, NSError *error))completion {
[[FIRAuth auth]
completion:^(FIRUser *user, NSError *error) {
FIRDatabaseReference *ref = [[FIRDatabase database] reference];
FIRDatabaseReference *userRef = [[ref child:@"users"] child:username];
[userRef observeSingleEventOfType:FIRDataEventTypeValue withBlock:^(FIRDataSnapshot *snapshot) {
if (snapshot && snapshot.value[@"uid"] == nil) {
[userRef setValue:user.uid forKey:@"uid"];
clarle /
Created Jun 29, 2016
Generate simulated phylogenetic data using DendroPy
import dendropy
from dendropy.simulate import treesim
from dendropy.model.discrete import Hky85, simulate_discrete_char_dataset
# Generate a simulated tree
taxa = dendropy.TaxonNamespace(['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'])
tree_model = treesim.birth_death_tree(birth_rate=1.0, death_rate=0.5, taxon_namespace=taxa)
# Use the HKY85 model for character mutation
seq_model = Hky85()
clarle / hour_summary.R
Last active Sep 14, 2018
Summing hours in HH:MM:SS format in R
View hour_summary.R
# Parse data from HH:MM:SS format into something that can be used by `lubridate`
hours %>%
separate(Duration, into = c("hours", "minutes", "seconds"), sep = ":", convert = TRUE) %>%
summarize(total_time = duration(hour = sum(hours), minute = sum(minutes), second = sum(seconds)))
clarle /
Last active Jun 7, 2016
Closest Mersenne function - optimized for readability, not performance
from math import log
def round_base_2(n):
return 2**round(log(n)/log(2))
def closest_mersenne(n):
rb2 = round_base_2(n)
# We got the closest power of 2, so you can just drop the first digit and replace all others with 1
result = bin(rb2)[3:].replace('0', '1')
return int(result, 2)
clarle / app.js
Created Oct 24, 2015
Target API data fetching with Express and Request
View app.js
var _ = require('lodash'),
express = require('express'),
request = require('request'),
app = express();
var API_KEY = '1Kfdqvy6wHmvJ4LDyAVOl7saCBoKHcSb';
app.get('/products/:id', function(req, res) {
var ourData = {
age_group: '0-1 years old',
clarle /
Created Aug 8, 2015
Blood sugar random data generation
import random
import csv
DAYS = 7
HOURS = 24
data = []
for day in range(DAYS):
for hour in range(HOURS):