Skip to content

Instantly share code, notes, and snippets.

View ngtrthanh's full-sized avatar

Nguyen Trong Thanh ngtrthanh

  • Home
  • 23:41 (UTC +07:00)
View GitHub Profile
@ngtrthanh
ngtrthanh / raspberry_pi_script_as_service.md
Created December 24, 2020 16:21 — forked from emxsys/raspberry_pi_script_as_service.md
How to run a python script as a service in Raspberry Pi - Raspbian Jessie

How to Run a Script as a Service in Raspberry Pi - Raspbian Jessie

By: Diego Acuña

Original Article: http://www.diegoacuna.me/how-to-run-a-script-as-a-service-in-raspberry-pi-raspbian-jessie/

A pretty common task when using this device, is to run some script (for example a python script) as a service in the operating system so it can start on boot, stop and restart using systemctl and more. In this post I'm going to explain how to set a little script as a service using Raspbian Jessie in a Raspberry Pi.

Example Python Script

@ngtrthanh
ngtrthanh / wireguard.conf
Created January 2, 2021 15:54 — forked from nealfennimore/wireguard.conf
Wireguard VPN - Forward all traffic to server
# ------------------------------------------------
# Config files are located in /etc/wireguard/wg0
# ------------------------------------------------
# ---------- Server Config ----------
[Interface]
Address = 10.10.0.1/24 # IPV4 CIDR
Address = fd86:ea04:1111::1/64 # IPV6 CIDR
PostUp = iptables -A FORWARD -i wg0 -j ACCEPT; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE; ip6tables -A FORWARD -i wg0 -j ACCEPT; ip6tables -t nat -A POSTROUTING -o eth0 -j MASQUERADE # Add forwarding when VPN is started
PostDown = iptables -D FORWARD -i wg0 -j ACCEPT; iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE; ip6tables -D FORWARD -i wg0 -j ACCEPT; ip6tables -t nat -D POSTROUTING -o eth0 -j MASQUERADE # Remove forwarding when VPN is shutdown
@ngtrthanh
ngtrthanh / .. MediaCreationTool.bat ..md
Created October 2, 2021 10:39 — forked from AveYo/.. MediaCreationTool.bat ..md
Universal MediaCreationTool wrapper for all MCT Windows 10 versions from 1507 to 21H1 with business (Enterprise) edition support

Not just an Universal MediaCreationTool wrapper script with ingenious support for business editions,
Preview
A powerful yet simple windows 1X deployment automation tool as well!

awesome gui dialogs to pick windows version and preset action
Auto Setup choice for upgrade directly without prompts, with edition change / intelligent fallback
Create ISO choice for authoring iso file directly via DIR2ISO snippet, including any 'oem' customizations
Create USB choice for authoring usb via native MCT, including any 'oem' customizations (prompts once)
Select in MCT choice for vanilla MCT processing without 'oem' modifications, script quits straightway
control via set script vars, commandline parameters or rename script like iso 21H2 Pro MediaCreationTool.bat

@ngtrthanh
ngtrthanh / gpsd.sh
Created February 21, 2022 08:48 — forked from hsiboy/gpsd.sh
Adding GPS to Raspberry Pi running PiAware / Dump1090 for ADS-B Flight Tracking
sudo apt-get install -y gpsd
sudo apt-get install -y gpsd-clients
sudo apt-get install -y python-gps
sudo apt-get install -y libcap-dev
sudo apt-get install -y pps-tools
echo console=ttyACM0,115200 >> /boot/cmdline.txt
# edit /etc/rc/local and add (before the exit 0)
# sudo gpsd /dev/ttyACM0 -F /var/run/gpsd.sock
@ngtrthanh
ngtrthanh / RS485_pyModbus_rs485.py
Created March 8, 2022 08:59 — forked from remceTkedaR/RS485_pyModbus_rs485.py
Python - Raspberry Pi - RS485
# -----
from pymodbus.client.sync import ModbusSerialClient
import serial.rs485
ser = serial.rs485.RS485(port='/dev/ttyAMA0', baudrate=1200)
ser.rs485_mode = serial.rs485.RS485Settings(rts_level_for_tx=False,
rts_level_for_rx=True,
delay_before_tx=0.0,
delay_before_rx=-0.0)
@ngtrthanh
ngtrthanh / test.service
Created March 10, 2022 15:48 — forked from circa10a/test.service
A Simple Systemd Service
#/etc/systemd/system/test.service
[Unit]
Description=Test Systemd Service
[Service]
ExecStartPre=/usr/bin/echo -e "\033[0;33m Pre start \033[0m"
ExecStart=/usr/bin/sleep 10
ExecStartPost=/usr/bin/echo -e "\033[0;33m Post start \033[0m"
@ngtrthanh
ngtrthanh / counter.py
Created March 23, 2022 15:57 — forked from yildizberkay/counter.py
Simple RaspberryPi Pulse Counter
import RPi.GPIO as GPIO
import threading
GPIO.setmode(GPIO.BCM)
GPIO.setup(23, GPIO.IN, pull_up_down = GPIO.PUD_DOWN)
i = 0
# Source: http://stackoverflow.com/a/14035296/2094521
def set_interval(func, sec):
def func_wrapper():
// Import Flux date package: https://docs.influxdata.com/influxdb/v2.0/reference/flux/stdlib/date/
import "date"
// Import Flux dictionary package: https://docs.influxdata.com/influxdb/v2.0/reference/flux/stdlib/dict/
import "dict"
bucket = "mybucket"
// Work with data collected in the past 5 minutes
start = -5m
stop = now()
@ngtrthanh
ngtrthanh / influxdb2.sh
Created April 10, 2022 06:14 — forked from ysdede/influxdb2.sh
InfluxDB 2.x Open Source Time Series Database on wsl2
wget -qO- https://repos.influxdata.com/influxdb.key | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/influxdb.gpg > /dev/null
export DISTRIB_ID=$(lsb_release -si); export DISTRIB_CODENAME=$(lsb_release -sc)
echo "deb [signed-by=/etc/apt/trusted.gpg.d/influxdb.gpg] https://repos.influxdata.com/${DISTRIB_ID,,} ${DISTRIB_CODENAME} stable" | sudo tee /etc/apt/sources.list.d/influxdb.list > /dev/null
sudo apt-get update && sudo apt-get install influxdb2
sudo chmod +x /etc/init.d/influxdb
sudo chown root:root /etc/init.d/influxdb
sudo update-rc.d influxdb defaults
sudo update-rc.d influxdb enable
@ngtrthanh
ngtrthanh / css-radar-animation.markdown
Created February 1, 2023 12:22
CSS radar animation