Skip to content

Instantly share code, notes, and snippets.

@zhao-ji
zhao-ji / gist:4c9c18428f30099b651f
Created April 11, 2015 13:42
Python output the Nature Number
class Num:
'''output the nature number'''
num = 0
def next_num(self):
yield self.num
self.num += 1
@zhao-ji
zhao-ji / viewport
Created January 21, 2015 09:10
移动端自适应宽度高度
<!--在html代码的<head>...</head>中嵌入下面代码-->
<meta name="viewport"
content="
height = [pixel_value | device-height] ,
width = [pixel_value | device-width ] ,
initial-scale = 0.5 ,
minimum-scale = float_value ,
maximum-scale = float_value ,
user-scalable = [yes | no] ,
"

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

@zhao-ji
zhao-ji / gist:d22d71d336f82149b67f
Created July 12, 2014 00:20
distense of two point
private const double EARTH_RADIUS = 6378.137;
private static double rad(double d)
{
return d * Math.PI / 180.0;
}
public static double GetDistance(double lat1, double lng1, double lat2, double lng2)
{
double radLat1 = rad(lat1);
double radLat2 = rad(lat2);
double a = radLat1 - radLat2;