Skip to content

Instantly share code, notes, and snippets.

View HouLinwei's full-sized avatar

HouLinwei

  • ex ByteDance
  • Beijing City, China
View GitHub Profile
@HouLinwei
HouLinwei / simpleScript.scala
Created November 2, 2018 17:05 — forked from dragade/simpleScript.scala
example of a simple scala script
#!/bin/sh
#This is an example scala script which requires the user to have scala in the PATH
#you can set CP to contain whatever other jars you need
CP=.
exec scala -classpath $CP "$0" "$@"
!#
val x = 1 to 10
val sum = x.foldLeft(0)(_+_)
println("sum=" + sum);
@HouLinwei
HouLinwei / go_iterator.go
Created May 24, 2018 04:00
go iterator demo
package main
import "fmt"
type Ret struct {
No int
}
func Iter(max int) func() (*Ret, bool) {
var cur int
@HouLinwei
HouLinwei / .bash_aliases
Created April 9, 2018 07:54 — forked from vratiu/.bash_aliases
Git shell coloring
# Customize BASH PS1 prompt to show current GIT repository and branch.
# by Mike Stewart - http://MediaDoneRight.com
# SETUP CONSTANTS
# Bunch-o-predefined colors. Makes reading code easier than escape sequences.
# I don't remember where I found this. o_O
# Reset
Color_Off="\[\033[0m\]" # Text Reset
@HouLinwei
HouLinwei / remove_shortcut_arrow.bat
Created July 30, 2017 01:54
remove windows desktop shortcut's arror
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Icons" /v 29 /d "%systemroot%\system32\imageres.dll,197" /t reg_sz /f
taskkill /f /im explorer.exe
attrib -s -r -h "%userprofile%\AppData\Local\iconcache.db"
del "%userprofile%\AppData\Local\iconcache.db" /f /q
start explorer
pause
@HouLinwei
HouLinwei / uwsgi.ini
Last active August 18, 2017 02:03
serve a Django application with uWGSI.
# mysite_uwsgi.ini file
[uwsgi]
# Django-related settings
# the base directory (full path)
chdir = /path/to/your/project
# Django's wsgi file
module = project.wsgi
# the virtualenv (full path)
home = /path/to/virtualenv
@HouLinwei
HouLinwei / echo_pid_accodring_port.sh
Created June 28, 2017 01:45
echo_pid_accodring_port
port=$1
pid=`netstat -nlp 2>/dev/null|grep ${port}|grep LISTEN|awk '{print \$NF}'|awk -F"/" '{print \$1}'`
echo $pid
class KMP:
def partial(self, pattern):
""" Calculate partial match table: String -> [Int]"""
ret = [0]
for i in range(1, len(pattern)):
j = ret[i - 1]
while j > 0 and pattern[j] != pattern[i]:
j = ret[j - 1]
ret.append(j + 1 if pattern[j] == pattern[i] else j)
@HouLinwei
HouLinwei / golang-get-the-function's-name.go
Created February 16, 2017 03:17
golang get the running function's name
// getCurrentFuncName will return the current function's name.
// It can be used for a better log debug system.(I'm NOT sure.)
func getCurrentFuncName() string {
pc, _, _, _ := runtime.Caller(1)
return fmt.Sprintf("%s", runtime.FuncForPC(pc).Name())
}
@HouLinwei
HouLinwei / latency.markdown
Created October 14, 2016 02:58 — forked from hellerbarde/latency.markdown
Latency numbers every programmer should know

Latency numbers every programmer should know

L1 cache reference ......................... 0.5 ns
Branch mispredict ............................ 5 ns
L2 cache reference ........................... 7 ns
Mutex lock/unlock ........................... 25 ns
Main memory reference ...................... 100 ns             
Compress 1K bytes with Zippy ............. 3,000 ns  =   3 µs
Send 2K bytes over 1 Gbps network ....... 20,000 ns  =  20 µs
SSD random read ........................ 150,000 ns  = 150 µs

Read 1 MB sequentially from memory ..... 250,000 ns = 250 µs

@HouLinwei
HouLinwei / demonize.py
Created March 23, 2016 03:10
create a demonize process with python
def daemonize():
"""Performs the necessary dance to become a background daemon."""
if os.fork():
os._exit(0)
os.chdir("/")
os.umask(022)
os.setsid()
os.umask(0)
if os.fork():
os._exit(0)