2012年10月3日 星期三

使用Git與Github管理軟體開發專案

http://billy3321.blogspot.tw/2009/02/github-howto.html


windows -

1.安裝與設定git


請先抓取putty-installer安裝,或至少抓取plink.exe
http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html
接下來抓取msysgit的安裝檔  ( 選 Git-1.7.11-preview20120704.exe - 安裝git bash )
http://code.google.com/p/msysgit/downloads/list

安裝時,選擇使用Plink,並從putty安裝資料夾或plink.exe所在資料夾點選plink。 (不知其用途)


2.設定與上傳ssh key
git使用ssh tunnel來傳遞原始碼,這個加密通道可以避免原始碼的封包被攔截而竊取。
因此要先產生與上傳ssh key到github,方便之後與伺服器之間的通訊。
在安裝好的git選單中選取git-bash,並輸入

$ ssh-keygen -C “username@email.com” -t rsa


Generating public/private rsa key pair.

Enter file in which to save the key (/home/tom/.ssh/id_rsa): <enter>

Enter passphrase (empty for no passphrase): <輸入存取此key之密碼,或直接按下enter使用空密碼>

Enter same passphrase again: <再一次輸入相同密碼>

Your identification has been saved in /home/tom/.ssh/id_rsa.

Your public key has been saved in /home/tom/.ssh/id_rsa.pub.

The key fingerprint is:

50:43:77:c6:97:af:61:82:dc:ea:9b:6b:67:d4:1b:61 tom@volcano


您的public key就存放在id_rsa.pub裡面,而id_rsa則是private key,請妥善保存以免遺失。
這個key是一對的,private key要存放於家目錄下的.ssh資料夾中。public key則複製後,貼上您github帳號中的SSH Public Keys欄位。注意小心不要複製到空格。

將Public key所有內容複製後貼上您github帳戶底下的 SSH Public Keys 欄位,一次貼上一個(注意,這邊貼上的是public key,另外請注意不要有空格。)
github設定public keys : 點右上角account settings圖示 -> 左邊點SSH Keys -> Add SSH key ( 把上面public key貼上去 )


3.設定github帳號並開啟一個repo

4. 第一次git push 時可能會遇到

No refs in common and none specified; doing nothing.
Perhaps you should specify a branch such as 'master'.
fatal: The remote end hung up unexpectedly
error: failed to push some refs to 'file:///xxxxxxx.git'
這是Git 找不到你要提交的版本了.

解法:
http://blog.csdn.net/viweei/article/details/6163562

$ git push origin master

5. (optional)安裝 Github 介面軟體
https://help.github.com/articles/set-up-git 點 Download GitHub for Windows (家裏電腦不知為何點了沒反應...)

6. 錯誤訊息:

Cloning into 'amp'...
FATAL ERROR: Disconnected: No supported authentication methods available (serve sent: publickey)
fatal: The remote end hung up unexpectedly

重裝git後照 https://help.github.com/articles/generating-ssh-keys 步驟做一次

更多的git安裝配置與錯誤處理: http://wiki.7color.org/git.html


ps. 讓git-bash的git有高亮
Why does git diff on Windows warn that the “terminal is not fully functional”?
http://stackoverflow.com/questions/7949956/why-does-git-diff-on-windows-warn-that-the-terminal-is-not-fully-functional

Can be fixed by adding the following line to ~/.bashrc:
export TERM=msys

Git - how to tell which commit a tag points to
http://stackoverflow.com/questions/1862423/git-how-to-tell-which-commit-a-tag-points-to


