Skip to content

Instantly share code, notes, and snippets.

@skyone-wzw
skyone-wzw / sqlQuery.js
Created September 11, 2021 09:56
SQL异步请求Promise
const sqlQuery = ({sql, connection}) => {
return new Promise((resolve, reject) => {
connection.query(sql, (err, result) => {
if (err) {
reject(err);
}
resolve(result);
})
})
}
@skyone-wzw
skyone-wzw / rename.sh
Created October 21, 2021 09:24
批量重命名
for i in `ls`; do
mv $i `echo $i | sed 's/from/to/'`
done
@skyone-wzw
skyone-wzw / hash.js
Created October 29, 2021 11:43
使用SHA256与MD5
const crypto = require('crypto');
const sha256 = (str) => {
const hash = crypto.createHash('sha256');
return hash.update(str, "utf-8").digest("hex");
}
const md5 = (str) => {
const hash = crypto.createHash('md5');
return hash.update(str, "utf-8").digest("hex");
}
@skyone-wzw
skyone-wzw / CMakeLists.txt
Last active December 22, 2021 05:19
Use CMake to build lua
project(lua C)
cmake_minimum_required(VERSION 3.16)
set(src_code
src/lapi.c src/lcode.c src/lctype.c src/ldebug.c src/ldo.c src/ldump.c src/lfunc.c src/lgc.c src/llex.c
src/lmem.c src/lobject.c src/lopcodes.c src/lparser.c src/lstate.c src/lstring.c src/ltable.c src/ltm.c
src/lundump.c src/lvm.c src/lzio.c)
set(src_lib
src/lauxlib.c src/lbaselib.c src/lcorolib.c src/ldblib.c src/liolib.c src/lmathlib.c src/loadlib.c
src/loslib.c src/lstrlib.c src/ltablib.c src/lutf8lib.c src/linit.c)
@skyone-wzw
skyone-wzw / tsconfig.json
Created January 27, 2022 14:14
一份带中文注释的 typescript 配置文件
{
"compilerOptions": {
/////////////////////////////////////////////////////////////////////////////////////////////////////////
/* 项目 */
"incremental": true, /* 启用增量编译 */
/* 语言和环境 */
"target": "es2016", /* 设置 JavaScript 语言版本 */
@skyone-wzw
skyone-wzw / gdt.asm
Created February 15, 2022 11:57
A file learn how to write GDT (Global Descriptor Table) 带中文
; Segment Descriptor
;
; |------------------------------------------------------|----------------------------------------|
; | 63 56 | 55 52 | 51 48 | 47 40 | 39 32 |
; | Base (24~31) | Flags (3~0) | Limit (19~16) | Access Byte (7~0) | Base (23~16) |
; |------------------------------------------------------|----------------------------------------|
; | 31 16 | 15 0 |
; | Base (0~15) | Limit (0~15) |
; |------------------------------------------------------|----------------------------------------|
;
#define offset_of(type, member) ((size_t) &((type *)0)->member)
#define container_of(ptr, type, member) ({ \
const typeof( ((type *)0)->member ) *__mptr = (ptr); \
(type *)( (char *)__mptr - offset_of(type, member) );})
@skyone-wzw
skyone-wzw / dcgan.ipynb
Created July 23, 2022 04:21
对抗神经网络
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@skyone-wzw
skyone-wzw / JsonPolymorphism.kt
Created November 10, 2022 05:38
Kotlin Json 序列化的多态
import kotlinx.coroutines.runBlocking
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.json.Json
private val json = Json {
classDiscriminator = "myType"
}
@skyone-wzw
skyone-wzw / KotlinNativeReadFile.kt
Created January 15, 2023 10:58
Read a file in kotlin/native use c interop.
package host.skyone.native
import kotlinx.cinterop.*
import platform.posix.*
fun main() {
val file = "test.txt"
val contentSize = nativeHeap.alloc<stat>().apply { stat(file, this.ptr) }.st_size
val buffer = ByteArray(contentSize)
val fp = open(file, O_RDONLY)