Skip to content

Instantly share code, notes, and snippets.

View XUJiahua's full-sized avatar

许嘉华 XUJiahua

  • Shanghai, China
View GitHub Profile
/**
理论基础: https://en.wikipedia.org/wiki/Byte_serving
使用range header可以得到网络资源的一部分字节
*/
package main
import (
"net/http"
"fmt"
"os"
"io/ioutil"
@XUJiahua
XUJiahua / rules.conf
Created October 27, 2015 12:51 — forked from janlay/README.md
Yet another config for Surge.app (build 245+)
# This config file was created for myself (@janlay). You may want to add or remove some rules to make efficient use of the Internet.
# This file depends on the main.conf which defines your own proxy.
# Your main.conf will look like this:
# ---- START ----
# #!PROXY-OVERRIDE:rules.conf
# [Proxy]
# Proxy = https,server.address,port,username,password
# ---- END ----
#
@XUJiahua
XUJiahua / Communicator.h
Created November 3, 2015 07:51 — forked from rjungemann/Communicator.h
How to open a TCP socket in Objective-C
#import <Foundation/Foundation.h>
@interface Communicator : NSObject <NSStreamDelegate> {
@public
NSString *host;
int port;
}
- (void)setup;
@XUJiahua
XUJiahua / nginx.conf.default
Created February 2, 2016 08:55 — forked from nishantmodak/nginx.conf.default
Default Nginx Conf
#user nobody;
#Defines which Linux system user will own and run the Nginx server
worker_processes 1;
#Referes to single threaded process. Generally set to be equal to the number of CPUs or cores.
#error_log logs/error.log; #error_log logs/error.log notice;
#Specifies the file where server logs.
@XUJiahua
XUJiahua / golang-tls.md
Created March 9, 2016 03:23 — forked from denji/golang-tls.md
Simple Golang HTTPS/TLS Examples

Generated private key

openssl genrsa -out server.key 2048

To generate a certificate

openssl req -new -x509 -key server.key -out server.pem -days 3650

https

# http://www.scipy-lectures.org/intro/numpy/exercises.html
import numpy as np
# 1
a = np.linspace(1,15,15).reshape([3,5]).T
b = a[[1,3],:]
# 2
a = np.arange(25).reshape(5, 5)
b = np.array([1., 5, 10, 15, 20])
@XUJiahua
XUJiahua / Main.java
Created December 11, 2016 05:33
String GBK转ASCII数据丢失,建议用byte2hex, hex2byte的形式
import java.nio.charset.Charset;
public class Main {
public static void main(String[] args) {
String myString = "中文123abc";
byte pText[] = myString.getBytes(Charset.forName("GBK")); // 10 bytes 2个字节代表1个中文
byte pText2[] = myString.getBytes(Charset.forName("UTF-8")); // 12 bytes 3个字节代表1个中文
byte pText3[] = myString.getBytes(Charset.forName("ASCII")); // 8 bytes 1个字节代表1个中文,精度损失了
@XUJiahua
XUJiahua / push.go
Last active April 9, 2017 06:00
redis假连接问题
// push.go
package push
import (
"github.com/mediocregopher/radix.v2/pool"
)
func listenOnQueue() {
p, err := pool.NewCustom("tcp", "address", 5, queue.REDIS_CUSTOM_CONN_FACTORY)
@XUJiahua
XUJiahua / main.go
Last active May 2, 2017 02:47
Host Swagger API Doc
http.HandleFunc("/", SpecUIPage)
http.HandleFunc("/swagger.json", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Access-Control-Allow-Origin", "*")
// put swagger.json under current folder
http.ServeFile(w, r, "swagger.json")
})
func SpecUIPage(w http.ResponseWriter, r *http.Request) {
swaggerAddr := "http://" + r.Host + "/swagger.json"
@XUJiahua
XUJiahua / filter_log_before_3_month.py
Created September 18, 2017 03:20
ElasticSearch数据清理(保留90天)
from datetime import datetime
from time import mktime
import time
import sys
for line in sys.stdin:
try:
datestr =line.strip()[-10:]
dt = time.strptime(datestr, "%Y.%m.%d")
dt = datetime.fromtimestamp(mktime(dt))