Skip to content

Instantly share code, notes, and snippets.

View isword123's full-sized avatar

Zhijian Xia isword123

  • Shanghai
View GitHub Profile
@isword123
isword123 / method-patch.go
Created December 19, 2020 16:46
Golang unittest patch for method by gomonkey example
func TestClient_RenameFile(t *testing.T) {
// 定义类型
var sc *stdsftp.Client
// 给方法打桩,相当于使用反射将对应的方法实现给替换了
patch := gomonkey.ApplyMethod(reflect.TypeOf(sc), "Rename", func(_ *stdsftp.Client, _, _ string) error {
return errors.New(" some err")
})
// 确保执行完会重置回去
defer patch.Reset()
@isword123
isword123 / iterate.go
Created February 27, 2020 16:07
Iterate tow array to find corresponding part
package main
import "fmt"
import "time"
func main() {
tLen(10)
tLen(100)
tLen(1000)
tLen(10000)
@isword123
isword123 / peak_clip.go
Created July 15, 2019 08:18
这个是用来削峰和阻止请求穿透的代码
package models
import (
"container/list"
"git.vpgame.cn/sh-team/das-ag-dota2/utils"
"go.uber.org/zap"
"sync"
"time"
)
@isword123
isword123 / install.sh
Last active September 26, 2017 01:53
vps init scripts for shadowsocks
#!/bin/bash
# ============================================================
# Filename: install.sh
# Created By: Geoffrey Xia
# Created On: 2017-09-25 20:53:43
# ============================================================
yum -y install python-pip vim
pip install --upgrade pip
pip install shadowsocks
mkdir -p /data
@isword123
isword123 / CMakeLists.txt
Created August 15, 2017 10:19
cmake config example
cmake_minimum_required(VERSION 2.8)
project(testapp)
set(CMAKE_BUILD_TYPE Debug CACHE STRING "set build type to debug")
set(CMAKE_VERBOSE_MAKEFILE true)
add_custom_command(
OUTPUT testapp
@isword123
isword123 / gist:71f144d9bd7a24215972b454ff2495f0
Created January 17, 2017 09:24 — forked from evildmp/gist:3094281
Set up Django, nginx and uwsgi

This document has now been incorporated into the uWSGI documentation:

http://uwsgi-docs.readthedocs.org/en/latest/tutorials/Django_and_nginx.html

Set up Django, nginx and uwsgi

Steps with explanations to set up a server using:

@isword123
isword123 / js_param_validation.js
Created June 19, 2016 09:29
For js params validation; Useful for API params validation or else
var _ = require('lodash');
function validateString(val, rule) {
// 判断是不是 String
if (!_.isString(val)) {
return 'INVALID_STRING';
}
// 如果有正则,判断是否符合正则表达式
if (rule.regex && !rule.regex.test(val)) {
@isword123
isword123 / vim_restore.sh
Last active August 29, 2015 14:18
Scripts to archive and restore vim configrations
#!/bin/bash
#set -x
# check input parameter first
TAR_REL_PATH=''
if [ $# -eq 1 ] ; then
TAR_REL_PATH="$1"
else
echo "Wrong parameter"
exit 2
@isword123
isword123 / js_condition_load
Last active December 31, 2015 19:59
A piece of code to load JS and CSS differently for desktop and mobile devices.
(function () {
var usingMobile = false,
userAgent = window.navigator.userAgent;
if (/Mobile|iP(hone|od|ad)|Android|BlackBerry|IEMobile|Kindle|NetFront|Silk-Accelerated|(hpw|web)OS|Fennec|Minimo|Opera M(obi|ini)|Blazer|Dolfin|Dolphin|Skyfire|Zune/.test(userAgent)) {
usingMobile = !/iPad/.test(userAgent); //specail for iPad
}
var sourceData = usingMobile ? RESOURCES.mobile : RESOURCES.desktop,
head = document.getElementsByTagName('head')[0];