Skip to content

Instantly share code, notes, and snippets.

View zhangyuchi's full-sized avatar

Terrell Franzman zhangyuchi

View GitHub Profile
@zhangyuchi
zhangyuchi / generate_cert.go
Created March 29, 2017 07:51
生成证书generate_cert.go
1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 // +build ignore
6
7 // Generate a self-signed X.509 certificate for a TLS server. Outputs to
8 // 'cert.pem' and 'key.pem' and will overwrite existing files.
9
10 package main
@zhangyuchi
zhangyuchi / golang-tls.md
Created March 15, 2017 08:15 — forked from denji/golang-tls.md
Simple Golang HTTPS/TLS Examples
Generate private key (.key)
# Key considerations for algorithm "RSA" ≥ 2048-bit
openssl genrsa -out server.key 2048

# Key considerations for algorithm "ECDSA" ≥ secp384r1
# List ECDSA the supported curves (openssl ecparam -list_curves)
openssl ecparam -genkey -name secp384r1 -out server.key
@zhangyuchi
zhangyuchi / xmlorigencode.go
Created March 7, 2017 09:25
xml dont escape 回车换行
package main
import (
"encoding/xml"
"fmt"
)
type MyXML struct {
XMLName xml.Name `xml:"item"`
Content interface{} `xml:"content"`
@zhangyuchi
zhangyuchi / nginx.conf
Created February 22, 2017 02:41
nginx.conf rewrite exsample
location ~ ^/icomet/.* {
rewrite ^/icomet/(.*) /$1 break;
proxy_read_timeout 60;
proxy_connect_timeout 60;
proxy_buffering off;
proxy_pass http://127.0.0.1:8100;
}
auto deleter = [](FILE* f) {fclose(f);};
std::unique_ptr<FILE, decltype(deleter)> p(fopen("1.txt", "w"),
deleter);
@zhangyuchi
zhangyuchi / deviceid.java
Last active August 9, 2016 05:19
获取设备唯一id
public static AccountInfo getAccInfo(Context context, String jid) {
synchronized (acclock) {
if (AccInfo == null) {
final TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
final String tmDevice, tmSerial, androidId;
tmDevice = "" + tm.getDeviceId();
tmSerial = "" + tm.getSimSerialNumber();
androidId = "" + android.provider.Settings.Secure.getString(context.getContentResolver(), android.provider.Settings.Secure.ANDROID_ID);
UUID deviceUuid = new UUID(androidId.hashCode(), ((long) tmDevice.hashCode() << 32) | tmSerial.hashCode());
@Override
public void onResume() {
super.onResume();
LocalBroadcastManager manager = LocalBroadcastManager.getInstance(getActivity());
IntentFilter filter = new IntentFilter(ACTION_EXAMPLE);
manager.registerReceiver(this.receiver, filter);
}
@zhangyuchi
zhangyuchi / getdir.sh
Created July 25, 2016 09:00
当执行一个脚本时,在脚本中获取脚本所在的路径 From http://stackoverflow.com/questions/59895/can-a-bash-script-tell-which-directory-it-is-stored-in
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
SOURCE="$(readlink "$SOURCE")"
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
#如果执行脚本不是软链接,则只需这一行即可
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
@zhangyuchi
zhangyuchi / ontimer.java
Created July 25, 2016 03:34
android 定时器实现
//一、采用Handle与线程的sleep(long)方法
class Timer1{
//1. 定义一个Handler类,用于处理接受到的Message。
Handler handler = new Handler() {
public void handleMessage(Message msg) {
// 要做的事情
super.handleMessage(msg);
}
};
func getActiveUserInzone(appid uint16, zone uint16) ([]*session.UserSession, error) {
var resp []*session.UserSession
keyname := fmt.Sprintf(userStatSetKey, appid, zone)
userids, err := SessionPool.Call(getSessionAddr(keyname)).SMEMBERS(keyname)
if err != nil {
return resp, errors.New(keyname + ":" + err.Error())
}