Skip to content

Instantly share code, notes, and snippets.

View simryang's full-sized avatar

Joseph simryang

  • WIZnet
  • 성남시
  • 12:21 (UTC +09:00)
View GitHub Profile
@simryang
simryang / timezonelist.py
Last active September 5, 2024 07:05
timezone and key for openwrt
# Licensed to the public under the Apache License 2.0.
# from https://github.com/openwrt/luci/blob/master/modules/luci-lua-runtime/luasrc/sys/zoneinfo/tzdata.lua
# ('Timezone name', 'Key')
# TZ='Key' date +%Y%m%d-%H%M%S
# for example) TZ='KST-9' date +%Y%m%d-%H%M%S for Asia/Seoul
TZ = (
('Africa/Abidjan', 'GMT0'),
('Africa/Accra', 'GMT0'),
('Africa/Addis Ababa', 'EAT-3'),
@simryang
simryang / flash_test.sh
Last active July 16, 2024 05:29
wizfi630s with openwrt flash read/write test script
#!/bin/sh
# openwrt WizFi630S 읽기 쓰기 테스트
echo "----------------------------"
date
FILE_COUNT=$(df -h / | awk -F'[^0-9.]+' 'NR==2{print int($4)}')
for i in `seq 1 $FILE_COUNT`; do
dd if=/dev/urandom of=test_file_$i.bin bs=1M count=1 > /dev/null 2>&1
hash=`sha256sum test_file_$i.bin | awk '{print $1}'`
eval file_${i}_sha256=$hash
echo "File $i hash: $hash"
@simryang
simryang / move_file_in_py37.py
Created June 24, 2024 08:30
rename files from timestamp name to formatted name
from pathlib import Path
from os.path import splitext, dirname, rename
from os import rename
def move_pathlib(src_full: Path):
# filename = "/home/pi/1709705942.jpg"
newname = datetime.fromtimestamp(int(src_full.stem)).strftime("%Y-%m-%d_%H-%M-%S")
npp = Path(pp.parent, newname).with_suffix(pp.suffix)
src_full.rename(npp)
@simryang
simryang / aiowatch.py
Created June 24, 2024 07:59 — forked from mivade/aiowatch.py
Using watchdog with asyncio
import asyncio
from pathlib import Path
from typing import Optional
from watchdog.events import FileSystemEvent, FileSystemEventHandler
from watchdog.observers import Observer
class _EventHandler(FileSystemEventHandler):
def __init__(self, queue: asyncio.Queue, loop: asyncio.BaseEventLoop,
@simryang
simryang / w5500-overlay.dts
Created April 22, 2024 11:18 — forked from renakim/w5500-overlay.dts
WIZnet W5500 device tree overlay example for Raspberry Pi kernel
/dts-v1/;
/plugin/;
/ {
compatible = "brcm,bcm2835";
fragment@0 {
target = <&spi0>;
__overlay__ {
#address-cells = <1>;
#size-cells = <0>;
@simryang
simryang / check_jpg.py
Created January 5, 2024 02:19
check a file is jpg or not
from pathlib import Path
def is_jpg():
img = Path("output-2023-12-15/30661_10000000c840e868_2023-12-15_16-01-46.wav").read_bytes()
print("jpg" if img[0] == 0xff and img[1] == 0xd8 and img[2] == 0xff else "no jpg")
return True if img[0] == 0xff and img[1] == 0xd8 and img[2] == 0xff else False
@simryang
simryang / get_rpi_type_from_revision.py
Last active January 5, 2024 01:57
get raspberry type in python include Raspberry pi 5
import yaml
from pathlib import Path
def get_rpi_type() -> str:
rev = int(yaml.safe_load(Path("/proc/cpuinfo").read_text().replace("\t", "")).get("Revision"), base=16)
rpi_type = (rev & 0x00000FF0)>>4 if rev & 0x800000 else [0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 3, 6, 2, 3, 6, 2][rev & 0x1f]
rpi_model = {0: 'A', 1: 'B', 2: 'A+', 3: 'B+', 4: '2B', 6: 'CM1', 8: '3B', 9: 'Zero', 0xa: 'CM3', 0xc: 'ZeroW', 0xd: '3B+', 0xe: '3A+', 0x10: 'CM3+', 0x11: '4B', 0x12: 'Zero2W', 0x13: '400', 0x14: 'CM4', 0x15: 'CM4S', 0x17: '5',}
return rpi_model.get(rpi_type, "")
@simryang
simryang / check_csi_rpicamera.py
Created November 17, 2023 06:54
raspberry pi 4B check csi rpi2 camera
from pathlib import Path
import smbus
bus_number = 10
def have_csicamera() -> bool:
# csi 카메라는 i2c 를 사용하므로 연결되어 있다면 /dev/i2c-10 이 존재
return Path(f"/dev/i2c-{bus_number}").exists()
@simryang
simryang / mv_git_repo_with_history.sh
Last active December 29, 2023 01:06 — forked from trongthanh/gist:2779392
How to move a folder from one repo to another and keep its commit history
# source: http://st-on-it.blogspot.com/2010/01/how-to-move-folders-between-git.html
# First of all you need to have a clean clone of the source repository so we didn't screw the things up.
git clone git://server.com/my-repo1.git
# After that you need to do some preparations on the source repository, nuking all the entries except the folder you need to move. Use the following command
git filter-branch --subdirectory-filter your_dir -- -- all
# This will nuke all the other entries and their history, creating a clean git repository that contains only data and history from the directory you need. If you need to move several folders, you have to collect them in a single directory using the git mv command.
@simryang
simryang / asyncssh_nohup.py
Created September 22, 2023 01:03
example for how to do remote ssh command via asyncssh/asyncio
import time
import asyncssh
import asyncio
params = range(10)
async def run():
async with asyncssh.connect("localhost", 8090, username="tester", password="t35t3r", known_hosts=None) as conn:
for param in params:
await conn.create_process(f"nohup very_very_long_run.sh {param} &")