Posts

python standard library

Standard Library 中有用的函数 https://docs.python.org/2/library/index.html http://python-reference.readthedocs.io/en/latest/index.html binO: int -> binary 位运算的时候有用。 相关位运算有用的打包函数有: divmod() binary->int   int([binary string], 2) ... 以后再补充 Data structure: 这是可以用于threading的queue. 是否thread safe有待考证。。 https://docs.python.org/2/library/queue.html Example of how to wait for enqueued tasks to be completed: def worker (): while True : item = q . get () do_work ( item ) q . task_done () q = Queue () for i in range ( num_worker_threads ): t = Thread ( target = worker ) t . daemon = True t . start () for item in source (): q . put ( item ) q . join () # block until all tasks are done http://book.pythontips.com/en/latest/map_filter.html http://zh-google-styleguide.readthedocs.io/en/latest/contents/ http://www.pythonforbeginners.com/basics/list-comprehensions-in-python Random函数...

Quick Sort

看一万遍忘一万遍, 再看亦是如初见。 对quick sort的思考,希望下次再看的时候能有蓦然回首灯火阑珊的感受! 对于quick sort, 无论排大排小,最核心的部分在于如何找到pivot, 并且为pivot 找到它最正确的位置。在业界,也叫用pivot 对需要排序的list进行partition. 什么是partition? 简单说来,用K 对一个list进行partition,就是将该list分为两部分,一部分是小于k的部分,而另一部分是大于k的部分,然后输出那条分界线。 然而在quick sort中,在最核心的partition 之前,又多了一步,找pivot 什么是pivot? pivot就是一个list中的任意值,它可以将list分解为大于等于,和小于它的两部分,它所处的index就是该list此刻的值域分界线。 pivot可以是任意值,它的取值习惯一般分为种 start end mid any 其中,最简单的取值方式要属于前面第一种和第二种,即start和end. 这是为什么呢? 因为在quick sort的时候,我们需要明确的知道每一条分界线具体的Index, 也就是说,在partition完成之后的那条分界限上的值必须要是之前选取的pivot. 简单说来,我们需要在记住pivot的位置,然后在partition结束后将pivot放置在那条分界线上。 为什么要将每次选取的pivot放置在patition的分界线上? 我认为这是quick sort的精髓所在,在quick sort中,每次sort之后唯一确定的位置就是pivot的位置。因为pivot的位置固定,我们就可以使用divide and conquer 的算法,当找到该pivot的固定位置之后就可以只对(start, pivot-1) 和 (pivot+1, end)的部分进行sort.

Python 学习小心得 001

最近花了2天时间学习了一下python。越发的觉得,整个编程语言的进程就是一部活活的进化史。看见了它拥有所有的编程语言都有的不变的筋骨,看见了它萃取他人之精华,也看见了它化繁为简自成一派的优势。 时代在进步,我为此感到了无比的欣喜。最近常常和身边的朋友说,长大真是一件好美妙的事情,可以看懂了以前看不懂的电影,理解了以前理解不了的书,听懂了以前听不懂的音乐,唯有一点,似乎对人的宽容和耐心比以前少了些,也许是发现,再好玩的人再有意思的人都有个终点,不如我自己好玩。哈哈哈哈。不过我也很清楚的明白,这是不好的,要像我的同事Alejandro学习,做一个耐心的,谦虚的,有责任感的,thoughtful的人。 As my principal: Do something good Do something meaningful Do something helpful 下面要记录下我在python里面的小感受。 1. 化繁为简,只用list代替了queue, stack, list, array. 所有的iteratable的操作都可以用list完成。 Python List Methods append()  - Add an element to the end of the list extend()  - Add all elements of a list to the another list insert()  - Insert an item at the defined index remove()  - Removes an item from the list pop()  - Removes and returns an element at the given index clear()  - Removes all items from the list index()  - Returns the index of the first matched item count()  - Returns the ...

Topological Sort

What's topological sort? Topological sorting for Directed Acyclic Graph (DAG) is a linear ordering of vertices such that for every directed edge uv, vertex u comes before v in the ordering.  Topological Sorting for a graph is not possible if the graph is not a DAG. 结果: 在DAG中,f or every directed edge uv, vertex u comes before v in the ordering. 它是对图中顶点的排序,保证在有向图中,每个节点的出现都是线性的有序的。 注意: 只有DAG能够拓扑排序。(什么是DAG? DAG 是没有回路的有向图。) 不能拓扑排序的条件: 有回路 有向 一个DAG的拓扑序可能有多个 拥有唯一拓扑序的条件: 排序算法: 统计每个点的入度  将每个入度为 0 的点放入队列(Queue)中作为起始节点  不断从队列中拿出一个点,去掉这个点的所有连边(指向其他点的边),其他点的相应的入度 - 1  一旦发现新的入度为 0 的点,丢回队列中 Question of Topological sort 求任意1个拓扑序 Topological Order  是否存在拓扑序(是否可以被拓扑排序)  是否存在环? 求所有的拓扑序  DFS backtracking 求是否存在且仅存在一个拓扑序 每次Queue中最多同时只有1个节点 拓展: 图的相关问题。 树:in  graph theory , a  tree  is an  undirected graph  in which any two  vertices  are connected by  exactly one   pa...

研究课题

1. 如何做好网站的SEO? 2. 如何scraping website?

什么是Atomic Commit?

https://en.wikipedia.org/wiki/Atomic_commit https://people.cs.umass.edu/~arun/cs677/notes/week3.pdf https://www.freshconsulting.com/atomic-commits/ https://stackoverflow.com/questions/38155592/atomic-commits-best-practice

How to write logs?

The best practice: https://logmatic.io/blog/beyond-application-monitoring-discover-logging-best-practices/