Skip to content

Instantly share code, notes, and snippets.

View JCloudYu's full-sized avatar

JCloudYu JCloudYu

View GitHub Profile
@JCloudYu
JCloudYu / ibeacon.py
Created October 1, 2023 02:50
ibeacon.py
"""
The MIT License (MIT)
Copyright © 2020 Walkline Wang (https://walkline.wang)
Gitee: https://gitee.com/walkline/esp32-ble-uart
Original repo: https://github.com/micropython/micropython/blob/master/examples/bluetooth/ble_uart_peripheral.py
"""
import ubluetooth as bt
__UART_UUID = bt.UUID("6E400001-B5A3-F393-E0A9-E50E24DCCA9E")
__RX_UUID = bt.UUID("6E400002-B5A3-F393-E0A9-E50E24DCCA9E")
@JCloudYu
JCloudYu / beacon.py
Created October 1, 2023 02:45 — forked from N3MIS15/beacon.py
micropython iBeacon example
import struct
import ubluetooth as bt
from micropython import const
MANUFACTURER_ID = const(0x004C)
DEVICE_TYPE = const(0x02)
DATA_LENGTH = const(0x15)
BR_EDR_NOT_SUPPORTED = const(0x04)
FLAG_BROADCAST = const(0x01)
MANUFACTURER_DATA = const(0xFF)
@JCloudYu
JCloudYu / tools.runtime.js
Last active February 13, 2024 11:16
A tiny log tool that generates log string in json formats
// LogTool
{
const SESSION_ID = require('node:crypto').randomBytes(10);
let SEQ = 0;
const LogStreamMeta = new WeakMap();
class LogStream {
constructor() {
LogStreamMeta.set(this, {
@JCloudYu
JCloudYu / ToLocalISOString.js
Last active June 30, 2023 17:15
Convert date to a string formatted as ISO with local timezone
function ToLocalISOString(ref_date=undefined, show_milli=false) {
if ( this instanceof Date ) ref_date = this;
if ( typeof ref_date === "string" || typeof ref_date === "number" ) {
ref_date = new Date(ref_date);
}
else
if ( !(ref_date instanceof Date) ) {
ref_date = new Date();
}
@JCloudYu
JCloudYu / storage.console.ts
Last active June 10, 2023 16:29
shared-storage extended console
import $ from "shstore";
import util from "util";
const STORE_KEY = 'console';
declare global {
interface ExtendedSharedStorage{(scope:typeof STORE_KEY):{
colorize:boolean;
max_depth:number|null;
show_milli:boolean;
@JCloudYu
JCloudYu / uniqidentity.js
Last active March 14, 2023 04:40
A script that will generate uniq identity to /etc/uniqidentity.js
#!/usr/bin/env node
const fs = require('fs');
const os = require('os');
if ( os.platform().substring(0,3) === 'win' ) {
console.error("This script doens't support windows environment!");
process.exit(1);
}
@JCloudYu
JCloudYu / webcrypto-examples.md
Created February 9, 2023 11:25 — forked from pedrouid/webcrypto-examples.md
Web Cryptography API Examples
declare type bytes = Uint8Array;
declare type uniqid = string;
declare type hex = `0x${string}`;
declare type base64 = string;
declare type base32 = string;
declare type base58 = string;
declare type http_str = `${'http'|'https'}://${string}`;
declare type email_str = `${string}@${string}.${string}`;
@JCloudYu
JCloudYu / vstore-ext-exmaple.d.ts
Created November 27, 2022 19:18
A tiny volatile memory storage designed for better typing
import "process";
declare global {
interface IVolatileStorage {
(key:'some-key'):{
definition_1: Buffer;
definition_2: string;
}
}
}
@JCloudYu
JCloudYu / trimid.d.ts
Created November 23, 2022 11:54
A simplified trimid generate function
declare const GenTrimId:{():string};
export = GenTrimId;