Skip to content

Instantly share code, notes, and snippets.

@syaoo
syaoo / timing.c
Created June 20, 2025 09:48
对比linux、windows上的几种时间获取的函数
#include <stdio.h>
#include <time.h>
#ifdef _WIN32
#include <windows.h>
#endif
#ifdef __linux__
#include <unistd.h>
#endif
#include <sys/time.h>
@syaoo
syaoo / fcs.c
Created May 20, 2025 01:05
some method for calc crc for enthernet fcs.
#include <stdint.h>
#include <stdio.h>
#include <zlib.h>
// gcc fcs.c -lz
#define CRC_POLY UINT32_C(0xEDB88320)
uint32_t crc_ether(const uint8_t *data, size_t len) {
uint32_t accum = ~UINT32_C(0);
for (size_t n = 0; n < len; ++n) {
accum ^= data[n];
@syaoo
syaoo / list_ksz9031_reg.c
Created May 19, 2025 05:35
read or write enthernet phy register use mdio.
/**
*
* usage: ./list_ksz9031_reg ethx phyid
* ethX is Ethernet Interface name, such as, eth0, eth1...
* phyid is PHY's physical address, such as, 0.
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@syaoo
syaoo / 163music.py
Last active February 10, 2025 10:55
网易云音乐Android App缓存解码并获取歌曲信息
#!/bin/python3
"""
1. 加密文件的各字节与0xa3异或运算
2. filetype.guess_extension()获取解密后的文件类型
3. 根据id从网易云音乐获取歌曲信息
3.1 该API使用简单,但存在被封ip的情况
[收藏这些API,获取网易云音乐数据超轻松 - 云+社区 - 腾讯云](https://cloud.tencent.com/developer/article/1543945)
https://music.163.com/api/song/detail/?id={864489955}&ids=%5B{864489955}%5D
获取的json文件关键词可能有所不同,如歌手关键词可能上ar或artist,还有可能存在返回的json为空的情况
3.2 使用POST方法获取,该方法实现较为麻烦
@syaoo
syaoo / show_sympy_in_browser.py
Created June 26, 2024 06:10
A simple single page http server, for show sympy calculate result.
import sympy
from sympy import Symbol, Matrix, cos, sin, latex
import http.server
import socketserver
# 欧拉角$\varepsilon_x, \varepsilon_y, \varepsilon_z
# 绕x轴旋转角
Ex = Symbol('varepsilon_x', real=True)
# 绕y轴旋转角
@syaoo
syaoo / get_ip.py
Last active July 1, 2024 01:32
Using flask to check client ip
import ipaddress
import json
import urllib
from flask import Flask
from flask import request
from flask import jsonify, render_template_string
"""
# 获取客户端IP
一个简单的demo,

SSH端口转发

  1. 设备B0 IP: 10.0.0.90
  2. 设备A IP: 10.0.0.80, 192.168.0.50
  3. 设备C IP: 192.168.0.51
    ┌────┐         ┌───┐                        
    │    │         │   │         ┌──────────┐   
 │ B0 │◄───────►│ A ├────────►│ Internet │