Tuesday, July 31, 2012

HTTP header

Firefox :
https://addons.mozilla.org/en-us/firefox/addon/live-http-headers/

wget -d
d = debug

curl -v
v = verbose

Change wget agent

http://whatsmyuseragent.com/

using with wget -U 'AGENT' to check whether wget work.

hvn@hvnatvcc: ~/python/NetChecker/bin $ wget http://whatsmyuseragent.com/

hvn@hvnatvcc: ~/python/NetChecker/bin $ wget -U 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:13.0) Gecko/20100101 Firefox/13.0.1' http://whatsmyuseragent.com/ 

return other result

Friday, July 27, 2012

Python buildout

The official document quite ugly:
http://www.buildout.org/install.html

You should follow below tuts to get understanding what id does:
http://wiki.pylonshq.com/display/pylonscommunity/Howto+install+Pylons+with+buildout#initialize-a-buildout-for-your-project

http://jacobian.org/writing/django-apps-with-buildout/

Deploy using zc.buildout and PythonPaste  (if you know flask "just a little", this will help you full understand what it do,)

http://flask.pocoo.org/snippets/27/

Then, you can turn back to read the official document

What does zc.buildout do?
Basically, it install packages that you specified in buildout.cfg. So you can develop/deploy isolate to other project, and futhermore, you can help someone has the same environment as yours.



What is build out :
Quoting the Buildout website, "Buildout is a Python-based build system for creating, assembling and deploying applications from multiple parts, some of which may be non-Python-based. It lets you create a buildout configuration and reproduce the same software later.". Buildout originated from the Zope/Plone community to automate deployment of customized instances of their software. Lead by Jim Fulton, CTO of Zope Corporation, Buildout became a stable and mature product over the years.
Buildout is used in SlapOS to define which software must be executed on a Slave Node. It has a key role in SlapOS industrial successes. Without it, SlapOS could not exist. However, buildout is also often misunderstood - sometimes purposely - by observers who criticize its use in SlapOS. Many people still do not realize that there is no possible software standard on the Cloud and that buildout is the solution to this impossibility. Experts know for example that any large scale production system which is operated on the Cloud (ex. a social network system) or privately (ex. a banking software) uses patched software. Relational databases are patched to meet performance requirements of given applications as soon as data grows. If a Cloud operating system does not provide the possibility to patch about any of its software components, it is simply unusable for large scale production applications. SlapOS is usable because its definition of what is a software is based on the possibility of patching any dependent software component.

