Skip to content

Instantly share code, notes, and snippets.

@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++
@fangdingjun
fangdingjun / dutch_nation_flag.go
Last active October 14, 2015 03:13
This code implement the Dutch Nation Flag problem, use three-way partition algorithms
package main
import (
"fmt"
)
var flags = []int{1,2,3,3,2,1,1,2,3}
func main() {
var i, j, n int
@fangdingjun
fangdingjun / mouse_in_maze.go
Created October 14, 2015 03:09
This code implement the Mouse In a Maze problem
package main
import (
"fmt"
)
var maze [][]int = [][]int{
{2, 2, 2, 2, 2, 2, 2, 2, 2, 2},
{2, 0, 0, 0, 2, 0, 0, 0, 2, 2},
{2, 0, 2, 0, 2, 0, 2, 2, 0, 2},
@fangdingjun
fangdingjun / pascal_triangle.go
Last active October 14, 2015 03:07
This code print a Pascal triangle
package main
import (
"fmt"
)
func main() {
var N = 12
for i := 0; i <= N; i++ {
for j := 0; j <= i; j++ {