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 / .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
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 / 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