Summary: Since there are about 4 almost equally acceptable yet different answers I will summarise all the different ways to skin a tag.
  1. git rev-list $TAG | head -n 1 (thanks mipadi). git rev-list outputs the commits that lead up to the $TAG similar to git log but only showing the SHA1 of the commit. For non-unix heads like myself head -n 1 will show the first line of the output, which is the tip of the tag.
  2. git show-ref --tags (thanks Charles Bailey) will show all tags (local and fetched from remote) and their SHA1s.
  3. git show-ref $TAG(thanks Jakub Narębski) will show the tag and its path along with the SHA1.
  4. git rev-parse $TAG(thanks Jakub Narębski) will show the SHA1 of an unannotated tag.
  5. git rev-parse --verify $TAG^{commit} (thanks Jakub Narębski) will show a SHA1 of both annotated and unannotated tags. On Windows use git rev-parse --verify %TAG%^^^^{commit} (four hats).
  6. cat .git/refs/tags/* or cat .git/packed-refs (thanks The MYYN) depending on whether or not the tag is local or fetched from remote.






2012年9月26日 星期三

[Apache] 在URL中刪除目錄

http://lmgtfy.com/?q=url+rewrite+remove+folder

http://stackoverflow.com/questions/1314279/mod-rewrite-in-expression-engine-removing-directory-in-url

使用下面規則把目錄去掉
  
#RewriteEngine on  #可能需要打開
#RewriteBase /
RewriteCond %{THE_REQUEST} ^GET\ /website/
RewriteRule ^website/(.*) /$1 [L,R=301]
RewriteRule !^website/ website%{REQUEST_URI}

2012年9月22日 星期六

[CodeIgniter] No Input File Specified.

用ci出現 No input file specified. 錯誤:

http://tzangms.com/programming/977/

因為 http://www.codeigniter.org.tw/user_guide/installation/troubleshooting.html
伺服器可能不支援 PATH_INFO 變數

因為把 config.php
$config['index_page'] = 'index.php';
改為
$config['index_page'] = 'index.php?';

使用 helper - url 的 redirect 會有問題,所以讓url-rewrite去解

把 rewrite改掉如下
原本的 rewrite
RewriteRule ^(.*)$ index.php/$1 [L]
改成
RewriteRule ^(.*)$ index.php?/$1 [L]


2012年9月13日 星期四

我的CI模組

1. http://www.codeigniter.org.tw/  下載最新CI
2. https://github.com/Vheissu/Ci-Smarty 下載最新ci-smarty ,直接解壓縮到CI application目錄下
3. http://www.codeigniter.org.tw/user_guide/general/urls.html 設定ci url-rewrite (把index.php 拿掉),
RewriteEngine on
RewriteBase /
RewriteCond $1 !^(index\.php|images|robots\.txt|$)
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
index.php、images、robots.txt 的全部 HTTP request 都會被當成是 request index.php 檔案。 )
如果目錄是 http://localhost/justin/amp/index.php/smartytest RewriteBase 要設定 /justin/amp/
4. http://rental.zhupiter.com/postshow_178_1_1.html 打開本機 apache - url-rewrite ( 我電腦是 win 7 - appserv )
4-1 先確定自己的 Apache web server 有設定成支援 ReWrite。
   動態載入 ReWrite engine 的設定下會在 httpd.conf 中看到這一行『LoadModule rewrite_module modules/mod_rewrite.so』。4-2 在 DocumentRoot 所屬的 Directory 設定內設定 ReWrite 參數。
RewriteEngine On
4-3 因為我設定 virualhost 所以也要到 D:\AppServ\Apache2.2\conf\extra\httpd-vhosts.conf 修改設定


<VirtualHost *:80>
    DocumentRoot "D:\AppServ\www"
    ServerName localhost      
    <Directory "D:\AppServ\www">
        Options FollowSymLinks Indexes
        AllowOverride All
        Order allow,deny
        Allow from all
    RewriteEngine On
    </Directory>
</VirtualHost>
4-4 設定完 apache 後 去 win 7的 "服務" 重新啟動apache.
4-5 如果主機不支援url-rewrite或url-rewrite有問題且無法設定apache , 啟動CI的Query Strings
http://www.codeigniter.org.tw/user_guide/general/urls.html

CodeIgniter 也有提供這個功能,可以到 application/config.php 檔案中開啟底下的設定:
$config['enable_query_strings'] = FALSE;
$config['controller_trigger'] = 'c';
$config['function_trigger'] = 'm';
只要把 "enable_query_strings" 設定為 TRUE,這個功能就會啟動。
index.php?c=controller&m=method

設定encryption_key以啟動session功能
$config['encryption_key'] = 'xxx';

5. 在application\libraries\Smarty.php 中設定左分隔符和右分隔符

$this->left_delimiter = '{{';
$this->right_delimiter = '}}';

6. 在 application\config\smarty.php 調整smarty cache
$config['cache_status']         = TRUE;
設為FALSE 讓開發時不使用cache

7. application\config\autoload.php 設定
$autoload['helper'] = array('url'); 
讓前端能直接使用 {{base_url()}} 抓網站網址
$autoload['libraries'] = array('parser','database','session');
自動載入smarty、db、session 功能

8. 在linux主機上要把cache資料夾改權限
ex. $ chmod 777 -R cache

出現錯誤Only variable references should be returned by reference:
A PHP Error was encountered
Severity: Notice
Message: Only variable references should be returned by reference
Filename: core/Common.php
Line Number: 257
https://ellislab.com/forums/viewthread/244510/
解法:

return $_config[0] =& $config;
改成
$_config[0] =& $config;
return $_config[0];

2012年9月4日 星期二

CodeIgniter URL-rewrite

http://www.codeigniter.org.tw/user_guide/general/urls.html
以下是將除了像是 index.php、captcha(資料夾)、images、admin、swf檔(使用.*為任意檔名)、css檔、js檔 的全部 HTTP request 都會被當成是 request index.php 檔案。 ( ex. pond.php => index.php/pond.php )
  
RewriteEngine on
RewriteBase /
RewriteCond $1 !^(index\.php|captcha|images|admin|.*\.swf|.*\.css|.*\.js|.*\.xml|.*\.jpg|$)
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

2012年8月30日 星期四

在安裝了Firebug的Firefox中打開網頁慢的原因

原出處: http://younglab.blog.51cto.com/416652/272905


      Firebug是每個Web開發者必用的調試工具,不過你有沒有發現,當Firebug處於打開狀態的時候,載入網頁變慢了,尤其是DOM結構比較複雜和JavaScript腳本比較多的網頁,有時候甚至會導致Firefox停止回應。不過關閉Firebug以後,一切又正常了。我一直被這個問題困惑著,原以為是Firebug打開時會在Firebug調試器中同步載入網頁數據,導致網頁打開很慢。
      今天終於找到原因了。Rob Campbell在其博客中闡述了FireBug使Firefox變慢的原因。文章地址是:http://antennasoft.net/robcee/2009/12/15/firebug-and-the-jit/文章比較容易理解,我就不翻譯了。

*有時js會與firefox套件衝突,當別人firefox功能正常(或自己chrome正常時->我比較少裝chrome套件)
解法:除了firebug以外的plugin都關掉,目前已知json viewer啟動後在contest上傳時會有bug

前端開發firefox的套件:
靈感:Dean的firefox畫面捷圖

Javascript Deminifier ( 可搭配firebug使用 )
[Firefox] 利用附加模組把最小化的 javascript 還原格式
http://demo.tc/Post/726
如何啟動?
選項->勾選"附加元件列"->在下方的JSD狀態開關ON/OFF ->重新刷頁(ctrl+r)
stackoverflow解法:http://stackoverflow.com/questions/5386826/how-can-i-debug-a-minified-js-in-firebug
**JS Deminifer  啟動後的BUG
<script type="text/javascript" src="global_mapping.js"></script>
如果global_mapping裡面有判斷式有註解這樣亂寫:
if (a) {
    ...
}
// 2009-10-12 10:43:18 / 1978-10-10T10:00:00Z
else if (b) {
    ...
}      
// 10/12/2009 10:12:43            
else {
    return null;

}
JS Deminifier啟動後會有bug
解法:在publish時不要勾選 Turn off javascript minifier,使得js檔壓縮,移除註解

YSlow

Fiddler

Rellik =>
WEB DEVELOPER
http://chrispederick.com/work/web-developer/installed/firefox/12/
DNSSEC Validator
http://www.dnssec-validator.cz/



perl 取現在時間並格式化

use POSIX;
my $now_time = POSIX::strftime("%Y-%m-%d %H:%M:%S", localtime(time())); #now time

perl -e 'print localtime(time())' # 30403201111243540

OR

use Date::Format; print time2str("%Y-%m-%d %H:%M:%S", time());
perl -e 'print time()' # 1356003592

使用指令直接執行perl,
# perl -MPOSIX -e 'print POSIX::strftime( "%A, %B %d, %Y", localtime());' //顯示時間
#perl -MLWP::Simple -e 'getprint "http://www.cs.nthu.edu.tw";' //抓網站資料直接在console顯示