Skip to content

Instantly share code, notes, and snippets.

View zhangxiang958's full-sized avatar
💭
Working on my full time job

Shawn Cheung zhangxiang958

💭
Working on my full time job
View GitHub Profile
@zhangxiang958
zhangxiang958 / configure.md
Created July 3, 2025 12:33 — forked from jherax/configure.md
VS Code: Debugging with Jest

VS Code: Debugging Jest

Sometimes, debugging with console.log is not enough to find out what is happening in the code, as console.log prints only plain objects but neither functions nor objects with circular references. Besides, it's possible you may need to know the context and flow of the code.

Read more about debugging with VS Code in VS Code: Debugging.

@zhangxiang958
zhangxiang958 / HowJWTWork-README.md
Last active February 18, 2024 03:38
learn how jwt work

How JWT Work

研究下 jwt 相关的流程和逻辑是什么

What

jwt 是一种认证方式,适合分布式 sso 场景。服务端无需记录登录信息。

Why

How

@zhangxiang958
zhangxiang958 / sse.go
Created October 19, 2023 08:05 — forked from fiorix/sse.go
Go and Server Sent Events for HTTP/1.1 and HTTP/2.0
// Go and Server Sent Events for HTTP/1.1 and HTTP/2.0
//go:generate go run $GOROOT/src/crypto/tls/generate_cert.go -host localhost
package main
import (
"fmt"
"io"
"log"
"net/http"
@zhangxiang958
zhangxiang958 / testSaramaMemoryLeak.go
Created July 19, 2023 07:05
show why sarama kafka connection leads to memory leak
package main
import (
"fmt"
"log"
"net/http"
_ "net/http/pprof"
"runtime"
"strconv"
"time"
@zhangxiang958
zhangxiang958 / launch.json
Created June 15, 2021 09:14 — forked from cecilemuller/launch.json
Run ts-node in VSCode Debugger
{
"version": "0.2.0",
"configurations": [
{
"name": "Example",
"type": "node",
"request": "launch",
"runtimeExecutable": "node",
"runtimeArgs": ["--nolazy", "-r", "ts-node/register/transpile-only"],
@zhangxiang958
zhangxiang958 / encryption.js
Created May 27, 2021 12:51 — forked from vlucas/encryption.ts
Stronger Encryption and Decryption in Node.js
'use strict';
const crypto = require('crypto');
const ENCRYPTION_KEY = process.env.ENCRYPTION_KEY; // Must be 256 bits (32 characters)
const IV_LENGTH = 16; // For AES, this is always 16
function encrypt(text) {
let iv = crypto.randomBytes(IV_LENGTH);
let cipher = crypto.createCipheriv('aes-256-cbc', Buffer.from(ENCRYPTION_KEY), iv);
@zhangxiang958
zhangxiang958 / decorator.go
Created May 26, 2021 06:54 — forked from saelo/decorator.go
Decorators in Go
package main
import (
"fmt"
"reflect"
)
func Decorate(impl interface{}) interface{} {
fn := reflect.ValueOf(impl)
@zhangxiang958
zhangxiang958 / getVaildByte.go
Created May 21, 2020 02:46
获取有效字符(去除字符中的 '\000')
func GetValidByte(src []byte) []byte {
var str_buf []byte
for _, v := range src {
if v != 0 {
str_buf = append(str_buf, v)
}
}
return str_buf
}