2015年7月26日 星期日

[胡言亂語] Android Studio

最近在找 Android Studio 的資料, 發現簡中的文件比繁中多太多了, 雖然是早已經知道的結果, 可是還是不禁要感嘆一下 reference: Android Studio系列教程

2015年7月25日 星期六

[Tips] 切換 Python 版本

電腦裡裝了很多版本的 Python
python             python2.6          python2.7          python3.4-config   python3.4m-config  
python2            python2.6-config   python3.4          python3.4m         python-config      
預設是使用超級舊的 2.6.5, 有些模組功能不支援, 例如 subprocess 的 check_output 只在 python2.7 以後才能使用
python --version
Python 2.6.5
我們可以利用 update-alternatives 切換 python 的版本 先查一下可使用的版本, 真糟糕不能用
update-alternatives --list python
update-alternatives: error: no alternatives for python.
加入 2.6
sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.6 1
update-alternatives: using /usr/bin/python2.6 to provide /usr/bin/python (python) in auto mode.
加入 2.7
sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.7 2
update-alternatives: using /usr/bin/python2.7 to provide /usr/bin/python (python) in auto mode.
加入 3.4
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.4 3
update-alternatives: using /usr/bin/python3.4 to provide /usr/bin/python (python) in auto mode.
再查一下可使用的版本
update-alternatives --list python
/usr/bin/python2.6
/usr/bin/python2.7
/usr/bin/python3.4
可以很高興的切換版本了
sudo update-alternatives --config python
There are 3 choices for the alternative python (providing /usr/bin/python).

  Selection    Path                Priority   Status
------------------------------------------------------------
* 0            /usr/bin/python3.4   3         auto mode
  1            /usr/bin/python2.6   1         manual mode
  2            /usr/bin/python2.7   2         manual mode
  3            /usr/bin/python3.4   3         manual mode

Press enter to keep the current choice[*], or type selection number: 2
update-alternatives: using /usr/bin/python2.7 to provide /usr/bin/python (python) in manual mode.
看看現在使用的 python 版本吧
python --version
Python 2.7.6
這套工具特別適合程式語言版本的切換, Java 更是需要阿

最近發生了一個趣事, 切換版本以後 apt-get 會用到 python 的指令都爛掉了, 錯誤訊息如下:
After this operation, 0B of additional disk space will be used.
(Reading database ... 417151 files and directories currently installed.)
Preparing to replace python-pkg-resources 0.6.10-4ubuntu1 (using .../python-pkg-resources_0.6.10-4ubuntu1_all.deb) ...
Traceback (most recent call last):
  File "/usr/bin/pycentral", line 2300, in 
    main()
  File "/usr/bin/pycentral", line 2294, in main
    rv = action.run(global_options)
  File "/usr/bin/pycentral", line 1653, in run
    runtimes = get_installed_runtimes(with_unsupported=True)
  File "/usr/bin/pycentral", line 278, in get_installed_runtimes
    default_version = pyversions.default_version(version_only=True)
  File "/usr/share/pycentral-data/pyversions.py", line 172, in default_version
    raise ValueError, "/usr/bin/python does not match the python default version. It must be reset to point to %s" % debian_default
ValueError: /usr/bin/python does not match the python default version. It must be reset to point to python2.6
dpkg: warning: old pre-removal script returned error exit status 1
dpkg - trying script from the new package instead ...
Traceback (most recent call last):
  File "/usr/bin/pycentral", line 2300, in 
    main()
  File "/usr/bin/pycentral", line 2294, in main
    rv = action.run(global_options)
  File "/usr/bin/pycentral", line 1653, in run
    runtimes = get_installed_runtimes(with_unsupported=True)
  File "/usr/bin/pycentral", line 278, in get_installed_runtimes
    default_version = pyversions.default_version(version_only=True)
  File "/usr/share/pycentral-data/pyversions.py", line 172, in default_version
    raise ValueError, "/usr/bin/python does not match the python default version. It must be reset to point to %s" % debian_default
ValueError: /usr/bin/python does not match the python default version. It must be reset to point to python2.6
dpkg: error processing /var/cache/apt/archives/python-pkg-resources_0.6.10-4ubuntu1_all.deb (--unpack):
 subprocess new pre-removal script returned error exit status 1
