Skip to content

Instantly share code, notes, and snippets.

View jhxxs's full-sized avatar
🍵
三点几了,饮茶先!

Kyle jhxxs

🍵
三点几了,饮茶先!
View GitHub Profile
@jhxxs
jhxxs / span-method.ts
Last active November 16, 2022 08:41
spanMethod
interface NetConfigStep {
/* 配网引导内容 */
content: {
[key: string]: string
}
/* 文件地址URL */
file_url: string
id?: number
/* 配网类型,支持 BLE、AP、EZ、ZB、ZBN */
@jhxxs
jhxxs / getBytes.ts
Last active April 4, 2022 12:09
等同于java的String.getBytes方法
function strToUtf8Bytes(str = '') {
const utf8: number[] = [];
for (let i = 0; i < str.length; i++) {
let charCode = str.charCodeAt(i);
if (charCode < 0x80) utf8.push(charCode);
else if (charCode < 0x800) {
utf8.push(0xc0 | (charCode >> 6), 0x80 | (charCode & 0x3f));
} else if (charCode < 0xd800 || charCode >= 0xe000) {
utf8.push(0xe0 | (charCode >> 12), 0x80 | ((charCode >> 6) & 0x3f), 0x80 | (charCode & 0x3f));
} else {
@jhxxs
jhxxs / encrypt.java
Last active March 3, 2022 08:50
数据加密
public static byte[] encrypt(byte[] plain, String key) throws Exception {
if (plain == null) {
throw new Exception("plain cannot be null");
}
if (key == null) {
throw new Exception("key cannot be null");
}