Skip to content

Instantly share code, notes, and snippets.

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 / django_deploy.md
Created Jun 29, 2021 — forked from bradtraversy/django_deploy.md
Django Deployment - Digital Ocean
View django_deploy.md

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 / find_n_collect_video_files.py
Last active Feb 16, 2020
find all video files by extensions and collect the files into one folder
View find_n_collect_video_files.py
# 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 / sds011
Last active Aug 9, 2020 — forked from kadamski/sds011
SDS011 dust sensor reading
View sds011
#!/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 / readPMS7003.py
Last active Jan 30, 2019
read and log data from dust sensor PM2.5 Plantower PMS7003
View readPMS7003.py
#! /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 / captureSerial.py
Last active Dec 30, 2019
capture Serial data and log to file
View captureSerial.py
#! /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"
View try_except_while_guessingnumber_demo.py
#! /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 / recordSerial.py
Last active May 18, 2022
record serial and log output, useful tools working Arduino
View recordSerial.py
#! /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)
'''
@binh-bk
binh-bk / find_and_move_files.py
Last active Jun 7, 2018
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
View find_and_move_files.py
#! /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