Skip to content

Instantly share code, notes, and snippets.

View clarle's full-sized avatar

Clarence Leung clarle

  • Netflix
  • Los Gatos, CA
  • 12:22 (UTC -08:00)
  • X @clarler
View GitHub Profile
@clarle
clarle / keybase.md
Last active September 19, 2019 19:12

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 July 5, 2024 07:06
Image Denoising with OpenCV
Loading
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 March 2, 2018 00:49 — 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.
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 June 23, 2017 03:40
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()
hog.setSVMDetector(cv2.HOGDescriptor_getDefaultPeopleDetector())
@clarle
clarle / SignupViewModel.m
Created August 7, 2016 17:42
Sign up a user with a unique username in Firebase
- (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 June 29, 2016 13:17
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
clarle / hour_summary.R
Last active September 14, 2018 21:50
Summing hours in HH:MM:SS format in 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 June 7, 2016 16:20
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
clarle / app.js
Created October 24, 2015 16:06
Target API data fetching with Express and Request
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 August 8, 2015 04:54
Blood sugar random data generation
import random
import csv
DAYS = 7
HOURS = 24
data = []
for day in range(DAYS):
for hour in range(HOURS):