Skip to content

Instantly share code, notes, and snippets.

Avatar

Dat Nguyen datlife

View GitHub Profile
@datlife
datlife / notes.md
Last active May 25, 2022 14:55
Setup Apache Spark/ Jupyter Notebook on MacOS
View notes.md
@datlife
datlife / README.md
Last active December 19, 2021 06:49
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 / mortgage.py
Created May 20, 2021 22:52
Mortgage Calculator
View mortgage.py
"""
Mortgage Calculator for fun
https://en.wikipedia.org/wiki/Mortgage_calculator
What I want to know:
---- What's interest that I have to pay at payment N ?
---- What's principal that I have to pay at payment N ?
@datlife
datlife / mnist_tfdata.py
Last active January 25, 2021 09:13
Training Keras model with tf.data
View mnist_tfdata.py
"""An example of how to use tf.Dataset in Keras Model"""
import tensorflow as tf # only work from tensorflow==1.9.0-rc1 and after
_EPOCHS = 5
_NUM_CLASSES = 10
_BATCH_SIZE = 128
def training_pipeline():
# #############
# Load Dataset
@datlife
datlife / export_tfserving.py
Created February 2, 2018 18:52
Export pre-trained TF Object Detection API model to Tensorflow Serving
View export_tfserving.py
"""
Thiss script would convert a pre-trained TF model to a servable version for TF Serving.
A pre-trained model can be downloaded here
https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/detection_model_zoo
Requirements:
* A directory contains pretrained model (can be download above).
* Edit three arguments `frozen_graph`, `model_name`, `base_dir` accordingly
@datlife
datlife / README.md
Last active September 30, 2020 23:54
Pub Sub pattern using pure `socket` programming on Python. No extra dependencies :) 🍻
View README.md

Problem statement

I have a fast producer (client) and slow subscriber (server) due to slow Internet connection. How to decouple the connection such that server won't affect client performance?

  • The server will not send any data back to client once the TCP connection is established. In my case, it is a data sink.

Solution

In order to avoid drag down client IO, e.g. waiting for ACK from server, there are a few solutions:

@datlife
datlife / fscale.sh
Last active May 1, 2020 06:59
Fractional Scaling for Ubuntu 18.04
View fscale.sh
#!/bin/bash
# Enable fractional scaling on Ubuntu 18.04
#
# Problem:
# --------
# - Ubuntu 18.04 runs on Gnome 3.28, whichs does not support fractional scaling (120%, 130%).
# - As a result, the text and icon on my 4K 27" monitor are very small.
#
# Usage:
# -------
@datlife
datlife / README.md
Last active February 4, 2020 22:58
UNIX Tricks
View README.md

Format /etc/passwd file

tail -n +11 /etc/passwd| sort -t$':' -k3 -n | awk -F":" \
'
 BEGIN {
    printf "GID | Name        | User_dir          | Bash_Access        | Description      \n"
    printf "--- | ----------- | ----------------- | ------------------ | -----------------\n"
 }
 {
 printf "%s | %s | %s | %s | %s\n",$3, $1, $6, $7, $5 
@datlife
datlife / dga.dat
Created February 1, 2020 22:43
Extract all DGA data to a file
View dga.dat
bqkrtxgkmriwsiwcngtivpx.info
jdtmfupdyueqeldvhsjzdvzob.net
guhmpoxzivhba.com
nqqxqhuacaqhzurde.org
lgqsqgpqzijwid.info
ykolyecdcyk.biz
ztvflnxqzpxvpfobv.biz
zqrmkpivrbxccawozqwqpfzh.org
iqyqwhntrxfeq.org
ftadkbomxlnsib.info
@datlife
datlife / README.md
Created October 7, 2019 05:46
Spark on K8s using helm
View README.md

Status: alpha

alias k=kubectl

# Add microsoft charts to heml
helm repo add msftcharts http://microsoft.github.io/charts/repo
helm repo update

# Launch spark cluster with custom config