[Movie] 电影分享记录

  1. 血肉之躯(Warm Bodies)
    血肉之躯 Warm Bodies (2013)
    短评:人与人之间的冷漠岂不也是如同僵尸,敞开心扉,迎接新生活
  2. 僵尸世界大战
    僵尸世界大战 World War Z (2013)
    短评:当末日来临,家庭、使命终将面临艰难选择;刨根问底发现隐藏在背后的真相必然是要付出代价的,看你愿不愿付出这份代价
  3. 楚门的世界
    短评:眼前的现实或许不那么糟,但不敢或不舍打破眼前的平淡,那么你永远陷于这份平淡中。走出去、向前看的勇气,是进步的趋势,虽然走出去依然可能是进入另一个虚假布局。
  4. 心灵捕手
    短评:who are u? what u want? where u are going? Follow your heart!
  5. 钢琴家
    短评:保持人性的善良,保持自己的尊严;当面临生存困然时,活着是那么的珍贵

[Python]Threading.Thread之Daemon线程

对Daemon线程理解一直不清晰,翻看手册,记录说明如下:

一、什么是Daemon

1
2
3
4
5
A thread can be flagged as a “daemon thread”. 
The significance of this flag is that the entire Python program exits when only daemon threads are left.
The initial value is inherited from the creating thread. The flag can be set through the daemon property.
线程可以被标识为"Daemon线程",Daemon线程表明整个Python主程序只有在Daemon子线程运行时可以退出。
该属性值继承自父线程,可通过setDaemon()函数设定该值。

Note: Daemon threads are abruptly stopped at shutdown.
Their resources (such as open files, database transactions, etc.) may not be released properly.
If you want your threads to stop gracefully, make them non-daemonic and use a suitable signalling mechanism such as an Event.
注意:Daemon线程会被粗鲁的直接结束,它所使用的资源(已打开文件、数据库事务等)无法被合理的释放。因此如果需要线程被优雅的结束,请设置为非Daemon线程,并使用合理的信号方法,如事件Event。

[Python]安全打开关闭文件的方式

Python官方文档支持的with方式进行文件打开、关闭操作:

1
2
with open('file.txt', 'r') as f:
# do stuff with f

在Python2.5版本以前,需手动打开关闭操作,需要考虑的几点:

  • 文件打开成功时,操作正常, 关闭文件
  • 文件打开成功,但操作时异常的, 需手动关闭文件
  • 当文件打开异常时,不需要关闭文件(此时无法进行关闭操作)

安全的处理方式:

1
2
3
4
5
6
7
f = None
try:
f = open('file.txt', 'r')
# do stuff with f
finally:
if f is not None:
f.close()

[LeetCode]328.Odd Even Linked List | 奇偶链表操作

题目来源:328. Odd Even Linked List

Given a singly linked list, group all odd nodes together followed by the even nodes. Please note here we are talking about the node number and not the value in the nodes.

You should try to do it in place. The program should run in O(1) space complexity and O(nodes) time complexity.

Example:
Given 1->2->3->4->5->NULL,
return 1->3->5->2->4->NULL.

Note:
The relative order inside both the even and odd groups should remain as it was in the input.
The first node is considered odd, the second node even and so on …

Credits:
Special thanks to @DjangoUnchained for adding this problem and creating all test cases.

Subscribe to see which companies asked this question

Hexo Installation Document | Hexo安装及部署GitHub

记录通过Hexo搭建Github博客的过程, 记录、分享
部署环境:

1
2
3
ubuntu 14.04.3
node.js: v0.10.37
npm: 3.7.3

1. 安装node.js

1
2
3
4
5
6
7
sudo apt-get install python-software-properties
sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs

five@master:~$ node --version
v0.10.37

PS:由于网络原因可能导致无法下载安装脚本,请自行下载脚本后,执行sudo sh install.sh安装。

2. 安装npm

1
2
3
4
curl http://npmjs.org/install.sh | sudo sh

five@master:~$ npm --version
3.7.3

[LeetCode]172.Factorial Trailing Zeroes | 计算阶乘的尾数零的数量

题目来源:LeetCode:172. Factorial Trailing Zeroes

Given an integer n, return the number of trailing zeroes in n!.

Note: Your solution should be in logarithmic time complexity.

思路

  • 计算阶乘数中尾数0个数主要由2和5的数量决定
  • 2的数量远大于5的个数
  • 要求: 5<-->2, 5^2<-->2^2, 5^3<-->2^3, 5^4<-->2^4, 因2^n<5^n,所以主要由5的数量决定
  • 尾数0的个数= sum(n/5^1+n/5^2+n/5^3+…+n/5^m)
    例:5^3<-->2^3,结合后可生成三个0
  • 特殊情况:n=0时, 因不存在0!应返回0

时间复杂度:O(logn), 空间复杂度O(1)

J2EE项目完整开发、测试、部署、发布环境(updating)

J2EE项目目前成熟的框架、工具很多,但个人对整个项目完整的开发、测试、部署、发布及代码管理缺乏系统整理。
本文旨在对整个项目管理全生命周期详述,以期改进、总结项目流程

主要围绕下述几个维度和工具展开:

  • 项目配置工具: Maven, Git, Log4j
  • 代码测试: TestNG, Selenium
  • 代码管理: GitLab
  • 代码审核: Gerrit
  • 持续集成及发布: Jenkins

[LeetCode]135. Candy | 分糖果

题目来源:LeetCode: 135 Candy

There are N children standing in a line. Each child is assigned a rating value.

You are giving candies to these children subjected to the following requirements:

Each child must have at least one candy.
Children with a higher rating get more candies than their neighbors.
What is the minimum candies you must give?

  • 规则1:每个人手中至少一个
  • 规则2:评分更高的孩子比左右邻居糖果数量多:分别遍历比较比左侧孩子多,比右侧孩子多。
  • 贪婪算法(Greedy Algorithm),从左到右遍历确保高分孩子比左侧糖果多,从右向左遍历确保高分孩子比右侧糖果多。

时间复杂度:O(n), 空间复杂度O(1)

Database indexing theroy | 数据库索引实现分析

一、数据库索引的实现原理

推荐阅读:MySQL索引背后的数据结构及算法原理

摘录:

  • 数据库索引,是数据库管理系统中一个排序的数据结构,以协助快速查询、更新数据库表中数据。索引的实现通常使用B树及其变种B+树。
  • 设置索引要付出代价:一是增加了数据库的存储空间,二是在插入和修改数据时要花费较多的时间(因为索引也要随之变动)。