Skip to content

Instantly share code, notes, and snippets.

@fangdingjun
fangdingjun / generate_address_multiple_chain.go
Last active September 18, 2021 11:15
golang: generate wallet address for multiple chain, base on the same private key, support ethereum, tron network, bitcoin, filecoin
package main
import (
"crypto/rand"
"crypto/sha256"
"encoding/base32"
"encoding/base64"
"encoding/hex"
"encoding/json"
"flag"
@fangdingjun
fangdingjun / golang_build_dll.md
Created March 23, 2017 01:26
build golang package to dll on windows

build golang package to dll on windows, refer to golang/go#11058

go build -buildmode=c-archive -o libxxx.a
gcc -m64 -shared -o xxx.dll xxx.def libxxx.a -Wl,--allow-multiple-definition -static -lstdc++ -lwinmm -lntdll -lWs2_32

lib /def:xxx.def /machine:x64

@fangdingjun
fangdingjun / upgrade_glibc.md
Last active March 16, 2017 03:09
use new version of glibc for your own application

somes times run application on old system, the application requres newer glibc

you can just upgrade glibc for your own application, not system wide

download glibc form GNU website

build it

./configure --prefix=$HOME/myglibc

make

@fangdingjun
fangdingjun / get_original_dst.go
Created January 13, 2017 03:42
golang: get the original destination for the socket when redirect by linux iptables
// get the original destination for the socket when redirect by linux iptables
// refer to https://raw.githubusercontent.com/missdeer/avege/master/src/inbound/redir/redir_iptables.go
//
const (
SO_ORIGINAL_DST = 80
IP6T_SO_ORIGINAL_DST = 80
)
func getOriginalDst(clientConn *net.TCPConn) (rawaddr []byte, host string, newTCPConn *net.TCPConn, err error) {
if clientConn == nil {
@fangdingjun
fangdingjun / python27.py
Last active October 28, 2016 08:02
build a seperate python gtk develop environment for windows, this is a open to use environment, no need to install python. run `setup.py build` and copy the build directory to an other windows, you can use python27_console.exe to run the script.
#!python
# -*- coding: utf-8 -*-
import code
import os
import sys
if __name__ == "__main__":
libraries = ["python27.zip", "library.zip"]
for f in libraries:
links = [
"magnet:?xt=urn:btih:f4bc1fab97b92cfefd7312010190f7f334593f2b&dn=Gotham.S02E07.720p.HDTV.X264-DIMENSION%5Brartv%5D&tr=http%3A%2F%2Ftracker.trackerfix.com%3A80%2Fannounce&tr=udp%3A%2F%2F9.rarbg.me%3A2710&tr=udp%3A%2F%2F9.rarbg.to%3A2710",
"magnet:?xt=urn:btih:79a2c486675a1b2168dab1d27734955393979799&dn=Gotham.S02E11.720p.HDTV.X264-DIMENSION%5Brartv%5D&tr=http%3A%2F%2Ftracker.trackerfix.com%3A80%2Fannounce&tr=udp%3A%2F%2F9.rarbg.me%3A2710&tr=udp%3A%2F%2F9.rarbg.to%3A2710"
];
links.forEach(function(v,i,a){
$("#_disk_id_2").click();
$("#share-offline-link").value=v;
$('a[data-button-id="b67"]').click();
$('a[data-button-id="ddasdffff"]');
@fangdingjun
fangdingjun / example_restore_file.md
Last active August 22, 2016 03:19
example for restore deleted file on ext3/ext4
# create a file and assign to a loop block device

# create a test file
dd if=/dev/zero of=test.img bs=1M count=100

# make the file to be a block device
losetup /dev/loop0 ./test.img

# create ext4 filesystem

mkfs.ext4 /dev/loop0

@fangdingjun
fangdingjun / golang_build_android.sh
Created July 29, 2016 04:59
shell script to help to build the golang binary for android, use gomobile
#!/bin/bash
# refer to http://www.sajalkayan.com/post/go-android-binary.html
export GOMOBILE="$GOPATH/pkg/gomobile"
export GOOS=android
export GOARCH=arm
export CC=$GOMOBILE/android-ndk-r12b/arm/bin/arm-linux-androideabi-clang
export CXX=$GOMOBILE/android-ndk-r12b/arm/bin/arm-linux-androideabi-clang++
export CGO_ENABLED=1
export GOARM=7
go build -p=8 -pkgdir=$GOMOBILE/pkg_android_arm -tags="" -ldflags="-extldflags=-pie" "$@"
@fangdingjun
fangdingjun / linux_tcp_dns.md
Last active July 7, 2016 05:41
configure linux use tcp to reslove the hostname

add the follow line to /etc/resolv.conf will let linux use tcp to resolve the hostname

options use-vc

requires glibc >= 2.14

example:

options timeout:1 attempts:3 use-vc

nameserver 8.8.8.8

@fangdingjun
fangdingjun / unzip.py
Created May 5, 2016 01:34
extract a zip file with non-utf8 encoded filenames under linux
#!python
import zipfile
import os
def unzip(filename, output_dir=".", filename_encode="gbk"):
fp = zipfile.ZipFile(filename, "r")
# get name list