顯示具有 指令小記 標籤的文章。 顯示所有文章
顯示具有 指令小記 標籤的文章。 顯示所有文章

2015-04-28

MySQL 相關問題

問題:lost connection to mysql server during query
原因可能是由於與 mysql 網路連線過慢或者資料量過大需要較長的讀取/insert(if indexed) 時間
試著設定系統變數 net_read_timeout
mysql -u username -p
...
...

2014-07-21

svn 指令小記


* To check different file names between two revisions
$svn diff -r revision1:revision2 --summarize
note that parameter '--summarize' force svn lists file names only.

ex,
user@ub1204:~/MyAnt_422$ svn diff -r 4355:4211 --summarize
M       mkandroid.sh
M       kernel_imx/build.sh
M       kernel_imx/arch/arm/mach-mx6/board-mx6q_myant.c
M       kernel_imx/drivers/video/mxc/ldb.c
M       device/fsl/sabresd_6dq/BoardConfig.mk
M       configuration

2014-07-18

git 指令小記

* git add
# git add . # add to index only files created or modified and not those deleted
# git add -u # add to index only files modified or deleted and not those created
# git add -A # do both operation at once, add to index all files

* undo delete
1. 用 git reflog 找出 sha1 碼
2. 使用指令
git branch branchName <SHA1>

* 重新命名 local branch
git branch  -m  <原來名>    <新名>

* 刪除遠端 branch
git push remote :遠端branch名

* 在 git repository 中切換 main branch
git symbolic-ref HEAD refs/heads/BRANCH_NAME
註: 等同 local 的 git checkout BRANCH_NAME

* 如果早已把 file 加入 track, 但現在不想讓改變一直被 track, 例如 config file. 則可以下以下命令
git update-index --assume-unchanged FILENAME
未來, 又想它被 track 可以用以下命令回復

git update-index --no-assume-unchanged FILENAME

* git push 後造成 objects 目錄下的權限問題
當有人上傳新版code, 則會在objects下產生其自有的目錄, 權限是user:group, 其中 group 只有 read 權限,
故必需要在建立 git repository 時先就要設 group share 或已經建立後, 可再下命令改 git config
a. 建立時
# git init --bare --shared=group my-repo.git
 

b. 建立後修補方法
$ git config core.sharedRepository group

 

c.建立步驟參考
# mkdir -p /usr/local/share/git/stuff.git
# cd /usr/local/share/git/stuff.git
# chgrp gitusers . # make sure all users that need access are in the group
# chmod 0660 .
# chmod g+s .     # setguid bit
# git init --bare --shared=0660 .

or
# git init --shared=0644

參考文件: http://chirp.syxyz.net/2012/02/sharing-a-git-repository-over-ssh/


* git 移除已加入 git repository 的檔案
git rm --cached FILE_NAME

use -r to recursively remove files from cache,
git rm --cached -r FILE_NAME

* git 放棄 merge
git reset --merge


===================================
[rebase]

f you are not sharing develop branch with anybody, then I would just rebase it every time master updated, that way you will not have merge commits all over your history once you will merge develop back into master. Workflow in this case would be as follows:

> git clone git://<remote_repo_path>/ <local_repo>
> cd <local_repo>
> git checkout -b develop
....do a lot of work on develop
....do all the commits
> git pull origin master
> git rebase master develop
Above steps will ensure that your develop branch will be always on top of the latest changes from the master branch. Once you are done with develop branch and it's rebased to the latest changes on master you can just merge it back:

> git checkout -b master
> git merge develop
> git branch -d develop

========================
檢查兩個 commit 的不同檔案
git diff --name-status 65813002de..9bafa9b3f9




* 當你在windows 及 linux 之間編輯檔案時, 可能會因 windows 換行符號與 linux 不同而讓 git 誤以為檔案有所改變. 這時候你需要一個聰明辨別 windows/linux 的 git.很巧的是 git 的確有提供這個功能, 指令如下:

$git config --global core.autocrlf true
這樣子, 當你再下 git status 時, 那些惱人的因錯辨換行符號而誤以為是檔案被更改過的問題就一掃而空了.
$git status


* 變更 git commit 時使用旳編輯器(editor) 
例如使用 nano  
$ git config --global core.editor nano 
例如使用 OSX 的文字編輯器(TextEdit)
$ git config --global core.editor 'open -a TextEdit' 

*將舊 log 裡的某個檔案拿出來儲存成其它名稱
git show 897be4c3902:api/old_file_name.py > new_file_name.py
 

========================
當你有兩個遠端 bare repository, 例如 repo  A 跟 repo B 
基本上你都 將 local push 到 repo B 再由 repo B push 到 repo A 
 
[repo A]  <-- [repo B] <-- [local] 
 
