Skip to content

Instantly share code, notes, and snippets.

View teshanshanuka's full-sized avatar

Teshan Liyanage teshanshanuka

View GitHub Profile
@teshanshanuka
teshanshanuka / myserv.service
Last active July 1, 2018 07:58
medium article 1
[Unit]
Description=Our sample program
After=multi-user.target
[Service]
Type=idle
ExecStart=/usr/bin/python3 /home/<username>/myprogram/myservice.py
[Install]
WantedBy=multi-user.target
import time
with open("logs/myservice.log", "w") as fl:
while True:
try:
fl.write(time.ctime() + '\n')
time.sleep(1)
except KeyboardInterrupt:
break
import time
filename = "/home/<username>/myprogram/logs/myservice.log"
with open(filename, "w") as fl:
while True:
fl.write(time.ctime() + '\n')
time.sleep(1)
import time, signal
def exit_gracefully(signum, frame):
global exit_now
exit_now = True
signal.signal(signal.SIGTERM, exit_gracefully)
filename = "/home/<username>/myprogram/logs/myservice.log"
exit_now = False
@teshanshanuka
teshanshanuka / ROS_mqtt_bridge_client.py
Last active June 22, 2020 19:25
ROS mqtt_bridge client for `msgpack` packed payloads
# Author: Teshan Liyanage <[email protected]>
# Original mqtt client code from https://www.eclipse.org/paho/clients/python/docs/
import paho.mqtt.client as mqtt
import logging
import msgpack
logging.basicConfig()
log = logging.getLogger(__name__)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@teshanshanuka
teshanshanuka / text_box.py
Last active November 11, 2022 02:08
Draw unicode box around text
# Author: Teshan Liyanage <[email protected]>
def box_text(text, fmt="regular", padding=(0, 0)):
""" Put text into a box in unicode
:param text: Text
:param fmt: Options - [regular, bold, rounded]
:param padding: horizontal and vertical padding
:Example:
@teshanshanuka
teshanshanuka / gen.sh
Created October 20, 2020 09:30
Python3 import problem - folder structure
#!/bin/bash -e
# Question: https://stackoverflow.com/questions/64427513/python3-package-file-cannot-import-from-same-directory-when-used-in-a-different?noredirect=1#comment113946981_64427513
mkdir -p pyprob/mypkg
cd pyprob/mypkg
touch __init__.py
cat > foolib.py << EOF
@teshanshanuka
teshanshanuka / img_quality_reducer.py
Created April 19, 2021 19:14
Reduce image quality
import cv2
import os
from tqdm import tqdm
ipdir = 'Camera'
opdir = 'CamLow'
out_quality = 70
fmt = ('.jpg', '.jpeg', '.png')
for f in tqdm([_f for _f in os.listdir(ipdir) if _f.endswith(fmt)]):
FROM ubuntu:18.04
RUN apt update && apt dist-upgrade -y
RUN apt install -y software-properties-common
RUN add-apt-repository ppa:bitcoin/bitcoin
RUN apt update
RUN apt install -y build-essential gcc make perl dkms git build-essential libtool autotools-dev automake pkg-config libssl-dev libevent-dev bsdmainutils libboost-system-dev libboost-filesystem-dev libboost-chrono-dev libboost-program-options-dev libboost-test-dev libboost-thread-dev libboost-all-dev
RUN apt install -y libdb4.8-dev libdb4.8++-dev libminiupnpc-dev libzmq3-dev libprotobuf-dev protobuf-compiler libprotobuf-dev protobuf-compiler openssl1.0 libssl1.0-dev