(theo http://www.slapos.org/wiki/slapos.Why.Buildout)

Nói chung với buildout bạn sẽ:
- Phát triển các phần mềm trên môi trường độc lập (tương tự virtualenv). Tức ở project này bạn dùng package A, phiên bản B còn ở project khác dùng package C phiên bản D. (ở A dùng python2.5 còn ở C dùng python2.7 chẳng han)
- Không cần quyền root để cài các package
- Tự động thiết lập môi trường giống hệt ở mọi nơi chỉ cần file buildout.cfg
- Tạm thế.

Thursday, July 26, 2012

Introduction to finance

đã enrolll lớp này
https://class.coursera.org/introfinance-2012-001/lecture/index
và sẽ take note tất cả ra đây :D

insist on clear understanding
~~~~~~~~~~~~~~~~~~~~~~
Week1

Finance is the study of value, not money\
Money is just tool
Value creatation: 2 components: time & uncertainly
Will learn a framework
Finance = art + science

time value of money
decision criteria
bonds and stocks
uncertainty & risk

understand WHY they work the way they do

TVM
time value of money:

PV = present value
FV = future value
N :  number of period (#)
r = Interest rate (%) > 0

Book: theory of interest

love for example, is something that you can't put a dollar sign. That's why it's awesome

Wednesday, July 25, 2012

Code then fail...

Lesson for to day: (some best practice i've leart from my experiences)

  1. Every Python function should return a value if it supposed to return a value. You should explicit return None. (Explicit is better than implicit - PEP 20)
    "So if a function is supposed to return a value, then I make sure all code paths have a return, and that the return has a value, even if it is None.
    If a function "doesn't" return a value, that is, if it is never called by someone using its return value, then it's ok to end without a return, and if I need to return early, I use the bare form, return."
    http://stackoverflow.com/questions/4027586/is-it-ok-to-skip-return-none?answertab=votes#tab-top
  2.  pdb not work on multithreading
  3. careful with copy. Understand when you need deepcopy
  4. You should know how to use debuger, it will save your life one day.
  5. Debugger and unittest will show it value when you found your bug. When you fail!

Friday, July 20, 2012

Debian Squeeze (i386 & amd64)

Install skype 4 on squeeze (ix86 / amd64) 
Installing skype on Debian Squeeze
How to install Skype 4.0 on Debian Squeeze
 
root@HVNLappy:/home/hvn/Downloads# sudo dpkg -i skype-debian_4.0.0.8-1_i386.deb
sudo: unable to resolve host HVNLappy
(Reading database ... 67004 files and directories currently installed.)
Preparing to replace skype 4.0.0.8-1 (using skype-debian_4.0.0.8-1_i386.deb) ...
Unpacking replacement skype ...
dpkg: dependency problems prevent configuration of skype:
 skype depends on libqt4-dbus (>= 4:4.5.3); however:
  Package libqt4-dbus is not installed.
 skype depends on libqt4-network (>= 4:4.5.3); however:
  Package libqt4-network is not installed.
 skype depends on libqt4-xml (>= 4:4.5.3); however:
  Package libqt4-xml is not installed.
 skype depends on libqtcore4 (>= 4:4.6.1); however:
  Package libqtcore4 is not installed.
 skype depends on libqtgui4 (>= 4:4.6.1); however:
  Package libqtgui4 is not installed.
dpkg: error processing skype (--install):
 dependency problems - leaving unconfigured
Processing triggers for gnome-menus ...
Processing triggers for desktop-file-utils ...
Errors were encountered while processing:
 skype
root@HVNLappy:/home/hvn/Downloads# sudo apt-get install libqtgui4
sudo: unable to resolve host HVNLappy
Reading package lists... Done
Building dependency tree      
Reading state information... Done
You might want to run 'apt-get -f install' to correct these:
The following packages have unmet dependencies:
 libqtgui4 : Depends: libaudio2 but it is not going to be installed
             Depends: libfontconfig1 (>= 2.9.0) but 2.8.0-2.1 is to be installed
             Depends: libjpeg8 (>= 8c) but it is not going to be installed
             Depends: libmng1 (>= 1.0.10) but it is not going to be installed
             Depends: libqtcore4 (= 4:4.8.2-1) but it is not going to be installed
             Depends: libtiff4 (> 3.9.5-3~) but 3.9.4-5 is to be installed
             PreDepends: multiarch-support but it is not going to be installed
 skype : Depends: libqt4-dbus (>= 4:4.5.3) but it is not going to be installed
         Depends: libqt4-network (>= 4:4.5.3) but it is not going to be installed
         Depends: libqt4-xml (>= 4:4.5.3) but it is not going to be installed
         Depends: libqtcore4 (>= 4:4.6.1) but it is not going to be installed
E: Unmet dependencies. Try 'apt-get -f install' with no packages (or specify a solution).
root@HVNLappy:/home/hvn/Downloads# apt-get -f install
DONE

~~~~~~~~~~~~~~
Tự challenge mình với việc cài Debian 6.0.5 Squeeze 64 , không giao diện và rồi... đầu hàng. Thế nhưng những kinh nghiệm trả giá bằng thời gian thì phải giữ lại.

 Chọn chỉ cài phần core + gói cho laptop, không tự động config mạng.
Sau khi cài xong, việc đầu tiên là làm cho có mạng, ở đây là mạng dây.

sửa file /etc/network/interfaces

thêm vào dòng
auto eth0
iface eth0 inet dhcp

#Cho wifi
auto wlan0
iface wlan0 inet dhcp
wpa-ssid ten_mang_wifi
wpa-psk password

 sau đó lấy quyền root chạy /etc/init.d/networking restart
ifup / ifdown ten_iface
Eg: ifup wlan0

nếu vẫn không được thì gõ lệnh : dhclient
~~~~
Cài sudo (thường có sẵn trong đĩa nên ko cần dơwn):
sửa file : /etc/sudoers
thêm dòng
hvn    ALL=(ALL) ALL dưới dòng  (hvn là tên user)
# User privilege specification
root    ALL=(ALL) ALL
~~~~~~~~~~~~~
Để có giao diện:
cài xorg (hình như chỉ cần cài mỗi xorg-server thôi, lúc cài nó tống hết nên ko chắc.
Sau đó phải cài 1 desktop manager.Ở đây mình chọn gdm
apt-get install gdm


rồi cài 1 window manager, lựa chọn là i3
apt-get installl i3

do squeeze là bản stable của debian, với tinh thần stable một cách bảo thủ của họ thì bạn hòan toàn khó có thể sống 1 cách "on the edge" được. Để cài 1 số phiên bản mới hơn của 1 số phần mềm, hãy sửa lại trong file /etc/apt/sources.list , thay

deb http://ftp.tw.debian.org/debian squeeze main
thành 
deb http://ftp.tw.debian.org/debian wheezy main
hoặc
deb http://ftp.tw.debian.org/debian sid main

bạn chỉ nên thay rồi apt-get update, cài xong app mình cần rồi chuyển lại về squeeze, việc chạy lẫn lộn giữa các bản thế này nhiều khi khiến hệ thống mất đi tính stable và có thể bị hỏng =.=

Debian là một os tốt cho những thứ cần tính ổn định cao như làm server, còn để làm desktop, có lẽ bạn nên dùng Ubuntu để được dùng những phần mềm mới hơn mà tính ổn định của 1 desktop vẫn được đảm bảo. Giảm thiểu thời gian config những thứ ko cần thiết.

~~~~~~~~~~~~~~~~~
Khó khăn  ~.~
bản 64bit:
1. ko tìm được FF bản stable trên trang của Firefox
2. cài ibus không được vì dependency
3. sau 1 hồi đánh vật cũng cài được skype, nó cần thư viện ia32libs. Phải chọn source từ wheezy mới có.
-> bỏ, không chơi bản này nữa.

~~~~~~~~~~~~~~
32bit:
Skype 4.0 lại bị dependency vào libqt...Gõ như đoạn đầu bài này là giải quyết được.
~~~~~~~~~~~~~~~~
resolv.conf rewritten each time reboot

open file: /etc/dhcp/dhclient.conf
$ sudo gedit /etc/dhcp/dhclient.conf 
remove comment from line:
# prepend domain-name-servers 127.0.0.1;
to
prepend domain-name-servers 8.8.8.8, 8.8.4.4;
note the trailing semicolon

~~~~~~~~~~~~~~~~
add service start at boot:

add command to file: /etc/rc.local





Saturday, July 14, 2012

Nhật ký ArchLinux - KISS

vì thích cái triết lý của Arch từ lâu mà đã down đĩa cài về. Install xong nhưng vứt 1 xó vì không có thời gian mò.


http://www.archlinux.org/

A simple, lightweight distribution 

the Arch Philosophy, perhaps best summarized by the acronym KISS for Keep It Simple, Stupid. 

nay lại chả muốn làm gì, ngồi nghịch arch tiếp cho vui :D