Wednesday, August 15, 2012

Python assigment, shallow copy, and deep copy

I 've copy many text from below links, but deleted them all. Never copy, never copy, never copy ^6^

Below links are MUST read, if you really use python

Must read, because you will write python code, not C/Java...
Code Like a Pythonista
Must read, to get to know about mutable and immutable object. Things seem not important to beginner but will cause many problems if you don't really understand it.
http://docs.python.org/reference/datamodel.html
Must read, because you must understand how does assigment, shallow and deep copy work.
http://docs.python.org/library/copy.html

If you dont, prepace to face many bug because lack of knowledge :)

"numbers, strings and tuples are immutable, while dictionaries and lists are mutable."

Tuesday, August 7, 2012

Why crontab does not work?

I've try to set my python script run daily use crontab.
If your dont know what is cron, learn it now:
http://www.thegeekstuff.com/2009/06/15-practical-crontab-examples/

If your crontab is working well now, skip this post. Otherwise, try to figure out why it does not work.

0. Find out whether cron daemon running or not

hvn@squeeze:~/Apps/birth-reminder$ pgrep cron
1530

Monday, August 6, 2012

Python When and Where

When to use XYZ
Where to use ABC

Answer them all here.

(update later)

Decorator:
http://stackoverflow.com/questions/489720/what-are-some-common-uses-for-python-decorators

Python global


global (readonly):
a good approach:
- If you have only 1 file: declare global variables at the top.
- If you have many files use them: write all that variables to a config file, use ConfigParser to read them in.

global (not-readonly):
pass it around! don't use global


SO: you should never use global keyword

Wednesday, August 1, 2012

[FIXBUG] depends ... but ... is not going to be installed

Cài lại vim vì bản vim đang dùng không hỗ trợ copy ra clipboard.

Làm sao biết?
mở vim ra, gõ :version
tìm xem chữ  xterm_clipboard trước nó là dấu + hay -.
Nếu - là không hỗ trợ (không compile với parameter xterm_clipboard).

Thế nên phải cài vim-gtk hoặc vim-gnome. Nhưng khi gõ sudo apt-get install vim-gnome nó báo lỗi như sau:
....
depends vim-common (= 2:7.3.429-2ubuntu2) but 2:7.3.429-2ubuntu2.1 is to be installed
các xử sự với tất cả các lỗi kiểu depends ... but ... is not going to be installed như sau

gỡ hết ra và cài lại:
sudo apt-get purge vim
sudo apt-get remove vim-common
sudo apt-get autoremove

rồi cài lại là ok