可是今天可能是同伴開發時 未經 B 直接就 push 到 A
也就是 repo A 比 repo B 新
[repo A](new)  <-- [someone]  ,      [repo B] (old)    
這時你從 repo B push 上 repo A 時會遇到這個訊息: 
hint: Updates were rejected because a pushed branch tip is behind its remote
hint: counterpart. Check out this branch and merge the remote changes
hint: (e.g. 'git pull') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details. 
 
 
若你真的確定 A 比 B 新,你要從 A pull 到 B,你可以在 B 裡下以下指令 
$ git fetch origin +refs/heads/*:refs/heads/* --prune
 
這個動作會將 repo A 的所有 branch update "覆蓋" 你的 repo B
然後你就可以再重新在 local pull repo B, merge repo B
最後再經一般上傳方式上傳
 
 
 
======================== 
當你想產生版本差異的完整檔案(非 patch),且照既有目錄排好,這時你要如何產生?

假設你要取版本 71eba333 ~ 目前 HEAD 位置的所有差異檔案
git archive --format=zip HEAD `git diff 71eba333 HEAD --name-only` > a1.zip

解壓 a1.zip 就是你要的,而且會依照原目錄的結構存放
真的太好用了

延伸題
如上,但你 71eba333 ~ 目前 HEAD有刪除的檔案,這時怎麼辦?可以用 --diff-filter 來過濾掉 D(deleted) 的檔案
git archive --format=zip HEAD `git diff --diff-filter=ACMRTUXB 71eba333 HEAD --name-only` > a2.zip


這個好處是你可以給 patch 檔給不會程式的人,但有 sense 知道如何解壓覆蓋,例如客戶,叫他直接解壓覆蓋即可。什麼語言合適?類interpreter 語言均好用,php, python, perl, bash, ...


參數意義
A Added
C Copied
D Deleted
M Modified
R Renamed
T have their type (mode) changed
U Unmerged
X Unknown
B have had their pairing Broken
* All-or-none
========================
修改最後一個 commit message
git commit --amend
按enter後直接修改即可

修改之前 commit message
只能利用 rebase git rebase -i @˜4 然後利用交談式介面完成 註 @ 即 HEAD

===================================
中止 rebase
git rebase --abort回

回復到未 rebase 狀況
git reset --hard ORIG_HEAD
這不常用,會忘記 head 名稱(不常用是對的)

===================================
樹狀顯示 git log
git log --pretty=format:"%h %s" --graph
git log --graph


===================================


2014-07-12

Python 的 decorator (Part III)

問題
前面 decorator Part I & Part II 已經涵蓋了 decorator 困難部分8成
這裡我們再進階看一個 "參數問題"

Decorator 的下一個問題是, 如果我 decorator 要傳參數的話要怎麼辦呢?
個人覺得這個架構是 python 一個很醜很醜的敗筆

請看一下底下例子

2014-07-11

Python 的 decorator (Part II)


前篇 Python 的 decorator (Part I) 遺留了一個問題


如下程式碼, 那就是明明是 Star 為什麼 Star.__name__ 變成了 my_wrap ?

2014-07-10

Python 的 decorator (Part I)

緣起
當我第一次看到 python 的 @ 符號時,當場傻眼,這是什麼東咚? 這是 command line 的變數的控制符號嗎?
後來去 goo 了一下才發現這東西叫 decorator
花了五分鐘看了一下, 瞭解了
但再實際不同 source 去運作及比對, 才發現...好像怪怪的, 不懂
再去搜集研究比對一下, 好像又懂了
再遇到 wraper 名稱取代 ... 哇~ 又不懂了
一波三折~ 5分鐘的事搞成半小時

Pre-說明
我最討厭只是為了要瞭解一個東西的意義/作用, 就要看人家 blog 寫的落落長的教學文, 寫一堆無關緊要的東西, 但重點只有一個. 甚至還講不到重點(我想即使版主未來想自己參考, 我猜他自己還會看不懂, 真的~)
但 decorator 要說清楚真的需要落落長, 廢話少說開始吧...
我的理解是...

2014-07-09

Android 查 activity 指令 & 指令喚起執行 apk/app

Android 查 activity 指令

aapt dump xmltree PmCalib.apk AndroidManifest.xml  <== Android SDK提供的命令
user@ub1004:~/temp/penmount/calibration/android-4$ aapt dump xmltree PmCalib.apk AndroidManifest.xml
N: android=http://schemas.android.com/apk/res/android
  E: manifest (line=2)

Android Keyevent 大全

adb shell input keyevent 7    # for key '0'
adb shell input keyevent 8    # for key '1'
adb shell input keyevent 29    # for key 'A'
adb shell input keyevent 54    # for key 'B'

linux 指令小記

Linux 最大的缺點就是安裝程式一定是落落長(configure, make, make install), 第二大缺點就是指令一久不用就忘會, 以下小記常用到的指令

[journalctl 查看最後幾行 log]
journalctl --unit=my.service | tail -n 300
journalctl -f tail 


刪除指定名稱的程序(process)
刪除 dnsmasq
ps aux | grep "^dnsmasq" | awk '{print $2}' | xargs  kill -9
但以上會刪到 kill 本身, 若起頭的 "執行身份" 是 nobody, 用以下限制刪除
ps aux | grep "^nobody.*dnsmasq" | awk '{print $2}' | xargs  kill -9
ps aux | grep "^.*nginx:\ .*process.*" | awk '{print $2}' | xargs  kill -9

2014-06-25

python 相關指令及工具小記


[工具]
yolk : 可以列出 packages 的工具
安裝
#sudo easy_install yolk
使用
#yolk -a


2014-06-23

pip 安裝錯誤

你是否遇到這種安裝錯誤訊息?

user@ub1004:~$ pip install pinax
Downloading/unpacking pinax
  Could not find a version that satisfies the requirement pinax (from versions: 0.9a2)
Cleaning up...
No distributions matching the version for pinax
Storing debug log for failure in /home/user/.pip/pip.log

2014-06-20