2022/03/06

BlockChain 相关电子书

@copyright of Sam Chadwick  - https://thehub.thomsonreuters.com/groups/bitcoin/blog/2017/09/10/blockchain-paper


Blockchain Papers

A curated list of blockchain-related academic papers.

General

Consensus

Cryptography

Block generation parameters

Stake

Attacks

Wallets

Crime

Economics

Marketplaces and Trust

Privacy

Sidechains, Higher layer and Scalability

Fungibility

Network

Smart Contracts

Formal Methods

Proof of work

Survey, Sociological & Anthropological

2020/05/05

用 Visual C++ Build Tool 编译 Lua 5.3 源代码

Windows 下用 Microsoft Visual C++ Build Tool 来编译 Lua 5.3 源代码 其实很简单。
  1. 打开一个编译命令行窗口
  2. 解开 Lua 5.3.x 的源代码到 C:\Lua53
  3. 进入src目录, 执行下面的命令
REM cd src
del *.o *.obj *.res
cl /MD /O2 /c /DLUA_BUILD_AS_DLL *.c
ren lua.obj lua.o
ren luac.obj luac.o
IF EXIST wmain.obj ren wmain.obj wmain.o
link /DLL /OUT:lua53.dll *.obj
link /OUT:lua53.exe lua.o lua53.lib
lib /OUT:lua53a.lib *.obj
link /OUT:luac.exe luac.o lua53a.lib
IF NOT EXIST wlua.rc goto DEPLOY
rc wlua.rc
link /subsystem:windows /OUT:lua53w.exe wmain.o lua.o wlua.res lua53.lib
del /y *.o *.obj *.res
:DEPLOY
move /y *.exe ..
mkdir /y ..\lib
move /y *.lib ..\lib\

2020/01/28

利用 socat 搭建一个简易 VPN 的服务端脚本

Server Side - Bash

#!/bin/bash

