#!/usr/bin/env python vs #!/usr/local/bin/python

#!/usr/bin/env python

Will figure out the correct location of python and make that as the interpreter for rest of the script.

#!/usr/local/bin/python

Pointing to python is located at /usr/local/bin/python.

简单说 /env python 就是查找系统环境变量中的 python 并默认选择 path 里第一个。/usr/local/bin/python 就是指定使用这个路径下的 python,可能不同机子不同环境下 python 位置稍有差别,就有可能 /usr/local/bin/python 不存在。

via Here

Cron notes

Cron is a Linux system process that will execute a program at a preset time. To use cron you must prepare a text file that describes the program that you want executed and the times that cron should execute them. Then you use the crontab program to load the text file that describes the cron jobs into cron. via Using cron

crontab -e to edit the crontab file.

Format:

[min] [hour] [day of month] [month] [day of week] [program to be run]

Some examples:

10 3 * * * /usr/bin/foo ==> Will run /usr/bin/foo at 3:10am on every day.

12 3 * * * root tar czf /usr/local/backups/daily/etc.tar.gz /etc >> /dev/null 2>&1 via Cron Help Guide

CocoaChina Devcon 2

随手用手机记了几点:

  1. 东西方游戏差别:东方玩家讲究剧情、操作、难度、画面,更享受游戏的过程和过关后那种爽快;西方游戏玩家比较喜欢休闲、娱乐、简单的游戏,不愿意去学习游戏操作甚至秘籍。
  2. 90% 的 iOS 用户对游戏都是新手,所以不能照搬 PC、PSP、街机游戏机游戏那种设计。
  3. 大部分 iOS 上的游戏玩家的 GQ 都很低,所以 Don’t make me think.
  4. 游戏时长最好 3~5 分钟,这个时长也是大家的碎片时间,休闲娱乐来一下~
  5. App 推广,俩字:曝光!充分利用一切途径加大程序的曝光度。
  6. 上线之前的准备工作要充足细致,App ICON 设计,画面截图,文字描述要准备充分,这个是唯一的一次宣传机会。

最后一个演讲很有货,准备把 keynotes 抓下来自己好好回味一下,不仅仅是 App Store 的生存法则。

SQL LEN function in MySQL

SQL: The LEN() function returns the length of the value in a text field.

SELECT LEN(column_name) FROM table_name

BUT: in MySQL LEN() does NOT work,it’s called LENGTH().

SELECT * FROM table_name WHERE LENGTH(column_name) < 5

via 1 2

Terminal Tips and Tricks For Mac OS X

via SuperUser:Terminal Tips and Tricks For Mac OS X

  • open . #Opens the folder you’re currently browsing in Finder.URLs, images, documents.

  • open -a Preview image.png #overriding the default program set for the filetype.

  • say “Hello there.” #text-to-speech.

  • !! #Runs the last command again; sudo !! to rerun the last command using sudo.

  • mdfind fileName #-onlyin for directory specified; -name for matching file names only.

  • python -m SimpleHTTPServer 8000 #Start a quick webserver from any directory.

  • qlmanage -p 2>/dev/null #alias as ql,launch quicklook on a file from the command line

电子邮件签名格式

标准的电子邮件签名格式是:两个连字符,一个空格,然后断行,跟上你的签名信息,纯文本。

The formatting of the sig block is prescribed somewhat more firmly: it should be displayed as plain text in a fixed-width font (no HTML, images, or other rich text), and must be delimited from the body of the message by a single line consisting of exactly two hyphens, followed by a space, followed by the end of line.

via Wikipedia:E-mail and Usenet

你是这样的吗?

中国开发者的一个大的特点:

对技术痴迷的同时不食人间烟火
  1. 整天津津乐道的就是那些算法、数据结构、设计模式、语言技巧、技术规范
  2. 对于普通老百姓关心的东西一概没有兴趣。
  3. 大部分人对于时尚、化妆品、小资情调嗤之以鼻
  4. 对于电影、音乐、艺术、美食一知半解,对于地产、金融、法律知识一窍不通
  5. 对于一个普通老百姓市场生活中所能遇到的困难和问题,所追求的那一点享受和乐趣不闻不问
  6. 既不愿意亲身实践,更在主观心态上予以拒斥。
根本上缺少对于生活和需求的深刻体察,对于人的关怀!

策划产品的时候全凭感觉:

  • 做出来的东西千篇一律
  • 看上去什么都有,一用起来处处不贴心。
  • 我们把太多的时间用来围着电脑转,根本上缺少对于生活和需求的深刻体察,对于人的关怀。
  • 在企业软件领域,我们把这种情况称之为“不了解业务”,现在整个企业软件领域都在寻找“懂技术,通业务”的复合型人才
  • 在大众软件和公众互联网领域,这种情况同样严重。我就经常感觉,就算是 MP3 播放器、电子书、网络论坛这样最最平常的应用,一旦加上具体应用背景, 放在具体场合下,就有很多地方显得不方便,不贴心。

via Slide success story by @stingchen.

Python Dictionary tips

  • Constructing Dictionaries with Keyword Arguments,the simplest way to create a Dict.
dict(a=1, b=2, c=3) # returns {'a': 1, 'b': 2, 'c': 3}
  • Dicts to Lists.
dict = {'a': 1, 'b': 2, 'c': 3}
keys_list = dict.keys() #return ['a', 'c', 'b']
values_list = dict.values() #return [1,2,3]
dict_as_list = dict.items() #return [('a', 1), ('b', 2), ('c', 3)]

via Constructing Dictionaries with Keyword Arguments

Python zip function

The built-in zip function can be used, well, to zip lists together. It returns a list of tuples, where the nth tuple contains the nth item from each of the passed in lists.

letters = ['a', 'b', 'c']
numbers = [1, 2, 3]
squares = [1, 4, 9]

zipped_list = zip(letters, numbers, squares)
# zipped_list contains [('a', 1, 1), ('b', 2, 4), ('c', 3, 9)]

via Combining Multiple Lists, Item by Item

Python 多线程爬虫

备忘。

队列模块使用步骤(via):

  1. 创建一个 Queue.Queue() 的实例,然后使用数据对它进行填充。
  2. 将经过填充数据的实例传递给线程类,后者是通过继承 threading.Thread 的方式创建的。
  3. 生成守护线程池。
  4. 每次从队列中取出一个项目,并使用该线程中的数据和 run 方法以执行相应的工作。
  5. 在完成这项工作之后,使用 queue.task_done() 函数向任务已经完成的队列发送一个信号。
  6. 对队列执行 join 操作,实际上意味着等到队列为空,再退出主程序。

其中 join() 方法说明:

保持阻塞状态,直到处理了队列中的所有项目为止。在将一个项目添加到该队列时,未完成的任务的总数就会增加。当使用者线程调用 task_done() 以表示检索了该项目、并完成了所有的工作时,那么未完成的任务的总数就会减少。当未完成的任务的总数减少到零时,join() 就会结束阻塞状态。