Skip to content

Instantly share code, notes, and snippets.

View leozc's full-sized avatar

Leo Liang leozc

View GitHub Profile
@leozc
leozc / btc_addr_type.py
Created February 25, 2024 19:32
BTC address type
import re
def identify_btc_address_type(address):
# P2PKH: Starts with '1'
if address.startswith('1'):
return 'P2PKH'
# P2SH: Starts with '3'
elif address.startswith('3'):
return 'P2SH'
# P2WPKH and P2TR: Start with 'bc1'
@leozc
leozc / index.js
Last active May 24, 2023 04:43
Verify data consistency of Block and Transaction of a Web3 Provider
const Web3 = require('web3');
// Connect to Ethereum node (use your own provider URL here)
const web3 = new Web3('https://xxx.quiknode.pro/xxx/');
const web3s = new Web3(new Web3.providers.WebsocketProvider('wss://xxx.quiknode.pro/yyy/'));
web3s.eth.subscribe('newBlockHeaders', async (error, blockHeader) => {
if (error) {
console.error(`Error: ${error}`);
return;
def testA ():
for i in range(3):
for p in range(i,3):
# print tuple of i and p
print((i,p))
#time to run the function
def sortA (array):
for i in range(len(array)):
//express basic authentication example
const app = require('express')()
const basicAuth = require('express-basic-auth')
app.use(basicAuth({
users: { 'admin': '123456' },
challenge: true,
realm: 'xxxx',
unauthorizedResponse: getUnauthorizedResponse
@leozc
leozc / README.txt
Created December 28, 2021 23:33
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.7+commit.e28d00a7.js&optimize=false&runs=200&gist=
REMIX EXAMPLE PROJECT
Remix example project is present when Remix loads very first time or there are no files existing in the File Explorer.
It contains 3 directories:
1. 'contracts': Holds three contracts with different complexity level, denoted with number prefix in file name.
2. 'scripts': Holds two scripts to deploy a contract. It is explained below.
3. 'tests': Contains one test file for 'Ballot' contract with unit tests in Solidity.
SCRIPTS
@leozc
leozc / gist:72397f06fca47d2aace79f4dbfc86679
Created May 3, 2020 12:19
repl implementation for python in Bazel
https://github.com/bazelbuild/bazel/blob/master/src/main/java/com/google/devtools/build/lib/bazel/rules/python/python_stub_template.txt#L350
add
```
import code
code.interact()
```
@leozc
leozc / FutureCache.java
Last active September 11, 2018 02:15
FutureCache For Java CompletableFuture - enable enqueue a long running future task into the Future pool, and provide an interface to store and fetch the long running results
package com.leozc.FutureCache;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ThreadLocalRandom;
import java.util.function.BiConsumer;
import java.util.function.BiFunction;
import java.util.function.Function;
@leozc
leozc / gen.sh
Created January 2, 2018 23:29
Generate random ASCII file and add to git
TIME=time
for (( i=1; i<=10000000; i++))
do
filename=`cat /dev/urandom | env LC_CTYPE=C tr -cd 'a-f0-9' | head -c 32`
folder=`cat /dev/urandom | env LC_CTYPE=C tr -cd 'a-f0-9' | head -c 2`
mkdir -p $folder
base64 /dev/urandom | head -c 102400 > $folder/$filename.txt
git add $folder/$filename.txt
$TIME -o stat.txt -a -f "%U|%S" git commit . -m"for $filename.txt"
echo $i
#!/bin/bash
#brew install gun-time for Mac
for (( i=1; i<=200000; i++))
do
filename=`cat /dev/urandom | env LC_CTYPE=C tr -cd 'a-f0-9' | head -c 32`
folder=`cat /dev/urandom | env LC_CTYPE=C tr -cd 'a-f0-9' | head -c 2`
mkdir -p $folder
base64 /dev/urandom | head -c 100000 > $folder/$filename.txt
git add $folder/$filename.txt
@leozc
leozc / dockerfile
Last active January 30, 2017 22:23
FROM phusion/baseimage:latest
LABEL com.leozc.version="0.0.2-beta"
MAINTAINER Leo Liang
RUN apt-get update && apt-get install -y libxml2-dev mercurial libxslt1-dev gettext libncurses-dev libreadline-dev libpq-dev libgeos++-dev libtiff5-dev libjpeg8-dev zlib1g-dev libfreetype6-dev liblcms2-dev libwebp-dev tcl8.6-dev tk8.6-dev python-tk g++ python-setuptools python libffi-dev python-dev curl gcc openjdk-8-jdk scala git telnet \
&& easy_install pip && pip install --upgrade pip && mkdir /pants && cd /pants && curl -L -O https://pantsbuild.github.io/setup/pants && chmod +x pants && touch pants.ini && ./pants -V
pip install virtualenv