Skip to content

Instantly share code, notes, and snippets.

Avatar

Viet Vu vietvudanh

View GitHub Profile
@vietvudanh
vietvudanh / worker-pool.go
Last active Dec 22, 2020 — forked from harlow/worker-pool.go
Worker pool to control concurrency and collect results
View worker-pool.go
package main
import (
"fmt"
"sync"
"time"
)
const concurrency = 3
const numTasks = 100
View sqla_nodes.py
"""
simple example showing sqlalchemy Adjacency List Relationships
https://docs.sqlalchemy.org/en/13/orm/self_referential.html
"""
from sqlalchemy import create_engine, Column, ForeignKey, Integer, String
from sqlalchemy.orm import sessionmaker, relationship, backref
from sqlalchemy.ext.declarative import declarative_base
DB_PATH = 'sqlite:///nodes.sql'
@vietvudanh
vietvudanh / git.sh
Last active Feb 18, 2021
My common snippets
View git.sh
git config --global alias.logline "log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
git logline
@vietvudanh
vietvudanh / zip.sh
Last active Aug 14, 2020
Zip & Unzip
View zip.sh
# .zip
zip -r -o out.zip folder
unzip out.zip
# xz
gzip -r folder
gzip -f file
gunzip out.gz
# tar.gz
@vietvudanh
vietvudanh / vbox.sh
Last active Jul 28, 2020
Virtualbox manage
View vbox.sh
# list
vboxmanage list vms
vboxmanage list runningvms
# start
VM=cent7_1
vboxmanage startvm $VM --type headless
# stop
vboxmanage controlvm Ubuntu poweroff soft
View convert_csv_hdf5.py
# -*- coding: utf-8 -*-
import h5py
import sys
import pandas as pd
import datetime
if len(sys.argv) == 1:
print("No provided file")
sys.exit(1)
View rsync
#!/usr/bin/env bash
CWD="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
rsync -arv \
--exclude-from=$CWD/exclude.txt \
$CWD \
vpn:~/
View spark_job.py
from pyspark.sql import SparkSession
# config
INPUT = ""
OUTPUT = ""
def main():
spark = ( SparkSession.builder
.appName("Viet PySpark")
.config("spark.dynamicAllocation.enabled","true")
@vietvudanh
vietvudanh / an-inquiry-into-matplotlib-figures.ipynb
Created Jan 14, 2020 — forked from akashpalrecha/an-inquiry-into-matplotlib-figures.ipynb
An Inquiry into Matplotlib's Figures, Axes, subplots and the very amazing GridSpec!
View an-inquiry-into-matplotlib-figures.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@vietvudanh
vietvudanh / file.go
Last active Dec 3, 2019
GO file operations
View file.go
// read file by line
file, err := os.Open("file.txt")
if err != nil {
log.Fatal(err)
}
defer file.Close()
scan := bufio.NewScanner(file)
for scan.Scan() {
line := scan.Text()