Skip to content

Instantly share code, notes, and snippets.

@icejoywoo
icejoywoo / latency.txt
Created January 21, 2022 07:25 — forked from jboner/latency.txt
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@icejoywoo
icejoywoo / UnionFind.cpp
Created April 19, 2020 16:06
并查集的实现样例
#include<string>
#include<vector>
class UnionFind {
public:
UnionFind(vector<vector<char>>& grid) {
m = grid.size();
n = grid[0].size();
count = 0;
{
@icejoywoo
icejoywoo / Google protobuf installation on Mac
Last active August 21, 2019 07:31 — forked from rajkrrsingh/Google protobuf installation on Mac
Steps to Install google protobuf on Mac
# version 2.5.0
$wget https://github.com/google/protobuf/releases/download/v2.5.0/protobuf-2.5.0.tar.bz2
$tar xvf protobuf-2.5.0.tar.bz2
$cd protobuf-2.5.0
$./configure CC=clang CXX=clang++ CXXFLAGS='-std=c++11 -stdlib=libc++ -O3 -g' LDFLAGS='-stdlib=libc++' LIBS="-lc++ -lc++abi"
$make -j 4
$sudo make install
$protoc --version
# version 2.4.1
@icejoywoo
icejoywoo / EvalDemo.scala
Last active June 25, 2019 06:14
a simple calculator or expression in scala combinators
import com.twitter.util.Eval
object EvalDemo {
def main(args: Array[String]): Unit = {
val eval = new Eval
eval.compile(
"""
|object Env {
| val a = 5
|}
@icejoywoo
icejoywoo / InterpolationDemo.scala
Last active April 26, 2019 16:32
create case class using string interpolation
import com.twitter.util.Eval
object InterpolationDemo {
case class Indicator(basetime: String, key: String, value: Double)
case class ExprImplicit(basetime: String, data: Map[String, Double])
implicit class IndicatorExpressionHelper(val sc: StringContext) extends AnyVal {
def indicator(args: Any*)(implicit default: ExprImplicit): Indicator = {
@icejoywoo
icejoywoo / RDDImplicitDemo.scala
Created December 20, 2018 09:02
a example shows scala implicit in spark RDD
object RDD {
implicit def rddToPairRDDFunctions[K, V](rdd: RDD[(K, V)]): PairRDDFunctions[K, V] = {
new PairRDDFunctions(rdd)
}
}
class RDD[T] {
def filter(): Unit = {
println("filter")
@icejoywoo
icejoywoo / UsingJUnit.scala
Last active September 30, 2018 07:19
Scala Unit Test Demo -- Scala 的单测框架和示例(JUnit4 & ScalaTest)
import org.junit.Assert._
import org.junit._
// junit 4
object UsingJUnit {
@BeforeClass
def beforeClass(): Unit = {
println("before class")
}
#!/usr/bin/env python2.7
# encoding: utf-8
"""
@brief: 一个类型转换为自定义类型 json 的脚本,支持类型的嵌套
例如:string 变为 {"metadata":{"chineseName":null,"desc":null},"name":"simple_string","nullable":true,"type":"string"}
@author: icejoywoo
@date: 2018/8/27
"""
@icejoywoo
icejoywoo / CharUtil.java
Created August 23, 2018 04:43
中文字符判断
import java.util.regex.Pattern;
/**
* 字符通用工具类
*
* @author <a href="http://www.micmiu.com">Michael Sun</a>;
*/
public class CharUtil {
/**
@icejoywoo
icejoywoo / Forcomptran.md
Created August 3, 2018 03:10 — forked from loicdescotte/Forcomptran.md
Scala for comprehension translation helper

Scala for comprehension translation helper

"For comprehension" is a another syntaxe to use map, flatMap and withFilter (or filter) methods.

yield keyword is used to aggregate values in the resulting structure.

This composition can be used on any type implementing this methods, like List, Option, Future...