Skip to content

Instantly share code, notes, and snippets.

View simryang's full-sized avatar

Joseph simryang

  • WIZnet
  • 성남시
View GitHub Profile
@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} &")
@simryang
simryang / vim_remember_last_cursor_remote.sh
Created June 20, 2023 07:53
Change vim global setting to remember last curosr position
ssh pi@pi_ip_address "sudo sed -i 's/"\""au/au/' /etc/vim/vimrc"
@simryang
simryang / get_rpi_serial.sh
Last active December 29, 2023 01:10
Get Rasbperry Pi Serial from /proc/cpuinfo
python3 -c 'from pathlib import Path; import yaml; print(yaml.safe_load(Path("/proc/cpuinfo").read_text().replace("\t", " ")).get("Serial"))'
@simryang
simryang / my_public_ip.sh
Last active June 9, 2023 06:53
Identify public IP address
echo $(curl -s 'https://ident.me')
@simryang
simryang / folding.md
Last active May 22, 2023 00:08
[github markdown] 접기 / 펼치기
접기

자세한 내용