Skip to content

Instantly share code, notes, and snippets.

View datlife's full-sized avatar

Dat Nguyen datlife

View GitHub Profile
@datlife
datlife / README.md
Last active January 10, 2024 20:40
Setup `dnsmasq` on Mac M1

Install dnsmasq

brew install dnsmasq

Configure dnsmasq.conf

I will run my dnsmasq nameserver locally under 127.0.0.1:53 and will resolve a wildcard domain *.ml-dev.test to an local IP. Look for the line listen-address and address

@datlife
datlife / mortgage.py
Created May 20, 2021 22:52
Mortgage Calculator
"""
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 / README.md
Last active September 30, 2020 23:54
Pub Sub pattern using pure `socket` programming on Python. No extra dependencies :) 🍻

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 / README.md
Last active February 4, 2020 22:58
UNIX Tricks

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
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

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
@datlife
datlife / fscale.sh
Last active May 1, 2020 06:59
Fractional Scaling for Ubuntu 18.04
#!/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 / async.jsx
Last active May 19, 2019 01:45
Event Loop
// 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 March 25, 2024 17:10
Build LLVM / Clang on MacOS

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 May 25, 2022 14:55
Setup Apache Spark/ Jupyter Notebook on MacOS