Skip to content

Instantly share code, notes, and snippets.

View xinbinhuang's full-sized avatar
🍣
Sushi fan

Xinbin Huang xinbinhuang

🍣
Sushi fan
View GitHub Profile
@xinbinhuang
xinbinhuang / gist:b64304922a33b36995e7869a8789c459
Last active January 12, 2022 08:01
adguard-home-whitelist.txt
!
! Title: Personal AdGuard DNS whitelist
! Description: personal adguard home whitelist
! Author: xinbinhuang
!
||https://ad.doubleclick.net^
||ad.doubleclick.net^$google.com
@@||ad.doubleclick.net^$google.com
@xinbinhuang
xinbinhuang / wsl-cleanup.ps1
Last active July 3, 2020 17:41
Compact disk space used by WSL2
# https://github.com/microsoft/WSL/issues/4699
wsl.exe --shutdown
# Compact wsl2 vhd to save space
# You may need change the path to fit your actual WSL folder name
cd $env:LOCALAPPDATA\Packages\CanonicalGroupLimited.Ubuntu18.04onWindows_79rhkp1fndgsc\LocalState\
optimize-vhd -Path .\ext4.vhdx -Mode full
@xinbinhuang
xinbinhuang / example_rewrite_subdag.py
Created June 12, 2020 01:47
An exmpale DAG testing the new SubDagOperator
from airflow import DAG
from airflow.operators.dummy_operator import DummyOperator
from airflow.operators.subdag_operator import SubDagOperator
from airflow.utils.dates import days_ago
def dummy_dag(dag_name, args):
dag_subdag = DAG(
dag_id=dag_name,
default_args=args,
@xinbinhuang
xinbinhuang / emoji.md
Last active May 29, 2020 01:25 — forked from rxaviers/gist:7360908
Complete list of github markdown emoji markup
@xinbinhuang
xinbinhuang / Raymond Hettinger - Beyond PEP 8 -- Best practices for beautiful intelligible code - PyCon 2015.md Raymond Hettinger - Beyond PEP 8 -- Best practices for beautiful intelligible code - PyCon 2015. Distillation of knowledge gained from a decade of Python consulting, Python training, code reviews, and serving as a core developer. (https://www.youtube.com/watch?v=wf-BqAjZb8M)

Raymond Hettinger's professional at doing code review and architecture review

P vs. NP. Pythonic vs. Non-Pythonic.

How to make use of PEP 8

  1. Golden rule of PEP-8: PEP-8 onto yourself. PEP 8 is style guide, not a law book.
  2. Care about intelligibility, not simply visually better
  3. Transforming (Java) API to pythonic ones

Why not PEP 8

@xinbinhuang
xinbinhuang / class_instances_attr.py
Last active July 3, 2020 17:39
How to get a dict of attributes from a (data)class
from dataclasses import dataclass, field, asdict
import random
from faker import Faker
faker = Faker()
@dataclass
class Purchase:
@xinbinhuang
xinbinhuang / dev_ops.sh
Last active March 8, 2020 03:38
Some simple Linux/Docker/DevOps Commands
######################################################
######## Linux Admin
######################################################
# Disk Space Usage
df -h
# Disk Usage
# https://stackoverflow.com/questions/1019116/using-ls-to-list-directories-and-their-total-sizes
du --summarize --human-readable * # or du -sh *
@xinbinhuang
xinbinhuang / gist:a456df10268319ea2b034d07c53dfd71
Created January 22, 2020 19:07 — forked from chiragchamoli/gist:3754597
Example of 1NF, 2NF and 3NF in plain english?

1NF is the most basic of normal forms - each cell in a table must contain only one piece of information, and there can be no duplicate rows.

2NF and 3NF are all about being dependent on the primary key. Recall that a primary key can be made up of multiple columns. As Chris said in his response:

The data depends on the key [1NF], the whole key [2NF] and nothing but the key [3NF] (so help me [Codd][1]).

2NF

Say you have a table containing courses that are taken in a certain semester, and you have the following data:

@xinbinhuang
xinbinhuang / clean_local_branch.sh
Last active November 1, 2019 20:37
Git housekeeping: clean up local branches. Details: https://erikaybar.name/git-deleting-old-local-branches
#!/usr/bin/env bash
git remote prune origin
git branch -vv | grep 'origin/.*: gone]' | awk '{print $1}' | xargs git branch -d
@xinbinhuang
xinbinhuang / sed_examples.sh
Last active January 24, 2020 00:48
sed examples to insert, append, and substitute text in your files
sed -i \ # -i: inplace; you can remove -i to do a dry run
-e '/<pattern>/i <text>' \ # /i: insert text after the pattern
-e '/<pattern>/a <text>' \ # /a: append text before the pattern
-e 's/<pattern>/<text>/g' \ # s/: substitute ; /g: global; match ALL instances instead of just the 1st match
-e 's/(<pat1>)<random_text>(<pat2>)/\1 + \2' # \1 reference <pat1>; \2 reference <pat2>
input.file
# to loop through a directory
find <directory> -type f -exec sed -i -e 's/<pattern>/<text>/g' {} \;