Skip to content

Instantly share code, notes, and snippets.

Clarence Leung clarle

Block or report user

Report or block clarle

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View keybase.md

Keybase proof

I hereby claim:

  • I am clarle on github.
  • I am clarle (https://keybase.io/clarle) on keybase.
  • I have a public key ASAh6aiLWK3_56wuoAALnjzZykl57rHw4osXrK4yYTmG4wo

To claim this, I am signing this object:

@clarle
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
clarle / align_images_masked.py
Created Mar 2, 2018 — forked from anonymous/align_images_masked.py
Patched alignment and merging scripts including the option for masking via the detected face points, seamless clone and erosion and blurring of the masks.
View align_images_masked.py
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
clarle / pedestrian.py
Created Jun 23, 2017
Pedestrian Detection
View pedestrian.py
%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()
hog.setSVMDetector(cv2.HOGDescriptor_getDefaultPeopleDetector())
@clarle
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]
createUserWithEmail:email
password:password
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
clarle / simulate.py
Created Jun 29, 2016
Generate simulated phylogenetic data using DendroPy
View simulate.py
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
clarle / hour_summary.R
Last active Sep 14, 2018
Summing hours in HH:MM:SS format in R
View hour_summary.R
library(dplyr)
library(tidyr)
library(lubridate)
# 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
clarle / closest_mersenne.py
Last active Jun 7, 2016
Closest Mersenne function - optimized for readability, not performance
View closest_mersenne.py
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
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
clarle / generate.py
Created Aug 8, 2015
Blood sugar random data generation
View generate.py
import random
import csv
DAYS = 7
HOURS = 24
data = []
for day in range(DAYS):
for hour in range(HOURS):
You can’t perform that action at this time.