Skip to content

Instantly share code, notes, and snippets.

@logzh
logzh / pre-commit.sh
Created August 18, 2020 07:09 — forked from radlinskii/pre-commit.sh
pre-commit git hook file for working in Go. Be sure to save this file in your repository as `.git/hooks/pre-commit` and give it right to execute e.g. with command `chmod +x .git/hooks/pre-commit`
#!/bin/sh
STAGED_GO_FILES=$(git diff --cached --name-only | grep ".go$")
if [[ "$STAGED_GO_FILES" = "" ]]; then
exit 0
fi
GOLINT=$GOPATH/bin/golint
GOIMPORTS=$GOPATH/bin/goimports
@logzh
logzh / 1111
Created February 19, 2020 01:27
1111
local redis_c = require "resty.redis"
local ok, new_tab = pcall(require, "table.new")
if not ok or type(new_tab) ~= "function" then
new_tab = function (narr, nrec) return {} end
end
local _M = new_tab(0, 155)
@logzh
logzh / html_for_international_calling coes.htm
Created June 26, 2018 09:48 — forked from andyj/html_for_international_calling coes.htm
HTML <select> international calling codes for each country
<!-- country codes (ISO 3166) and Dial codes. -->
<select name="countryCode" id="">
<option data-countryCode="GB" value="44" Selected>UK (+44)</option>
<option data-countryCode="US" value="1">USA (+1)</option>
<optgroup label="Other countries">
<option data-countryCode="DZ" value="213">Algeria (+213)</option>
<option data-countryCode="AD" value="376">Andorra (+376)</option>
<option data-countryCode="AO" value="244">Angola (+244)</option>
<option data-countryCode="AI" value="1264">Anguilla (+1264)</option>
<option data-countryCode="AG" value="1268">Antigua &amp; Barbuda (+1268)</option>
@logzh
logzh / main.go
Created January 17, 2018 07:28
Handling Database/ORM Connections W/ Iris
// method 1:
// using a middleware function to "inject" into the RequestContext a user value that is a
// struct containing application-level services (e.g orm/db).
package main
import "os"
import "fmt"
import "flag"
import "github.com/jinzhu/gorm"
import "github.com/kataras/iris"
@logzh
logzh / addEventListener
Created August 14, 2017 04:04
throttle
window.addEventListener('scroll', _.throttle(eventHandler, 200), false);
#!/bin/sh
# create self-signed server certificate:
read -p "Enter your domain [www.example.com]: " DOMAIN
echo "Create server key..."
openssl genrsa -des3 -out $DOMAIN.key 1024
@logzh
logzh / gist:9319c90841447144bf43c183862f5ccb
Created April 21, 2017 07:42 — forked from thomseddon/gist:3511330
AngularJS byte format filter
app.filter('bytes', function() {
return function(bytes, precision) {
if (isNaN(parseFloat(bytes)) || !isFinite(bytes)) return '-';
if (typeof precision === 'undefined') precision = 1;
var units = ['bytes', 'kB', 'MB', 'GB', 'TB', 'PB'],
number = Math.floor(Math.log(bytes) / Math.log(1024));
return (bytes / Math.pow(1024, Math.floor(number))).toFixed(precision) + ' ' + units[number];
}
});
# _*_ coding: utf-8 _*_
"""类型和运算----类型和运算----类型和运算----类型和运算----类型和运算----类型和运算----类型和运算----类型和运算----类型和运算----类型和运算----类型和运算"""
#-- 寻求帮助:
dir(obj) # 简单的列出对象obj所包含的方法名称,返回一个字符串列表
help(obj.func) # 查询obj.func的具体介绍和用法
#-- 测试类型的三种方法,推荐第三种
if type(L) == type([]): print("L is list")
@logzh
logzh / changeTitle.js
Created June 13, 2016 06:47
如何通过 js 修改微信浏览器的title?
var $body = $('body');
document.title = ‘title’
// hack在微信等webview中无法修改document.title的情况
var $iframe = $('<iframe src="/favicon.ico"></iframe>').on('load', function() {
setTimeout(function() {
$iframe.off('load').remove()
}, 0)
}).appendTo($body)
// https://www.zhihu.com/question/26228251