Skip to content

Instantly share code, notes, and snippets.

View binh-bk's full-sized avatar
🤔
One step at a time

Binh Ng. binh-bk

🤔
One step at a time
  • Former R&D researcher at PAMAir.org
  • Hanoi, Vietnam
View GitHub Profile
@binh-bk
binh-bk / find_and_move_files.py
Last active June 7, 2018 04:04
python3 to look for a list of file format (movies, images) or file name patterns, and move found files into a designated folder, log record
#! /usr/bin/python3
# this script run on Linux, change path in accordance with your OS
import shutil
import fnmatch
import os
# images = ['*.jpg', '*.jpeg', '*.png', '*.tif', '*.tiff']
movies = ['*.mov', '*.mp4', '*.avi', '*.flv', '*.wmv','*.MOV', '*.MP4', '*.AVI', '*.FLV', '*.WMV']
#patterns = ['*_????_1.*'] # regex looking for my duplicated files
@binh-bk
binh-bk / recordSerial.py
Last active May 18, 2022 04:16
record serial and log output, useful tools working Arduino
#! /usr/bin/python3
'''
to use python 2 use /usr/bin/python2
requires pySerial to be installed
add date to the header, and time to the begining of each line
add sys argument to customize
USE: make executable by chmod +x scriptname.py and
> ./recordSerial.py test1000.txt (and Enter)
'''
#! /usr/bin/python3
# demonstrate while loop, try-except block, and print string
# EAFP: Easier to Ask for Forgiveness than Permission
# Binh Nguyen, July 20, 2018
import random
secret = random.randint(0, 100)
flag = True
count = 0
def delta(input_, target):
if abs(input_ - target) <= 5:
@binh-bk
binh-bk / captureSerial.py
Last active December 30, 2019 16:02
capture Serial data and log to file
#! /usr/bin/python3
'''
Binh Nguyen, Jan 2019
to use python 2 use /usr/bin/python2
requires pySerial to be installed
add date to the header, and time to the begining of each line
add sys argument to customize
USE: make executable by chmod +x scriptname.py and
> ./recordSerial.py test1000.txt (and Enter)
or python3 captureSerial.py "this is my optional message added the top of the file"
@binh-bk
binh-bk / readPMS7003.py
Last active January 30, 2019 11:46
read and log data from dust sensor PM2.5 Plantower PMS7003
#! /usr/bin/python2
"""
Binh Nguyen, Deccember 01, 2018
forked from Mark Benson's gist
Read a Plantower PMS7003 serial sensor data.
English datasheet: https://www.pdf-archive.com/2017/04/12/plantower-pms-7003-sensor-data-sheet/plantower-pms-7003-sensor-data-sheet.pdf
The sensor payload is 32 bytes:
"""
import serial
@binh-bk
binh-bk / sds011
Last active August 9, 2020 06:28 — forked from kadamski/sds011
SDS011 dust sensor reading
#!/usr/bin/python2 # only works with python2.7
# coding=utf-8
'''
forked from A. Adamski's gist: https://gist.github.com/kadamski/92653913a53baf9dd1a8
"DATASHEET": http://cl.ly/ekot
Binh Nguyen, November 2018
adapted from kadamski script with additional features:
1. logging
2. calculate AQI (US)
3. publish to MQTT broker.
@binh-bk
binh-bk / find_n_collect_video_files.py
Last active February 16, 2020 13:56
find all video files by extensions and collect the files into one folder
# Binh Nguyen, Feb 15, 2020
'''
Moving files with movies or images to a designated folder
Useful to collect large files (movies) to one places
'''
import fnmatch
import os
import shutil
movies = ['*.mov', '*.avi', '*.AVI', '*.MOV', '*.mp4', '*.MP4']
@binh-bk
binh-bk / django_deploy.md
Created June 29, 2021 02:30 — forked from bradtraversy/django_deploy.md
Django Deployment - Digital Ocean

Django Deployment to Ubuntu 18.04

In this guide I will go through all the steps to create a VPS, secure it and deploy a Django application. This is a summarized document from this digital ocean doc

Any commands with "$" at the beginning run on your local machine and any "#" run when logged into the server

Create A Digital Ocean Droplet

Use this link and get $10 free. Just select the $5 plan unless this a production app.

@binh-bk
binh-bk / script.sh
Created February 5, 2023 05:03 — forked from vielhuber/script.sh
PostgreSQL: Backup and restore export import pg_dump with password on command line #sql
# best practice: linux
nano ~/.pgpass
*:5432:*:username:password
chmod 0600 ~/.pgpass
# best practice: windows
edit %APPDATA%\postgresql\pgpass.conf
*:5432:*:username:password
# linux
@binh-bk
binh-bk / pace_in_mile_to_km.py
Last active November 5, 2024 05:48
convert running pace in minutes per mile to minutes per km and distance of mile to km
#! /usr/python3
def pace_mi2km(minute_per_mile: str):
# minute_a_mile: str, for example 10:19 (10minutes 19 seconds per mile)
# return a str of minutes per km
mile = 1.60934
# convert pace mm:ss to second
minute, second = minute_per_mile.split(':')[0].strip(), minute_per_mile.split(':')[1].strip()
# print(minute, second)
seconds = int(minute)*60 + int(second)