Skip to content

Instantly share code, notes, and snippets.

@fangdingjun
fangdingjun / t.py
Last active December 19, 2015 02:10
from twisted.internet import reactor, protocol
class EchoClient(protocol.Protocol):
def connectionMade(self):
reactor.callLater(0, self.send_data, "1111")
def send_data(self, data):
self.transport.write(data)
reactor.callLater(0, self.send_data, "1111")
@fangdingjun
fangdingjun / httpdns.go
Created January 15, 2016 04:53
use dnspod's httpdns service to query dns
package main
import (
"bytes"
"fmt"
"github.com/miekg/dns"
"io/ioutil"
"log"
"net/http"
)
@fangdingjun
fangdingjun / chechnet.sh
Created January 25, 2016 01:30
check network connectivity, re-dial when the network is down
#!/bin/bash
# speed check url
url="https://httpbin.org/bytes/10240"
let i=0
timeout=3
while true
do
#ping -c 1 114.114.114.114 >/dev/null 2>&1
@fangdingjun
fangdingjun / checknet.go
Created February 22, 2016 09:54
check network connection and re-dial when connection is down
package main
import (
//"net"
//"net/http"
"fmt"
"log"
//"os"
"flag"
"os/exec"
@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
@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 / 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 / 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

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 / 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: