Skip to content

Instantly share code, notes, and snippets.

View qZhang88's full-sized avatar

Qiao.Zhang qZhang88

View GitHub Profile
@qZhang88
qZhang88 / latency.txt
Created November 23, 2024 01:47 — 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
@qZhang88
qZhang88 / serialize_deserialize_rospy_python3
Created July 13, 2022 12:21 — forked from PeterMitrano/serialize_deserialize_rospy_python3
Quick example of how to serialize then deserialize a ROS msg in python 3
from io import BytesIO
from geometry_msgs.msg import Point
p = Point(x=2, y=4)
print(p)
buff = BytesIO()
p.serialize(buff)
serialized_bytes = buff.getvalue()
@qZhang88
qZhang88 / top_k.py
Created October 26, 2021 01:06 — forked from kernel1994/top_k.py
Top k element index in numpy array
import numpy as np
def largest_indices(array: np.ndarray, n: int) -> tuple:
"""Returns the n largest indices from a numpy array.
Arguments:
array {np.ndarray} -- data array
n {int} -- number of elements to select
@qZhang88
qZhang88 / 结巴词性标记集
Created August 17, 2019 02:05 — forked from hscspring/结巴词性标记集
结巴词性对照表
- a 形容词
- ad 副形词
- ag 形容词性语素
- an 名形词
- b 区别词
- c 连词
- d 副词
- df
- dg 副语素
- e 叹词

Linux 命令行编辑快捷键

初学者在Linux命令窗口(终端)敲命令时,肯定觉得通过输入一串一串的字符的方式来控制计算是效率很低。 但是Linux命令解释器(Shell)是有很多快捷键的,熟练掌握可以极大的提高操作效率。 下面列出最常用的快捷键,这还不是完全版。

  • 命令行快捷键:
    • 常用:
      • Ctrl L :清屏
  • Ctrl M :等效于回车
@qZhang88
qZhang88 / Multiple TF Graph Class.py
Created May 24, 2018 11:36 — forked from Breta01/Multiple TF Graph Class.py
Class for importing multiple TensorFlow graphs.
import tensorflow as tf
class ImportGraph():
""" Importing and running isolated TF graph """
def __init__(self, loc):
# Create local graph and use it in the session
self.graph = tf.Graph()
self.sess = tf.Session(graph=self.graph)
with self.graph.as_default():
# Import saved model from location 'loc' into local graph
@qZhang88
qZhang88 / singleton.py
Last active March 8, 2018 11:25 — forked from werediver/singleton.py
A thread safe implementation of singleton pattern in Python.
import threading
# folk from https://gist.github.com/werediver/4396488
# Based on tornado.ioloop.IOLoop.instance() approach.
# See https://github.com/facebook/tornado
class SingletonMixin(object):
__singleton_lock = threading.Lock()
__singleton_instance = None
@classmethod
@qZhang88
qZhang88 / graham_hull.py
Created January 2, 2018 02:09 — forked from arthur-e/graham_hull.py
Graham's scan convex hull algorithm, updated for Python 3.x
def convex_hull_graham(points):
'''
Returns points on convex hull in CCW order according to Graham's scan algorithm.
By Tom Switzer <thomas.switzer@gmail.com>.
'''
TURN_LEFT, TURN_RIGHT, TURN_NONE = (1, -1, 0)
def cmp(a, b):
return (a > b) - (a < b)
@qZhang88
qZhang88 / nltk-intro.py
Created March 20, 2017 07:57 — forked from alexbowe/nltk-intro.py
Demonstration of extracting key phrases with NLTK in Python
import nltk
text = """The Buddha, the Godhead, resides quite as comfortably in the circuits of a digital
computer or the gears of a cycle transmission as he does at the top of a mountain
or in the petals of a flower. To think otherwise is to demean the Buddha...which is
to demean oneself."""
# Used when tokenizing words
sentence_re = r'''(?x) # set flag to allow verbose regexps
([A-Z])(\.[A-Z])+\.? # abbreviations, e.g. U.S.A.
@qZhang88
qZhang88 / rank_metrics.py
Last active April 12, 2018 09:14 — forked from bwhite/rank_metrics.py
Learning to Rank Metrics.
"""Information Retrieval metrics
Useful Resources:
http://www.cs.utexas.edu/~mooney/ir-course/slides/Evaluation.ppt
http://www.nii.ac.jp/TechReports/05-014E.pdf
http://www.stanford.edu/class/cs276/handouts/EvaluationNew-handout-6-per.pdf
http://hal.archives-ouvertes.fr/docs/00/72/67/60/PDF/07-busa-fekete.pdf
Learning to Rank for Information Retrieval (Tie-Yan Liu)
"""
import numpy as np