Skip to content

Instantly share code, notes, and snippets.

@wsd1
wsd1 / mqtt_pub_jpeg.py
Created April 5, 2024 18:55
一个简单的示例,通过mqtt发送一张jpeg图片。
import os
import paho.mqtt.client as mqtt
# MQTT 代理地址和端口
broker_address = "192.168.xx.xx"
broker_port = 1883
# 文件路径
file_path = "160x128_demo_.jpg"
//npm i serialport
const SerialPort = require('serialport').SerialPort;
var port = new SerialPort({
path: '/dev/ttyUSB0',
baudRate: 9600, //波特率
dataBits: 8, //数据位
parity: 'none', //奇偶校验
stopBits: 1, //停止位
flowControl: false
}, false); // this is the openImmediately flag [default is true]
@wsd1
wsd1 / noiseGen.js
Created March 7, 2024 13:35
这是AI辅助生成的代码:用nodejs向/dev/video0 推送动态帧。测试用途。
const fs = require('fs');
const WIDTH = 512;
const HEIGHT = 32;
// 打开虚拟的 V4L 设备文件
const v4l2Device = fs.openSync('/dev/video0', 'w');
// 创建虚拟视频帧数据
@wsd1
wsd1 / queue.h
Last active February 26, 2024 02:16
简单精炼的queue实现
/*
From https://github.com/JSchaenzle/c-message-queue
20240224: Add 2 APIs
20240226: shxt.Bugs. (p_queue->read_idx)++ & (capacity - 1) => (p_queue->read_idx)++ % capacity
*/
#ifndef QUEUE_H
#define QUEUE_H
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
@wsd1
wsd1 / perspectiveTest.html
Created January 12, 2024 07:33
本demo展示了使用getPerspectiveTransform函数获取变换矩阵,并使用warpPerspective函数变换图片的能力。由chatGPT3.5协助完成。
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Hello OpenCV.js</title>
</head>
<body>
<h2>本demo展示了使用getPerspectiveTransform函数获取变换矩阵,并使用warpPerspective函数变换图片的能力.</h2>
@wsd1
wsd1 / test.html
Created December 15, 2020 12:18
matter.js测试,包括attractor插件的使用
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
<title>Matter-JS</title>
<script src="https://brm.io/matter-js/demo/js/lib/decomp.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/matter-js/0.14.2/matter.js"></script>
<script src="http://raw.githack.com/liabru/matter-attractors/master/build/matter-attractors.min.js"></script>
@wsd1
wsd1 / console.js
Created April 15, 2019 02:09
浏览器 console对象的兼容性包装和缓存化处理
// console.log/warn/error/info 均可用
// console.log('ha', 'hi');
// console.show(false); //停止显示log
// console.save(true); //开始存储log
// logs = console.cache(); //获取log数组,并清空log缓存
window.console = (function (origConsole) {
@wsd1
wsd1 / loginIn.html
Created April 11, 2019 01:27
Deepstream登录退出presence API测试。结论是:可以很好的检测退出,包括正常退出,页面关闭和断网
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>DsTest</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<!--link rel="stylesheet" type="text/css" media="screen" href="main.css" /-->
<script src="https://cdn.bootcss.com/deepstream.io-client-js/2.2.1/deepstream.js"></script>
<script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
@wsd1
wsd1 / gist:4bc8c121bee064fd767cbade7f2c1e45
Last active January 24, 2019 13:14
通过 window.innerWidth 和css填充canvas满屏的方法
function adjust(canvas, rw, rh) {
var width = window.innerWidth;
//var ratio = rw / rh; //canvas.width / canvas.height;
//var height = width / ratio;
if(!rw){
rw = canvas.width
rh = canvas.height
}
var height = width * rh / rw ;
@wsd1
wsd1 / wasm-check.html
Created June 8, 2018 08:44
WebAssembly 鉴定页面
<html>
<head>
<title>WASM check</title>
</head>
<body>
<script type="text/javascript">