Skip to content

Instantly share code, notes, and snippets.

@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
@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 / 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 / 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 / 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 / socks-server.py
Created December 4, 2015 09:02
a socks server implemented use twisted, support socks4/4a, socks5 protocol, only connect command support
#!python
"""
a socks server implemented by twisted
support socks4/4a, socks5 protocol
only support CONNECT command
#
"""
from twisted.internet.protocol import Protocol
@fangdingjun
fangdingjun / inet_pton.c
Created October 29, 2015 03:57
inet_pton, inet_ntop implements for windowns
#ifdef WIN32
#include <winsock2.h>
#include <Ws2tcpip.h>
#include <string.h>
#include <stdint.h>
#include <stdio.h>
int inet_pton4(const char *src, char *dst);
int inet_pton6(const char *src, char *dst);
int inet_pton(int af, const char *src, char *dst)
@fangdingjun
fangdingjun / tower_of_hanoi.go
Created October 14, 2015 03:19
Tower of Hanio problem code in golang
package main
import (
"fmt"
"os"
"strconv"
)
var count int
func hanoi(n int, a, b, c string){
if n == 1{
count++