Skip to content

Instantly share code, notes, and snippets.

@heisvoid
heisvoid / chkspr4.py
Last active August 7, 2024 04:43
Verify sprite type 4 in TWG
# -*- coding: utf-8 -*-
# Verity sprite file
import argparse
import struct
import os
parser = argparse.ArgumentParser(description='Check sprite file.')
parser.add_argument('-f', required=True, help='sprite file', dest='spr')
@heisvoid
heisvoid / waterbill-gimhae.py
Last active March 25, 2017 12:36
Water charge calculator for Daepyong building.
def cal(usage, homes, table):
charge = 0
for i, j in table:
assert 0 < i
assert 0 < j
if 0 >= usage:
break
@heisvoid
heisvoid / propertytax.py
Last active August 29, 2015 14:26
Property tax calculator for Daepyong building
HOUSE_TAX_TABLE = ((60, 1), (90, 1.5), (150, 2.5), (float('inf'), 4.0))
RESOURCE_TAX_TABLE = ((6, 0.4), (7, 0.5), (13, 0.6), (13, 0.8), (25, 1.0), (float('inf'), 1.2))
LAND_AREA = 324.7
LAND_UNIT_PRICE = 788000
BUILDING_AREA = 490.86
BUSINESS_AREA = 173.91
BUSINESS_UNIT_PRICE = 764000
def cal(usage, homes, table):
charge = 0
for i, j in table:
assert 0 < i
assert 0 < j
if 0 >= usage:
break
@heisvoid
heisvoid / dahua_ipc_event_listener.py
Last active November 17, 2022 04:16
Dahua IP camera event listener
import argparse
import pycurl
connected = False
ap = argparse.ArgumentParser(description="Monitor event notifications from Dahua IP camera.")
ap.add_argument("-i", required=True, help="User ID", dest="id")
ap.add_argument("-p", required=True, help="User Password", dest="pw")
ap.add_argument("-a", required=True, help="Address for a camera", dest="addr")
ap.add_argument("-n", default=80, required=False, help="Port number for a camera", dest="port")
@heisvoid
heisvoid / record.sh
Last active January 24, 2018 04:46
Example: Segmented RTSP recording for Dahua ip camera.
# My ffmpeg command makes time-based file names.
# RaspberryPi does not have RTC.
# So time should be synchronized to prevent files from being messed up.
/usr/bin/timedatectl status | /usr/bin/grep "synchronized: yes" >/dev/null 2>&1
if [ 0 -ne $? ]
then
return 1
fi
/usr/bin/ffmpeg -rtsp_transport tcp -stimeout 3000000 \
@heisvoid
heisvoid / record_cam.service
Last active January 25, 2018 05:13
~/.config/systemd/user/record_cam.service
[Unit]
Description=Record camera
[Service]
Type=simple
ExecStart=/bin/sh /home/heisvoid/bin/cam/record_cam.sh
Restart=always
RestartSec=10
@heisvoid
heisvoid / record_cam.timer
Created January 23, 2018 15:36
~/.config/systemd/user/record_cam.timer
[Unit]
Description=Record camera on boot
[Timer]
OnBootSec=10sec
[Install]
WantedBy=timers.target
@heisvoid
heisvoid / move_cam_records.sh
Created January 24, 2018 05:01
~/bin/move_cam_records.sh
i=0
for f in `/usr/bin/ls -1 -r /mnt/disk0/cam0/rec/*.mp4 2>/dev/null`
do
# Skip the latest file
if [ 0 -eq $i ]
then
i=1
continue
@heisvoid
heisvoid / move_cam_records.service
Last active January 25, 2018 05:12
~/.config/systemd/user/move_cam_records.service
[Unit]
Description=Move camera records
[Service]
Type=simple
ExecStart=/bin/sh /home/heisvoid/bin/cam/move_cam_records.sh