Skip to content

Instantly share code, notes, and snippets.

View HuakunShen's full-sized avatar

Huakun Shen HuakunShen

View GitHub Profile
@HuakunShen
HuakunShen / Cargo.toml
Created September 2, 2023 15:44
Rust actix file upload
[package]
name = "rust_http_file_upload"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
actix = "0.13.1"
actix-multipart = "0.6.1"
@HuakunShen
HuakunShen / crosscopy-desktop-update.json
Created August 8, 2023 18:37
CrossCopy Tauri Desktop Update File
{}
@HuakunShen
HuakunShen / ezup-update.json
Last active December 8, 2023 11:28
ezup updater file
{
"version": "0.1.8",
"notes": "See the assets to download this version and install.",
"pub_date": "2023-06-13T05:12:10.282Z",
"platforms": {
"linux-x86_64": {
"signature": "dW50cnVzdGVkIGNvbW1lbnQ6IHNpZ25hdHVyZSBmcm9tIHRhdXJpIHNlY3JldCBrZXkKUlVRQlFBRHprQnQ1Qm1GZUpQcFBxTGJtbER3cWlmKzVPbUNMQlFNSXQ0TVQ2V0RSMVkzY1JNc0YvWGh5Y0FpZXlQY25TRXNrU0ErV0xCUjMyTmloUVR2dXZCMzBZK0hBTWdJPQp0cnVzdGVkIGNvbW1lbnQ6IHRpbWVzdGFtcDoxNjg2NjMyMDk3CWZpbGU6ZXotdXBfMC4xLjhfYW1kNjQuQXBwSW1hZ2UudGFyLmd6CnZ6ZHBkall4TnZhUlpieXUyMUZZTFBqRGJhVXpGVzFFUGFwcDByS3VQb0xrUE9uNWEzWEY0RGppRGQ4c3lpWlZvL3R6MHVGYkZjNjJmbnVmb3VWZ0RRPT0K",
"url": "https://github.com/HuakunShen/EzUp/releases/download/v0.1.8/ez-up_0.1.8_amd64.AppImage.tar.gz"
},
"windows-x86_64": {
@HuakunShen
HuakunShen / wormhole-gui-update.json
Last active June 13, 2023 04:29
wormhole-gui updater file
{
"version": "0.1.6",
"notes": "See the assets to download this version and install.",
"pub_date": "2023-06-13T02:44:18.071Z",
"platforms": {
"linux-x86_64": {
"signature": "dW50cnVzdGVkIGNvbW1lbnQ6IHNpZ25hdHVyZSBmcm9tIHRhdXJpIHNlY3JldCBrZXkKUlVTbU5XTmtNQkU1NDlIWkw4SHN2em5OQTBxVm90eFNsYUZQeDhMckRteUQ1dndDR01sa3FzbG9KSDNmVmZTenNrdUoyRGh5Z21pcGVDT0cvdEpJWEFHTXV2ejY1QVp5alFVPQp0cnVzdGVkIGNvbW1lbnQ6IHRpbWVzdGFtcDoxNjg2NjIzMzkwCWZpbGU6d29ybWhvbGUtZ3VpXzAuMS42X2FtZDY0LkFwcEltYWdlLnRhci5negpzUGh2Q2dTZU01Q0pZQlVnUWo1MkxROFJvYTU2WjA0dUl3ZUROTWJEYW4zUGFDdUdQZXJXRmY3c1Y4Z0pkNlJ5aWpIaGlLQmNmeHErQWZBSVhvUVNEUT09Cg==",
"url": "https://github.com/HuakunShen/wormhole-gui/releases/download/v0.1.6/wormhole-gui_0.1.6_amd64.AppImage.tar.gz"
},
"windows-x86_64": {
@HuakunShen
HuakunShen / update-all-submodules.sh
Created January 9, 2023 23:26
Update and commit all submodules in one command.
#!/bin/bash
cwd=$PWD
submodulePaths=$(git submodule | awk '{$1=$1;print}' | cut -d ' ' -f 2)
function git_add_commit_update {
nothing=$(git status | grep 'nothing to commit')
if [[ -z $nothing ]]; then
git add .
@HuakunShen
HuakunShen / main.rs
Created January 8, 2023 16:57
Read Clipboard Image and Write to a File using rust
// cargo add image
// cargo add arboard
use std::convert::TryInto;
use arboard::*;
use image::*;
fn main() {
let mut clipboard = Clipboard::new().unwrap();
let image = match clipboard.get_image() {
@HuakunShen
HuakunShen / image-convert.ts
Created December 10, 2022 06:59
Read image as string -> convert back to buffer -> save image
import fs from 'node:fs';
const imagePath = '000000.jpg';
const encode = 'base64';
const rawImgBuf = fs.readFileSync(imagePath);
const encodedStr = rawImgBuf.toString(encode);
const recoveredBuf = Buffer.from(encodedStr, encode);
fs.writeFileSync('test.jpg', recoveredBuf);
@HuakunShen
HuakunShen / expressjs-style-middelware-design.md
Last active December 6, 2022 04:37
Express.js-Style Middleware Design using Chain of Responsibility

Express-Style Middleware Design

This gist demonstrates how to implement a expressjs-style middleware design with Chain of Responsibility design pattern.

expressjs middleware has the following structure

app.use((req, res, next) => {
  ...
 next();
@HuakunShen
HuakunShen / publish-npm-package-registry.md
Last active November 10, 2022 06:13
How to publish npm package to different registry

Install Package

If you want to install package from some registry, set the registry first

# choose one of the following if you don't have a .npmrc file
npm config set @crosscopy:registry https://registry.npmjs.org
npm config set @crosscopy:registry https://npm.pkg.github.com
@HuakunShen
HuakunShen / sample_usage.ts
Last active November 8, 2022 05:41
Socket.IO wrapper, easy reconnection, avoid re-registering event listeners when socket is changed (reconnected) using 2 layers of event listening design with "events" package.
const syncer = Syncer.getInstance({
connectionURL: "https://crosscopy.io",
accessToken: "Bearer <token>",
events: eventNames.SOCKETIO_EVENTS,
});
syncer
.onInit((data) => {
data.newRecords;
data.idMapping;
data.deletedRecInfo;