2018年1月24日 星期三

docker named volume path

Located at host's /var/lib/docker/volumes/

https://stackoverflow.com/questions/36312699/chown-docker-volumes-on-host-possibly-through-docker-compose/36321403#36321403

https://github.com/CWSpear/local-persist

Python project scaffold

http://docs.python-guide.org/en/latest/writing/structure/
https://www.kennethreitz.org/essays/repository-structure-and-python
https://github.com/pypa/sampleproject
https://github.com/sroberts/python-starter

找到這個generator,感覺更方便,處理方式也比較先進。
https://pypi.python.org/pypi/PyScaffold
pip install pyscaffold
putup my_project

如果是Django project可加--django參數,不過應該只是單純的幫你多下一次
django-admin.py startproject my_project而已

如果想要把apps放到不是project的root,而是像src的資料夾
在startapp之前要先把資料夾建好
mkdir ./src/newapp
然後才startapp
python manage.py startapp newapp ./src/newapp

之後要在project的setting.py多加這兩行
import sys
sys.path.insert(0, os.path.join(BASE_DIR, "src"))
才能在runserver時找到newapp
參考這個的

2018年1月16日 星期二

用Bitbucket存放Source code (如果ssh port22被擋)


SSH的 git@bitbucket.org:farwill/testlink_converter.git
改成HTTPS的 https://farwill@bitbucket.org/farwill/testlink_converter.git

所以是
git remote add origin https://farwill@bitbucket.org/farwill/testlink_converter.git
git push -u origin master

2017年12月20日 星期三

Python的Unicode HOWTO

https://docs.python.org/3/howto/unicode.html
最早的ASCII碼(Code),只有0~127(7bits),無法包含更多特殊字。
1980年代的個人電腦幾乎都是8bit,所以可以處理ASCII且還多出128~255可以使用,但不同機器有不同的Code。
Unicode一開始用16bits來取代原來的8bits,有2^16 (65536)個值可使用,目標是可包含所有的語言,但其實還是不夠。後來擴展到 0 through 1,114,111 ( 0x10FFFF in base 16).
一個字元(Character),Unicode定義了一個字元的Code point,就是這個字元的值。表示法如U+12CA就表示值是0x12ca的字元。
Encoding(編碼)是指從字串轉為位元組序列的規則,UTF-8就是一種最普遍的編碼方式,UTF (Unicode Transformation Format),8是指8-bits的數字被使用來編碼。規則是這樣:
  1. If the code point is < 128, it’s represented by the corresponding byte value.
  2. If the code point is >= 128, it’s turned into a sequence of two, three, or four bytes, where each byte of the sequence is between 128 and 255.
Python的預設編碼方式是UTF-8,可用特殊的註解改變(第一或第二行)
# -*- coding:  -*-
Python支援以Unicode為名的變數
若想保持Python的原始碼是ASCII-only,可用Escape字符 /u或/U或/N字元名來編寫
>>> "\N{GREEK CAPITAL LETTER DELTA}"  # Using the character name
'\u0394'
>>> "\u0394"                          # Using a 16-bit hex value
'\u0394'
>>> "\U00000394"                      # Using a 32-bit hex value
'\u0394'
另外,可用bytes的method "decode()"來輸出Unicode,另外帶encoding參數和error處理方式(請看最上方連結)
Python 3.2有100種不同的encoding。
單個字元的轉換,可用chr(int)輸出Unicode,用ord(str)輸出值(code point)
字串與位元組串的操作是bytes.decode() 和 str.encode()

The most important tip is:

Software should only work with Unicode strings internally, decoding the input data as soon as possible and encoding the output only at the end.

2017年11月28日 星期二

Bash if

if [[ -n "${VAR}" ]]; then
  echo variable VAR is set and value is ${VAR}
fi

if [[ -z "${VAR}" ]]; then
  echo variable VAR is unset or empty
fi

                        +-------+-------+-----------+
                VAR is: | unset | empty | non-empty |
+-----------------------+-------+-------+-----------+
| [ -z "${VAR}" ]       | true  | true  | false     |
| [ -z "${VAR+set}" ]   | true  | false | false     |
| [ -z "${VAR-unset}" ] | false | true  | false     |
| [ -n "${VAR}" ]       | false | false | true      |
| [ -n "${VAR+set}" ]   | false | true  | true      |
| [ -n "${VAR-unset}" ] | true  | false | true      |
+-----------------------+-------+-------+-----------+

if [[ -e file.txt ]]; then
  echo file.txt is exist
fi

if [[ ! -e file.txt ]]; then
  echo file.txt is NOT exist
fi

http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_07_01.html

2017年11月20日 星期一

docker jekyll on windows 10

docker run -p 80:4000 -v c:\tmp:/srv/jekyll jekyll/jekyll jekyll s -s ./my-site --watch --force-polling

Browse http://127.0.0.1:4000

on Windows 7  with Docker toolbox:
replace "c:\tmp" to "/c/tmp"

docker run -p 4000:4000 -v /c/Users/Jack_Lin/Documents/abc:/srv/jekyll jekyll/jekyll jekyll s --watch --force-polling

Browse http://192.168.99.100:4000

If your want to customize minima theme. check
https://github.com/jekyll/minima

Setup proxy on Docker Toolbox on Windows7

https://github.com/docker/toolbox/issues/102

Hi!,
Just tested the following steps on Win7 with Docker-toolbox and it works ! Wow!
Split from windows command directory to linux with the following command:
$ docker-machine ssh default
Now the command line start with "docker@default:~$"
Write sudo ..... as the following line
docker@default:~$ sudo vi /var/lib/boot2docker/profile
Write "i" to pass in insert mode and return button.
Add the two http export settings with username and password :
export "HTTP_PROXY=http://username:password@proxy.something.it:port"
export "HTTPS_PROXY=http://username:password@proxy.something.it:port"
Digit esc ": wq!" to save the new line and verify if everithing is ok with the cat command
docker@default:~$ cat /var/lib/boot2docker/profile
Restart the daemon
docker@default:~$ sudo /etc/init.d/docker restart
Now i have restarted the Docker toolbox and the "Docker pull image_name" work fine!
Thanks a lot to everybody!