Skip to content

Instantly share code, notes, and snippets.

@smallyunet
smallyunet / dag_ordering.py
Last active May 5, 2022 04:30
Implement topological sorting by Kahn's algorithm
# Implement topological sorting by Kahn's algorithm
# Reference: https://youtu.be/guJkbg-gnLM
def ordering(input):
output = []
queue = []
incoming = {}
for k, v in input.items():
if k not in incoming:
@smallyunet
smallyunet / getPrivateKey.js
Last active February 17, 2022 10:15
Get private key from keystore file of Ethereum
/**
* 1. Run `npm install keythereum` in an empty directory.
* 2. Save this script to a file named `main.js`.
* 3. Run `node main.js` in the same directory.
*/
let keythereum = require("keythereum");
// the keystore address
let address = "0x792E47E160f4eE67c17714Df1c92f678640E0E4c";
@smallyunet
smallyunet / Mapping.sol
Created February 8, 2022 06:46
Solidity iterable mapping template
//SPDX-License-Identifier: Unlicense
pragma solidity ^0.8.0;
import "hardhat/console.sol";
struct IndexValue {
uint256 keyIndex;
string value;
}
@smallyunet
smallyunet / js-proxy-google.js
Created October 14, 2021 06:16
proxy google.com use cloudflare workers
const upstream = 'www.google.com'
addEventListener('fetch', event => {
event.respondWith(fetchAndApply(event.request));
})
async function fetchAndApply(request) {
const region = request.headers.get('cf-ipcountry').toUpperCase();
const ip_address = request.headers.get('cf-connecting-ip');
chrome-bookmark-archive
daily-issue.bookmark
sonatype.bookmark
docker-shortcut
@smallyunet
smallyunet / generatorIdNumber.js
Created May 15, 2020 07:13
身份证号码校验位的校验算法
// 验证身份证号码的算法
// 可以根据规则找出校验位合规的身份证号
let generatorIdNumber = (x) => {
// 目前是 16位 + 2位
let str = '1111111111111111' + x
// 字符值
let a = str.split('').map(i => parseInt(i))
// 权重银子
@smallyunet
smallyunet / quickSort.py
Last active March 25, 2020 12:08
quick sort by python
"""
@desc quick sort python version
@param List arr
@return List arr
"""
def quickSort(arr, left=None, right=None):
# default parameter
if left == None or right == None:
left = 0