Traceback (most recent call last):
  File "/usr/bin/pycentral", line 2300, in 
    main()
  File "/usr/bin/pycentral", line 2294, in main
    rv = action.run(global_options)
  File "/usr/bin/pycentral", line 1477, in run
    runtimes = get_installed_runtimes()
  File "/usr/bin/pycentral", line 278, in get_installed_runtimes
    default_version = pyversions.default_version(version_only=True)
  File "/usr/share/pycentral-data/pyversions.py", line 172, in default_version
    raise ValueError, "/usr/bin/python does not match the python default version. It must be reset to point to %s" % debian_default
ValueError: /usr/bin/python does not match the python default version. It must be reset to point to python2.6
dpkg: error while cleaning up:
 subprocess installed post-installation script returned error exit status 1
Errors were encountered while processing:
 /var/cache/apt/archives/python-pkg-resources_0.6.10-4ubuntu1_all.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)
拜了咕狗以後, 才發現還是要把 default python 路徑(/usr/bin/python)指到一個喜歡的人上面(python2.6)
sudo ln -sf /usr/bin/python2.6 /usr/bin/python

2015年7月9日 星期四

[計算機概論] The TTY demystified

這篇有很詳盡的介紹 TTY 的歷史, 好像叫 demystified 的都很厲害?

貼幾張圖吧:


2015年6月26日 星期五

[Vim] 給Python的.vimrc超基本設定

syntax on
set t_Co=256
set bg=dark
set modeline
set shiftwidth=4
set softtabstop=4
set expandtab
set background=dark

2015年6月20日 星期六

[Tips] ERROR SOLUTION DURING FIRMWARE UPDATE HUAWEI MODEM

最近有一張 Huawei E398-u1 的網卡不知道為什麼無法連線, 結果找到幾個新版的 firmware, 更新一直要問密碼...

Error Solution:
http://www.modemunlock.com/error-solution-during-firmware-update-huawei-modem.html

Huawei modem unlock code and flash code calculator:
http://www.modemunlock.com/huawei.php

DC-unlocker client(看IMEI)
https://www.dc-unlocker.com/downloads




2015年2月19日 星期四

[Python] PEP8 Coding Style + 基本 Vim 設定

PEP8 落落長, 常用的紀錄一下吧

以下文字大多從這篇來的
1. 以 4 個空格進行縮排
2. 利用 4 個空格取代 Tab
3. 限制每行最多 79 字元
4. Top level 的函數與類別之間用空 2 行進行區隔
5. 類別內的方法,以空 1 行進行區隔
6. 程式檔案編碼使用 UTF-8
7. import 模組應該 1 行 1 個
8. import 需有次序之別,並且群組間以空行區隔
9. 不使用 Wildcard imports
10. 不需使用空格對齊
11. 不需在參數的等號(=)旁邊增加空格
12. 模組名稱應儘量短,並全部小寫
13. 類別名稱應使用 CapWords 命名
14. 函數名稱應使用小寫
15. 常數(Constants)應大寫,並以底線分割單字

另外 vim 的設定也可以注意一下
set tabstop=4
set shiftwidth=4
set softtabstop=4
set smarttab
set expandtab
nnoremap <F2> :<C-U>setlocal lcs=tab:>-,trail:-,eol:$ list! list? <CR>
按 F2 可以顯示 Tab 和空格

reference: 隨手養成 Python 好習慣 - PEP8 Coding Style、Vim 基本設定

2015年2月12日 星期四

[Tips] AWS EC2加大硬碟

總是要手忙腳亂, 最重要的就是要先備份

官方的文件其實蠻清楚的, 就是這篇

簡單紀錄步驟
1. 備份(做 snapshot)
2. 建立新的 volume(注意要和舊的 volume 在同一個 zone)
3. stop instance
4. 將舊的 volume 卸載
5. 將新的 volume 裝載, 使用剛剛的 snapshot, 並且 mount 到 /dev/sda1
6. start instance
7. IP 會跑掉, 所以 DNS 要改

真是心驚膽跳阿!!

對了, 這次才發現不同的 SSD 有不同的價格和建議用途, 參考這張

reference:
* How to upgrade EC2 Ubuntu Linux micro instance to small
* Expanding the Storage Space of a Volume on Linux
* How to Increase Disk Space on an Amazon EC2 Instance