Skip to content

Instantly share code, notes, and snippets.

View DavadDi's full-sized avatar

DavadDi DavadDi

View GitHub Profile
#! /usr/bin/perl
#
# to test:
# 1) run this script with either "accept" or "select-accept" as the argument
# (the script listens to 127.0.0.1:12345)
# 2) telnet localhost 12345
# 3) if you see "accept failed", there is the thundering herd problem
#
#
use strict;
@DavadDi
DavadDi / iptables.sh
Created November 14, 2016 10:11 — forked from thomasfr/iptables.sh
iptable rules to allow outgoing DNS lookups, outgoing icmp (ping) requests, outgoing connections to configured package servers, outgoing connections to all ips on port 22, all incoming connections to port 22, 80 and 443 and everything on localhost
#!/bin/bash
IPT="/sbin/iptables"
# Server IP
SERVER_IP="$(ip addr show eth0 | grep 'inet ' | cut -f2 | awk '{ print $2}')"
# Your DNS servers you use: cat /etc/resolv.conf
DNS_SERVER="8.8.4.4 8.8.8.8"
# Allow connections to this package servers
@DavadDi
DavadDi / mgoExample.go
Created February 17, 2017 02:00 — forked from border/mgoExample.go
mgo example
package main
import (
"fmt"
"labix.org/v2/mgo"
"labix.org/v2/mgo/bson"
"time"
)
type Person struct {
import (
"encoding/base64"
"fmt"
"net/http"
)
type BasicAuthTransport struct {
Username string
Password string
}
@DavadDi
DavadDi / html_template.go
Created February 19, 2017 09:04
html_template.go
package main
import (
"html/template"
"os"
)
type Class struct {
Name string
Value int32
package test
import (
"sync"
"testing"
)
var m sync.Mutex
func call() {
@DavadDi
DavadDi / IsEmpty.go
Created March 22, 2017 09:15
用于检查一个变量是否为空,支持指针类型
func IsEmpty(v interface{}) bool {
rt := reflect.TypeOf(v)
if rt.Kind() == reflect.Ptr {
rt = rt.Elem()
return reflect.DeepEqual(v, reflect.New(rt).Interface())
}
return reflect.DeepEqual(v, reflect.Zero(rt).Interface())
}
@DavadDi
DavadDi / main.go
Created March 29, 2017 08:15
get_ip
package main
import (
"errors"
"fmt"
"net"
)
func main() {
#!/bin/bash
#
# Generates client and server certificates used to enable HTTPS
# remote authentication to a Docker daemon.
#
# See http://docs.docker.com/articles/https/
#
# To start the Docker Daemon:
#
# sudo docker -d \
package main
import (
"crypto/tls"
"net/http"
"time"
"log"
)