Skip to content

Instantly share code, notes, and snippets.

View HuakunShen's full-sized avatar

Huakun Shen HuakunShen

View GitHub Profile
@HuakunShen
HuakunShen / Browser-Bookmark-Shortcut.md
Created April 12, 2022 20:16
Browser Bookmark Shortcuts

Browser Bookmark Shortcut

Browser allows you to run JavaScript by clicking on a bookmark prefilled with JS code.

Simply Create a new bookmark, give it any name, and input the js code in a special format in the URL input box.

Video Playback Rate

javascript: var v = v = document.querySelector("video"); var t = prompt('Set the playback rate'); v.playbackRate = parseFloat(t);;
@HuakunShen
HuakunShen / README.md
Created April 20, 2022 20:38
Remove Duplicate Image from Dataset

Remove Duplicate Images from a Dataset

We will be using Python package imagededup to detect duplicate images.

There are multiple options (algorithms) for detecting duplicates.

  • Convolutional Neural Network (CNN)
  • Perceptual hashing (PHash)
  • Difference hashing (DHash)
  • Wavelet hashing (WHash)
@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;
@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 / 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 / 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 / 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 / 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 / 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 / ezup-update.json
Last active May 18, 2024 15:03
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": {