Skip to content

Instantly share code, notes, and snippets.

@wuminzhe
wuminzhe / alias-to-github-cli-cmds.md
Last active October 17, 2024 03:53
alias-to-github-cli-cmds

add this two functions to your .zshrc

e() {
  gh copilot explain "$*"
}

s() {
  gh copilot suggest "$*"
}
@wuminzhe
wuminzhe / reliably-migrate-big-directories-with-rsync-and-autossh.md
Last active September 1, 2024 06:08
Reliably Migrate Big Directories Across Servers with rsync and autossh

Install rsync and autossh

sudo apt-get update
sudo apt-get install rsync autossh

Steps Explanation

Set Up a Persistent SSH Tunnel with autossh

@wuminzhe
wuminzhe / event_loop_pseudocode.rb
Last active June 18, 2024 09:10
Event loop pseudocode
# the code is from https://www.youtube.com/watch?v=Y29SSOS4UOc
waiting = {}
topics.each do |topic|
Worker do
io = connect
io.write(topic)
while response = io.read_nonblock
if response == :wait_readable
waiting[io] = Worker.current
@wuminzhe
wuminzhe / promise_monad.md
Created May 10, 2024 04:21 — forked from VictorTaelin/promise_monad.md
async/await is just the do-notation of the Promise monad

async/await is just the do-notation of the Promise monad

CertSimple just wrote a blog post arguing ES2017's async/await was the best thing to happen with JavaScript. I wholeheartedly agree.

In short, one of the (few?) good things about JavaScript used to be how well it handled asynchronous requests. This was mostly thanks to its Scheme-inherited implementation of functions and closures. That, though, was also one of its worst faults, because it led to the "callback hell", an seemingly unavoidable pattern that made highly asynchronous JS code almost unreadable. Many solutions attempted to solve that, but most failed. Promises almost did it, but failed too. Finally, async/await is here and, combined with Promises, it solves the problem for good. On this post, I'll explain why that is the case and trace a link between promises, async/await, the do-notation and monads.

First, let's illustrate the 3 styles by implementing

@wuminzhe
wuminzhe / contracts...abi_encode_packed.sol
Created April 3, 2024 14:46
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.17+commit.8df45f5f.js&optimize=false&runs=200&gist=
// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity 0.8.17;
import "hardhat/console.sol";
contract AbiEncodePacked {
function run() public pure {
uint8[] memory uint8Array = new uint8[](3);
uint8Array[0] = 1;
@wuminzhe
wuminzhe / StingBytesUint.sol
Last active May 21, 2023 06:35
Solidity: Sting Bytes Uint Convertion
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.8.2 <0.9.0;
import "github/GNSPS/solidity-bytes-utils/contracts/BytesLib.sol";
contract StingBytesUint {
// input: 0x6176616c616e636865
// return: true
@wuminzhe
wuminzhe / description.markdown
Created April 27, 2023 04:55 — forked from runemadsen/description.markdown
Reverse polymorphic associations in Rails

Polymorphic Associations reversed

It's pretty easy to do polymorphic associations in Rails: A Picture can belong to either a BlogPost or an Article. But what if you need the relationship the other way around? A Picture, a Text and a Video can belong to an Article, and that article can find all media by calling @article.media

This example shows how to create an ArticleElement join model that handles the polymorphic relationship. To add fields that are common to all polymorphic models, add fields to the join model.

@wuminzhe
wuminzhe / inert-key.sh
Created March 9, 2023 01:16
insert a session key
#!/bin/bash
SR_PHRASE="..." # Mnemonic Phrase
SR_PUB_KEY="..."
curl -H "Content-Type: application/json" \
--data '{ "jsonrpc":"2.0", "method":"author_insertKey", "params":["aura", "'"${SR_PHRASE}"'", "'"${SR_PUB_KEY}"'"],"id":1 }' \
"http://127.0.0.1:9933"
@wuminzhe
wuminzhe / vim-shortcuts.md
Created February 9, 2022 04:13 — forked from tuxfight3r/vim-shortcuts.md
VIM SHORTCUTS

VIM KEYBOARD SHORTCUTS

MOVEMENT

h        -   Move left
j        -   Move down
k        -   Move up
l        -   Move right
$        -   Move to end of line
0        -   Move to beginning of line (including whitespace)
#!/bin/bash
# rev4 - changes suggested by KownBash https://www.reddit.com/r/bash/comments/5cxfqw/i_wrote_a_simple_video_to_gif_bash_script_thought/da19gjz/
# Usage function, displays valid arguments
usage() { echo "Usage: $0 [-f <fps, defaults to 15>] [-w <width, defaults to 480] inputfile" 1>&2; exit 1; }
# Default variables
fps=15
width=480