Skip to content

Instantly share code, notes, and snippets.

View vietvudanh's full-sized avatar

Viet Vu vietvudanh

  • Ha Noi, Vietnam
View GitHub Profile
# 1. python file
sudo mkdir -p /opt/cred
cat <<ETO > /opt/cred/creds.py
import argparse
import sys
import yaml
parser = argparse.ArgumentParser(description='find creds or execute credential')
parser.add_argument('--mode', help='mode to run')
parser.add_argument('--name', help='name to find')
@vietvudanh
vietvudanh / sqla_nodes.py
Last active November 30, 2020 04:19
sqla nodes
"""
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 / snippets.md
Last active April 21, 2024 01:51
My common snippets

Bash

shebang

#!/usr/bin/env bash
CWD="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

date loop

@vietvudanh
vietvudanh / zip.sh
Last active August 14, 2020 02:09
Zip & Unzip
# .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 July 28, 2020 05:35
Virtualbox manage
# list
vboxmanage list vms
vboxmanage list runningvms
# start
VM=cent7_1
vboxmanage startvm $VM --type headless
# stop
vboxmanage controlvm Ubuntu poweroff soft
@vietvudanh
vietvudanh / convert_csv_hdf5.py
Created July 22, 2020 03:26
Convert csv to hdf5
# -*- 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)
@vietvudanh
vietvudanh / rsync
Created March 25, 2020 16:31
rsync
#!/usr/bin/env bash
CWD="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
rsync -arv \
--exclude-from=$CWD/exclude.txt \
$CWD \
vpn:~/
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 January 14, 2020 02:08 — forked from akashpalrecha/an-inquiry-into-matplotlib-figures.ipynb
An Inquiry into Matplotlib's Figures, Axes, subplots and the very amazing GridSpec!
Loading
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 December 3, 2019 13:30
GO file operations
// 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()