Skip to content

Instantly share code, notes, and snippets.

@syfun
syfun / pre-commit.sh
Last active December 26, 2019 08:25 — 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 --diff-filter=ACM | grep "\.go$")
if [[ "$STAGED_GO_FILES" = "" ]]; then
exit 0
fi
GOLINT=`which golint`
GOIMPORTS=`which GOIMPORTS`
@syfun
syfun / settings.py
Created June 1, 2019 02:49
django log config
LOG_LEVEL = 'DEBUG'
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'filters': {
'require_debug_false': {
'()': 'django.utils.log.RequireDebugFalse'
}
},
@syfun
syfun / urls.py
Last active June 2, 2019 01:50
add graphql-playground to graphene-django
# ...
urlpatterns = [
# ...
path('graphql', GraphQLView.as_view(playground=True))
]
@syfun
syfun / k8s-minikube.sh
Created December 30, 2018 06:24
Install k8s with minikube
#!/usr/bin/env bash
# pull image
docker pull syfun/kube-proxy:v1.12.4
docker pull syfun/kube-controller-manager:v1.12.4
docker pull syfun/pause:3.1
docker pull syfun/etcd:3.2.24
docker pull syfun/coredns:1.2.2
docker pull syfun/kube-apiserver:v1.12.4
docker pull syfun/kube-scheduler:v1.12.4
@syfun
syfun / tax.py
Created December 27, 2018 01:30
2019个税新算法
# 保留2位小数四舍五入
def round_two(value):
if isinstance(value, (int, float)):
return round(value, 2)
return value
# 校准
def calibrate(func):
def _calibrate(*args, **kwargs):
@syfun
syfun / gist:f75908989b0fd2d96825a08d0b844159
Created November 12, 2018 08:35
gin-solf-shutdown.go
package http
import (
"context"
"fmt"
"log"
"net/http"
"os"
"os/signal"
"time"
@syfun
syfun / heap.go
Created August 23, 2018 02:56
golang safe heap
package main
import (
"container/heap"
"sync"
)
// SafeHeap implement a concurrent safe heap.
type SafeHeap struct {
sync.RWMutex
@syfun
syfun / exec.py
Created August 19, 2018 01:40
python exec
script = """
a = 2
global d
d = {
"a": a
}
"""
def test():
@syfun
syfun / ssh-git-proxy.md
Last active July 30, 2018 06:28
ssh proxy

1. socks5: 1080

ssh -oProxyCommand="nc -x 127.0.0.1:1080 %h %p" ubuntu@192.168.1.2

2. alias

alias sshp="ssh -oProxyCommand=\"nc -x 127.0.0.1:1080 %h %p\""

3. add config, like for github

# ~/.ssh/config
@syfun
syfun / gitproxy.sh
Last active July 23, 2018 07:28
gitproxy set
#!/bin/sh
nc -X 5 -x 127.0.0.1:1080 "$@"