Skip to content

Instantly share code, notes, and snippets.

@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++ {
@fangdingjun
fangdingjun / nqueen_recusive.go
Created October 14, 2015 03:01
N queens problem implement code in golang
package main
import (
"fmt"
"log"
"os"
"strconv"
)
const (
@fangdingjun
fangdingjun / limit_webbench.sh
Last active November 27, 2015 07:03
使用iptables防止webbench工具的攻击
#限制单个ip的tcp的并发连接数为30
iptables -A INPUT -p tcp -m connlimit --connlimit-above 30 -j DROP
#限制连接web服务的连接速度, 单个ip在10s内只允许建立10个新连接
iptables -A INPUT -p tcp -m multiport --dport 80,443 -m state --state NEW --set --name web
iptables -A INPUT -p tcp -m multiport --dport 80,443 -m state --state NEW --update --name web \
--hitcount 10 --seconds 10 -j REJECT
@fangdingjun
fangdingjun / stunnel.js
Created May 20, 2015 09:55
The nodejs version of stunnel
var net=require("net");
var tls = require("tls");
/* listen address and port */
var listen_host = "0.0.0.0";
var listen_port = 8080;
/* the upstream https servers */
var servers = [
{host: "a.example.com",port:18080},
@fangdingjun
fangdingjun / pcs_to_aria2.py
Created May 15, 2015 06:45
使用aria2替换bypy的下载
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import urllib2
import urllib
import json
import xmlrpclib
class PcsLib(object):
def __init__(self, access_token, timeout = 10, basepath= "/apps/bypy"):