Skip to content

Instantly share code, notes, and snippets.

Dat Nguyen datlife

Block or report user

Report or block datlife

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
@datlife
datlife / async.jsx
Last active May 19, 2019
Event Loop
View async.jsx
// Async should be first priority over callbacks and promises
//
// High level idea:
// - Avoid .then .catch in promise
// - Syntatic sugar to make async programming similar to sequential code
const axios = require('axios');
DEFAULT_URL = "https://jsonplaceholder.typicode.com"
async function getUser(id) {
let resp = await axios.get(`${DEFAULT_URL}/users/${id}`)
@datlife
datlife / README.md
Last active May 17, 2019
Build LLVM / Clang on MacOS
View README.md

Build LLVM / Clang on MacOS

Problem

Built-in Clang / LLVM shipped by Xcode does not support Leak Santizer (-fsantize=leak) feature. For example, this code has memory leak:

// File: main.c

#include <stdlib.h>
@datlife
datlife / notes.md
Last active Mar 5, 2019
Setup Apache Spark/ Jupyter Notebook on MacOS
View notes.md
@datlife
datlife / trie.h
Created Dec 3, 2018
Trie Implementation in Modern C++ (Kind of, I am learning)
View trie.h
/**
* MIT License
*
* Copyright (c) 2018 Dat Nguyen
* Trie (aka Prefix Tree) is a type of Tree Data Structure. A node contains a
* list of child Nodes.
*
* Applications:
* ============
* * Word completion: quickly validate if a word is correctly type.
@datlife
datlife / launch.json
Last active Nov 9, 2018
C/C++ Workspace settings for VSCode on MacOS (lldb for Debugger)
View launch.json
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(lldb) Debug binary_tree",
"type": "cppdbg",
View move_forward.py
"""Move Forward
Start from the first element in the array (A), index is i. Move forward by A[i] steps max.
The algorithm is to return true/false, to indicate whether we can move from the first element
to the last element in the array
A = [2, 0, 1, 2, 0, 3] --> True
# Assumption:
-------------
* A[i] > 0 and there are [1 ... N] possible steps A[i] can move if A[i] = N.
@datlife
datlife / compute_mean_std_per_channel.py
Last active Jul 9, 2018
Compute mean and standard deviation (std) per channel give a list of images
View compute_mean_std_per_channel.py
"""Give a list of image filenames, this script compute the mean and std over all the images.
Requires:
* OpenCV
* tqdm
In this example, I use `Stanford Dogs Datasets" (~20k images)
Example Outputs: (8 cores CPU i7 4970K)
(env) dat@desktop:****/StanfordDogs$ python compute_mean_std.py
@datlife
datlife / test_bench.py
Last active Mar 14, 2018
Comparisons: How to efficiently iterate in pandas data frames by row.
View test_bench.py
"""
Problem:
--------
We would like to explore which method perform row iteration in the most efficient way.
Create a data frammes with 3 columns and 100,000 rows
Results:
--------
vector: Iterated over 100000 rows in 0.029180 | Sample at idx [0]: (1, 100000)
zip: Iterated over 100000 rows in 0.073447 | Sample at idx [0]: [1, 100000]
@datlife
datlife / gist:4819a1774de689916dcaa8fca2c42c86
Created Feb 20, 2018
Convert list of images into a MP4 H264
View gist:4819a1774de689916dcaa8fca2c42c86
ffmpeg -framerate 25 -i img%05d.jpg -c:v libx264 -profile:v high -crf 20 -pix_fmt yuv420p output.mp4
You can’t perform that action at this time.