[[ $# -lt 3 ]] && echo "Usage: $0 tunID udp-port remote.lan.ip/net" && exit 255

TUN_ID=$(echo $1 | tr -d '[a-zA-Z]+')
[[ "$TUN_ID" != "$(( $TUN_ID / 1 ))" ]] && echo "tunID:\"$1\" must suffix with a number!" && exit 254

## Debug
TUN_DEV=$1
LOCAL_INT="192.168.2.$(( $TUN_ID % 64 * 4 + 1 ))/30"
REMOTE_INT="192.168.2.$(( $TUN_ID % 64 * 4 + 2 ))"
UDP_PORT=$2
REMOTE_LAN=$3

# kill exists
pkill -f "tun-name=$TUN_DEV"

socat tun:$LOCAL_INT,tun-name=$TUN_DEV,up udp4-listen:$UDP_PORT,fork &
sleep 3

# tunX options
ip link set $TUN_DEV mtu 1452

shift 2

# Add all the given subnet to SNAT
for net in $*;do 
  ip route add $net dev $TUN_DEV
  iptables -t nat -I POSTROUTING -s $net -j SNAT --to-source $(hostname -i) 
done

Client Side - BusyBox

#!/bin/sh

[[ $# -lt 2 ]] && echo "Usage: $0 tunID remote.ip.udp:port" && exit 255

TUN_ID=$(echo $1 | tr -d '[A-Za-z]+')
[[ "$TUN_ID" != "$(( $TUN_ID / 1 ))" ]] && echo "tunID:\"$1\" must suffix with a number!" && exit 254

TUN_DEV=$1
LOCAL_INT="192.168.2.$(( $TUN_ID % 64 * 4 + 2 ))/30"
REMOTE_INT="192.168.2.$(( $TUN_ID % 64 * 4 + 1 ))"
REMOTE_UDP=$2

kill $(ps | grep tun-name=$TUN_DEV | cut -d ' ' -f 1) 2>/dev/null

socat tun:$LOCAL_INT,tun-name=$TUN_DEV,up udp4-connect:$REMOTE_UDP &
sleep 3

# MTU
ip link set $TUN_DEV mtu 1452

# IP Route2
ip route add default via $REMOTE_INT table $TUN_DEV
ip rule add from $REMOTE_INT table $TUN_DEV


2019/12/28

如何在 OpenWRT 下产生随机数:

MY_RANDOM=$(head /dev/urandom | tr -dc "0123456789" | head -c4)

如果是的Bash, Zsh, 或者BusyBox启用了RANDOM, 是可以直接使用内置的 $RANDOM 变量

MY_RANDOM=$RANDOM

如果需要限定数字的大小,可以使用 Shell 内置的运算表达式 $(( expr ))

MY_VAL=$(( MY_RANDOM % 200 + 1 ))

2019/03/07

拼音加加双拼输入方案

为Windows 10 添加拼音加加双拼输入方案

把下面的内容保存为 ppp.reg, 然后双击导入注册表,Pinyin PlusPlus双拼输入方案就有了。

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Microsoft\InputMethod\Settings\CHS]
"UserDefinedDoublePinyinScheme0"="Pinyin PlusPlus*1*^*uivsfgdwrtqbjhkmlqynypbxchxvzovx"

2018/09/03

vimrc 备份

  1 "" Let's start VIM journey
  2 set nocompatible
  3 
  4 "" Include default settings
  5 "source $VIMRUNTIME/vimrc_example.vim
  6 "source $VIMRUNTIME/gvimrc_example.vim
  7 
  8 "" shell settings
  9 let $PATH="$HOME/bin;C:/msys64/usr/bin;C:/msys64/mingw64/bin;C:/Windows;C:/Windows/System32"
 10 set shell=bash.exe
 11 set shellslash
 12 
 13 "" Don't need ugly files
 14 set backupdir=c:/temp/vim/backup
 15 set directory=c:/temp/vim/swap
 16 set nobackup
 17 set swapfile
 18 set undodir=c:/temp/vim/undo
 19 set undofile
 20 set writebackup
 21 
 22 "" UI settings
 23 set cmdheight=2
 24 "set guioptions-=t
 25 set laststatus=2
 26 set lazyredraw
 27 set lines=35 columns=160
 28 set number
 29 set renderoptions=type:directx
 30 set ruler
 31 set showcmd
 32 set wildmenu
 33 
 34 "colorscheme torte
 35 colorscheme koehler
 36 
 37 "" Tab/Space related
 38 set expandtab
 39 set shiftwidth=4
 40 set softtabstop=4
 41 set tabstop=4
 42 
 43 "" IME settings
 44 if has("multi_byte")
 45   set encoding=utf-8
 46   "let &termencoding = &encoding
 47   set termencoding=unicode
 48   " Set default encoding as UTF-8 with BOM
 49   setglobal fileencoding=utf-8 "bomb "bomb introduce problem for *nix
 50   set fileencodings=ucs-bom,utf-8,gb18030,cp936,cp950,latin1
 51   " Walkaround the encoding problem for fenc=utf-8 && enc=ucs-2
 52   augroup i18n
 53     autocmd!
 54     autocmd BufReadPost * if &fileencoding == "utf-8" | let &encoding = &fileencoding | endif
 55   augroup END
 56 endif
 57 
 58 "" Enable the Chinese characters
 59 "set guifont=Fira_Code:h11:cANSI,NSimSun:h12:cGB2312
 60 set guifont=Iosevka:h12:cANSI:qDRAFT ",SimHei:h12:cGB2312:qDRAFT
 61 "set guifontwide=SimHei:h12:cGB2312
 62 "set guifontwide=Microsoft_YaHei:h12:cGB2312
 63 set guifontwide=Noto_Mono:h12:cGB2312
 64 
 65 "" IME
 66 if has('multi_byte_ime')
 67   "未开启IME时光标背景色
 68   hi Cursor guifg=bg guibg=Orange gui=NONE
 69   "开启IME时光标背景色
 70   hi CursorIM guifg=NONE guibg=Skyblue gui=NONE
 71   " 关闭Vim的自动切换IME输入法(插入模式和检索模式)
 72   set iminsert=0 imsearch=0
 73   " 插入模式输入法状态未被记录时,默认关闭IME
 74   inoremap <silent> <ESC> <ESC>:set iminsert=0<CR>
 75 endif
 76 
 77 "" Useful Plugins
 78 packadd vim-fugitive
 79 "" Plugin - airline
 80 let g:airline_theme='solarized'
 81 let g:airline_detect_iminsert=1
 82 let g:airline_highlighting_cache = 1
 83 let g:airline_powerline_fonts = 1
 84 let g:airline#extensions#tabline#enabled = 1
 85 packadd vim-airline
 86 packadd vim-airline-themes
 87 
 88 "" Plugins
 89 packadd! emmet-vim
 90 packadd! ctrlp.vim
 91 packadd! nerdtree
 92 
 93 "" Key Maps
 94 "" display the syntax name under the cursor
 95 map <F12>   :echo synIDattr(synIDtrans(synID(line("."), col("."), 1)), "name")<CR>
 96 "" We can navigate the list by using the <F3> and <S-F3>
 97 map <F3>    :cnext<CR>
 98 map <S-F3>  :cprevious<CR>
 99 "" Let's help the tab navigation a little
100 map <F4>    :try\|:next\|finish\|catch\|:tabnext\|endtry<CR>
101 map <S-F4>  :bdelete<CR>
102 "" Tlist and NERDTree
103 map <F5>    :NERDTreeToggle<CR>
104 map <S-F5>  :Tlist<CR>
105 set tags=./tags,../tags,../../tags,../../../tags
106 "" open Terminal
107 tmap <F9>   <C-W>:$tabnew +:term<CR><C-W>o
108 map <F9>    :$tabnew +:term<CR><C-W>o
109 
110 

BlockChain 相关电子书

@copyright of Sam Chadwick   - https://thehub.thomsonreuters.com/groups/bitcoin/blog/2017/09/10/blockchain-paper Blockchain Papers A c...