Skip to content

Instantly share code, notes, and snippets.

View tossmilestone's full-sized avatar
:octocat:
Coding life

Shaw Ho tossmilestone

:octocat:
Coding life
  • Alauda
  • Nanjing, China
View GitHub Profile
@tossmilestone
tossmilestone / agnoster.theme.patch
Created August 21, 2018 14:19
Next line patched for oh-my-zsh agnoster theme
diff --git a/themes/agnoster.zsh-theme b/themes/agnoster.zsh-theme
index d1a69c56..2fafdb41 100644
--- a/themes/agnoster.zsh-theme
+++ b/themes/agnoster.zsh-theme
@@ -196,7 +196,7 @@ prompt_hg() {
# Dir: current working directory
prompt_dir() {
- prompt_segment blue $CURRENT_FG '%~'
+ prompt_segment blue $CURRENT_FG '%(4~|%-1~/…/%2~|%3~)'
@tossmilestone
tossmilestone / get_current_func.py
Created May 23, 2018 08:41
Get current function name in python
import inspect
# functions
def whoami():
return inspect.stack()[1][3]
def whosdaddy():
return inspect.stack()[2][3]
def foo():
print "hello, I'm %s, daddy is %s" % (whoami(), whosdaddy())
bar()
def bar():
@tossmilestone
tossmilestone / Flake8.txt
Created March 30, 2018 06:55
Flake8 integrated with PyCharm
How to manually setup flake8 as PyCharm external tool
File / Settings / Tools / External Tools / Add
Name: Flake8
Program: $PyInterpreterDirectory$/python
Parameters: -m flake8 --max-complexity 10 --ignore E501 $FilePath$
Working directory: $ProjectFileDir$
Output Filters / Add
Name: Filter 1
@tossmilestone
tossmilestone / TaskSchedulingApplication.java
Created March 5, 2018 03:26
Programmatically scheduling in spring
package demo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
@tossmilestone
tossmilestone / mem_fill.py
Last active November 22, 2017 09:48
Fill memory with bytes
#!/usr/bin/python2
import numpy
g = 10
result = [numpy.random.bytes(1024*1024) for x in xrange(g*1024)]
raw_input('Press <ENTER> to continue')
@tossmilestone
tossmilestone / daemon.json
Created July 18, 2017 09:11
Linux config file of docker daemon
{
"api-cors-header": "",
"authorization-plugins": [],
"bip": "",
"bridge": "",
"cgroup-parent": "",
"cluster-store": "",
"cluster-store-opts": {},
"cluster-advertise": "",
"debug": true,
@tossmilestone
tossmilestone / linux-shadows-global.sh
Created July 5, 2017 07:11
Linux global shadowsocks proxy
#!/bin/bash
# extern variables
SCRIPT_FULL_NAME=$0
SCRIPT_PID=$$
SCRIPT_PID_FILE=/tmp/shadowsocks_ss.pid
SS=ss-redir
SS_IP=127.0.0.1
SS_PORT=1080
SS_LOCAL_PORT=1081

##ss-redir 的 iptables 配置(透明代理)

透明代理指对客户端透明,客户端不需要进行任何设置就使用了网管设置的代理规则

创建 /etc/ss-redir.json 本地监听 7777 运行ss-redir -v -c /etc/ss-redir.json

iptables -t nat -N SHADOWSOCKS
# 在 nat 表中创建新链
iptables -t nat -A SHADOWSOCKS -p tcp --dport 23596 -j RETURN
# 23596 是 ss 代理服务器的端口,即远程 shadowsocks 服务器提供服务的端口,如果你有多个 ip 可用,但端口一致,就设置这个
@tossmilestone
tossmilestone / fibonacci.go
Created June 30, 2017 09:32
Fibonacci closure in go
package main
import "fmt"
// fibonacci is a function that returns
// a function that returns an int.
func fibonacci() func() int {
a, b, c := 0, 1, 0
return func() int {
c, a, b = a, b, a+b
@tossmilestone
tossmilestone / words_count.go
Created June 30, 2017 09:04
Words count in go tour
package main
import (
"golang.org/x/tour/wc"
"strings"
)
func WordCount(s string) map[string]int {
words := strings.Fields(s)
counts := make(map[string]int)