網頁

2023年11月30日 星期四

How to use TFS / GIT at same folder. 在同一個資料夾使用TFS和GIT.

If you still use the TFS. And want to connect same folder to GIT repository.
Git can work correctly. 
But when you opne Visual Studio. VS alert just support one version control at same time.
Below is my way:
  1. On Windows and use Git Bash.
  2. Your source folder already connect to TFS.
    • Example: /temp/source1/
  3. Source folder connect to new local GIT. (separate .git to another folder)
    • git init --separate-git-dir ../source1_git_repo
    • Now can see two folders in /temp/
      • /temp/source1/
      • /temp/source1_git_repo
    • Check .git just a folder path:
      • cat .git
      • gitdir: C:/Users/YouName/AppData/Local/Temp/test/source_git_repo
  4. Currently Git is work.
  5. How to use TFS for now? Just rename .git 
    • mv .git to .gitrepo (rename)

2018年5月12日 星期六

HTML CSS center a auto width DIV

2016年10月28日 星期五

Linux commands note

* w
* who

**generate password**
pwgen 15 3

**use wget sync web size**

**package install**
查詢套件
sudo apt-cache search gitlab

檢查可升級或安裝版本
sudo apt-cache policy gitlab-ce

安裝特定版本
sudo apt-get install gitlab-ce=10.4.3-ce.0

升級特定版本
sudo apt-get install --only-upgrade gitlab-ce=10.8.5-ce.0

2016年8月18日 星期四

OpenFoundry Projects 要關站了

OpenFoundry Projects 要關站了, 先Export Projects到自己身上了
https://github.com/wangaguo?tab=repositories

從Subversion轉換為Git參考方式

舊文件記錄~

在OpenFoundry的專案,VCS從Subversion轉換為Git,以下提供一個可行的方式,或您可使用其它更好的方式。若您使用Subversion,欲轉換為Git,可以使用git-svn進行clone,接著再將VCS切換為Git,進行後續的動作:

以下假定''testgit''專案,原本為使用Subversion,要轉換至Git。

1. 取出提交者的列表
這是為了提供Git的Author對應的email,先checkout一份從根目錄開始的工作複本,然後執行以下指令:


$ svn co https://www.openfoundry.org/svn/testgit /tmp/testgit-svn
$ cd /tmp/testgit-svn
$ svn log -q | awk -F '|' '/^r/ {sub("^ ", "", $2); sub(" $", "", $2); print $2" = "$2" <"$2">"}' | sort -u > authors-transform.txt
接著修改文字檔,填入提交者對應的電子郵件,如:
jwilkins = jwilkins
修改為
jwilkins = John Albin Wilkins



2. 複制Subversion版本庫至本地Git,使用git-svn


$ git svn clone https://www.openfoundry.org/svn/testgit --no-metadata -A /tmp/testgit-svn/authors-transform.txt --stdlayout /tmp/testgit-git
其中:
-A authors-transform.txt: 即為代入提交者的轉換資料。
--stdlayout:指的是使用慣例trunk; branches; tags為目錄架構。


3. 轉換svn:ignore為.gitignore
如果有使用svn:ignore屬性,可使用以下方式轉換。


$ cd /tmp/testgit-git
$ git svn show-ignore > .gitignore
$ git add .gitignore
$ git commit -m 'Convert svn:ignore properties to .gitignore.'


4. Push到新的git版本庫


先將專案VCS切換至Git,從“專案資訊->基本資料修改”,修改VCS為Git,等待約3分鐘,同步建置Git版本庫及權限。
版本控制->GitWeb,查看是否完成。
版本控制->存取方式,取得版本庫URL。https://www.openfoundry.org/git/[專案名稱].git

設定遠端版本庫:
$ git remote add origin https://www.openfoundry.org/git/testgit.git
將資料Push到專案的Git版本庫中
$ git push origin master


5. 查看及使用


版本控制->GitWeb,查看push後的記錄。
$ git clone https://www.openfoundry.org/git/testgit.git /tmp/testgit


此篇說明參考[http://john.albin.net/git/convert-subversion-to-git Converting a Subversion repository to Git]編寫。

2016年7月14日 星期四

Test transaction page performance

Usually we test web page performance. Maybe test 1000 with 5 concorrent.
If we test a transaction page performance. Will left many ugly transaction data.
So we can desgin a dryrun mode. below is ruby on rails sample.


  class PurchasesController < ApplicationController
    def create

      ActiveRecord::Base.transaction do
        # This do purchase
        raise ActiveRecord::Rollback if params[:dryrun] # when dryrun then rollback.
      end

    end
  end

2016年7月13日 星期三

Ruby method / block / yield / Proc / lambda 全面解釋

http://railsfun.tw/t/method-block-yield-proc-lambda/110

2016年7月12日 星期二

Nginx Reverse proxy from VirtualHost to VirtualHost

www.demo.com DNS is go to Server1. /and Reverse proxy to Server2 by server2.demo.com . But Server2 need to known www.demo.com. So we need set header by proxy_set_header.

**Server1**
```
server {
  listen 80;
  server_name www.demo.com;

  location / {
      proxy_set_header Host $host;
      proxy_pass http://server2.demo.com/;
  }
}

```


**Server2 server2.demo.com**
```
server {
    listen 80;
    server_name www.demo.comt;
    root /opt/www/;
    index index.html index.htm;
}
```

2015年5月4日 星期一

ffmpeg create thumbnail from local or remote video. with Ruby on Rails example.

ffmpeg create thumbnail from local or remote video.
Important point is -ss is before input file. If you place after input file And remote video. create thumbnail will very slow.

local video

$ ffmpeg -ss 5.3 -i "/home/ubuntu/video.mpg" -vframes 1 -f image2 "/home/ubuntu/thumbnail.jpg"

remote video

$ ffmpeg -ss 5.3 -i "http://example.com/video.mpg" -vframes 1 -f image2 "/home/ubuntu/thumbnail.jpg"

Ruby on Rails example

hr = %x[ffmpeg -loglevel error -ss #{m[:time_of]} -i \"#{input_file}\" -y -vframes 1 -vf scale='min(#{size}\\, iw):-1' -f image2 \"#{output_file}\" 2>&1]
  • -loglevel error: when error show message.
  • -ss: time offset. need before input file
  • -i: input file
  • -y: force overwrite output file
  • -vframe: Set the number of video frames to output. This is an alias for -frames:v
  • -vf scale='min(#{size}\\, iw):-1': set thumbnail output size.
  • -f image2: For extracting images from a video
  • "output_file": thumbnail output file
  • 2>&1: return error message

2013年12月4日 星期三

FreeBSD console顯示中文

資料來源:http://www.wretch.cc/blog/iantsai/13572128

裝好 FreeBSD 後因為使用 SSH 或 Console 遠端登入,中文顯示會亂碼,所以必須要修改 LOCALE 設定,才能正常顯示出中文編碼。

2. 使用csh /etc/csh.cshrc 加入下面三行後重開機即可顯示中文。

#vi etc/csh.cshrc
setenv LC_CTYPE en_US.ISO8859-1
setenv LC_ALL zh_TW.UTF-8
setenv LANG zh_TW.UTF-8

3. 若使用 BASH ,則在 /etc/profile 中加入下面三行後重開機就可顯示中文。

LC_CTYPE=en_US.ISO8859-1 ; export LC_CTYPE
LC_ALL=zh_TW.UTF-8 ; export LC_ALL
LANG=zh_TW.UTF-8 ; export LANG

2013年11月26日 星期二

Pound HTTPS Configuration

轉貼自:http://www.project-open.org/en/howto_pound_https_configuration

Pound HTTPS Configuration

The following steps will guide you through the generation of a self-signed certificate for your ]project-open[ server.
During the process you will create:
  • server.key: This is a 1024 bit random string ("private key") that uniquely identifies your server
  • server.csr: This is a "Certificate Signing Request" file. You can send this to a Certificate Authorities (CA), or sign it yourself.
  • server.crt: This is a "certificate" that certifies that server.key belongs to you.
  • server.pem: This is the file that Pound needs to work correctly. A PEM file is a bundle of a the "server.key" priviate key and a certificate.
  1. Generate an RSA private key for the server:
    openssl genrsa -out server.key 1024
  2. Remove the passphrase from the key. Please make sure that nobody will have access to this file except for you. Otherwise the security of your server is at risk:
    cp server.key server.key.org
    openssl rsa -in server.key.org -out server.key
  3. Create the Certificate Signing Request file, or CSR:
    openssl req -new -key server.key -out server.csr
    You will have to provide certain information for your CSR. Here are some sample values for ]project-open[:

    Country Name (2 letter code) [GB]: ES
    State or Province Name (full name) [Berkshire]: Catalonia
    Locality Name (eg, city) [Newbury]: Barcelona
    Organization Name (eg, company) [My Company Ltd]: Project Open Business Solutions S.L.
    Organizational Unit Name (eg, section) []:
    Common Name (eg, your name or your server's hostname) []: www.project-open.org
    Email Address []:webmaster@project-open.com
    A challenge password []:
    An optional company name []:
  4. Now you could go to some Certificate Authority in the Web (for example: http://www.instantssl.com/ currently offers free certificates for 90 days) and sign your key there. As a result, you will receive a "certificate" file that you can save as "server.crt".
  5. As an alternative you can sign the key yourself.
    The server.crt certificate will be technically valid. However, your browser will show a security warning if it encounters such a self-signed certificate:
    openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
  6. Verify your certificat. The following command should output some data, and not an error message:
    openssl x509 -in server.crt -text
  7. Create a PEM file:
    openssl x509 -in server.crt -out server.pem
    openssl rsa -in server.key >> server.pem
    ­
  8. Now you can add a HTTPS listener configuration to your pound.cfg configuration file:
    ListenHTTPS
      Address 0.0.0.0
      Port    443
      Cert    "/etc/pound/server.pem"
    End

    Older versions of Pound (<2.2) may require a different listener configuration, please consult the man-page of your installed version of Pound.
The new configuration will be come active after restarting Pound (/etc/init.d/pound restart).
You can execute "netstat -nlp" to list all network connections. In the upper part your should see something like this:
...
tcp        0      0 0.0.0.0:8000                0.0.0.0:*                   LISTEN      24804/nsd
tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      375/pound
...
tcp        0      0 0.0.0.0:443                 0.0.0.0:*                   LISTEN      375/pound
...­
  • ­ 0.0.0.0:8000: This is the AOLserver itself
  • 0.0.0.0:80: This is Pound listening for unincrypted HTTP connections
  • 0.0.0.0.443: This is the Pound HTTPS listener.
Pound will write any errors into /var/log/messages.

2013年9月3日 星期二

Exim4設定smtp伺服器與檢測

Debian 預設使用Exim4,當伺服器IP為外部IP時,預設值即可使用localhost的smtp來發送信件。但若為內部IP機器時,需進行設定如下,才可正確發信。
發信的成功失敗,可查看/var/log/exim4/maillog。


以下轉貼自【安裝筆記】Exim4 郵件伺服簡單設定與檢測

Debian Etch 套件預設是使用 Exim4,在安裝 base system 套件後即自動啟動,但無法寄出到 Internet,察看 /var/log/exim4/mainlog 訊息後:
 ** xxx@gmail.com R=nonlocal: Mailing to remote domains not supported

1.編輯並修改 /etc/exim4/update-exim4.conf.conf 下列兩行:
 dc_eximconfig_configtype=’internet’ #預設為 local
 dc_smarthost=’msxx.hinet.com’ #遠端的SMTP主機,利用它來發送郵件

2.修改 /etc/mailname ,改成你所在寄送郵件的領域(domain)。

3.執行 exim4 -bV 可測試 exim4 的配置有否出錯。

4.重新啟動 exim4:
 # /etc/init.d/exim4 restart

5.外部郵件發送測試
 # exim4 -bt kenming.wang@gmail.com

使用rsync建立長時間且不佔硬碟空間的備份

這裏不說明太多rsync其它的使用方式,只重點在“使用rsync建立長時間且不佔硬碟空間的備份”。

測試時可加上-n, --dry-run參數,就不會實際同步大量資料
rsync -n

重點指令為:
rsync -a -e ssh --link-dest=/backup/2013-09-02 x.x.x.x:/path/to/backup /backup/2013-09-03

這個方式會備份IP:x.x.x.x 的資料path/to/backup,備份到本機的/backup/2013-09-03,並參考前一天/backup/2013-09-02的資料,如此已存在的資料就用hard link的方式,從2013-09-02建立到2013-09-03中,就不會實際佔用空間,只有新檔案才會佔用空間。

第一次同步時,2013-09-02不在在,只會出現提示訊息,如
--link-dest arg does not exist: /backup/2013-09-02
往後只要前一天存在就不會重覆佔用空間。
而為了避免意外,如中間可能因故漏了幾天沒備份,因此設定--link-dest的路徑時,可往前查找幾天,如2013-09-02不存在,就再往前找2013-09-01,如此才不會因--link-dest設定路徑不存在,又重覆佔用了一次空間。

而確認是否為hard link,可使用ls -i (檢查檔案的inode number),比對兩個日期中的同一檔案,若相同則代表為hard link,實體為同一個,不會多佔硬碟空間。

若要保留一個月的備份資料,只要刪除2013-08-02之前的資料夾即可。

stderr and stdout to file (sh / bash / csh / tcsh)



stderr and stdout to file

sh: (time date) > wa.txt 2>&1
bash: (time date) >& wa.txt or (time date) &> wa.txt or (time date) > wa.txt 2>&1
csh/tcsh: (time date) >& wa.txt

There are 3 file descriptors, stdin(0), stdout(1) and stderr(2) (std=standard).

2013年6月7日 星期五

在Javascript中更好的計時器,取代Date,用來計算執行時間等應用

一般在javascript中要計算某段程式的執行時間,可以使用Date物件。
用法是Date.now() 或 new Date().getTime(),用以取得microsecond(毫秒)的目前時間數值。
在執行函數的前後取得並相減,以取得執行時間,例如:
var ticks_start = Date.now();
RunTestFunction();
var ticks_end = Date.now();
alert(ticks_end - ticks_start);

但一些指令的時間小於毫秒時,根本結果不是0就是1,看不出所以然。
從這篇文章“A better timer for JavaScript”得到了更小單位時間的方法。
window.performance = window.performance || {};
performance.now = (function() {
  return performance.now       ||
         performance.mozNow    ||
         performance.msNow     ||
         performance.oNow      ||
         performance.webkitNow ||
         function() { return new Date().getTime(); };
})();

再將程式改為以下,即可測得0.x毫秒的執行時間:
var ticks_start = performance.now();
RunTestFunction();
var ticks_end = performance.now();
alert(ticks_end - ticks_start);

2013年6月6日 星期四

Ubuntu 安裝 Sublime Text 2與中文輸入問題

2013/12/04註: Sublime Text 3 beta在2013/06/27已開放給未註冊使用者下載。

為了要能垂直編輯多行文字,在特定時候,只留下或編輯多行文字中的值,所以要裝sublime來用看看。
像是以下資料:
  * PID: 7234
  * PID: 6821  
  * PID: 7108    
可以按Ctrl-Alt + 上下左右,選取範圍後,删除或編輯。
變成像是:

  * 7234
  * 6821
  * 7108

即使位置不對等或不是連續,例如:
style="width: 500px;"
style="height: 100px; width: 50px;"
style="width: 80px;"

可以按Ctrl +滑鼠左鍵,點選要插入資料的位置,就可加入相同的內容到各個地方。
style="width: 500px; color: red;"
style="height: 100px; width: 50px; color: red;"
style="width: 80px; color: red;"

目前無法使用apt-get 來安裝,安裝方式如下:
  1. 先下載Linux 32或64於http://www.sublimetext.com/2.
  2. 開啟Terminal.
  3. cd ~/下載
  4. tar -xf "Sublime Text 2.0.1 x64.tar.bz2"  (檔名依下載版本修改)
  5. sudo mv "Sublime Text 2" /usr/lib
  6. sudo ln -s "/usr/lib/Sublime Text 2/sublime_text" /usr/bin/st2
啟動方式一:
  • Terminal中輸入st2
    • # st2
啟動方式二:
  • 加入左邊的啟動器選單中
    • 先在dash中找“主選單” ,接著按“新增項目”,加入/usr/bin/st2.
    • 然後在dash中就可找到 Sublime Text 2,並拉到啟動器。

參考:http://www.arthurtoday.com/2012/09/ubuntu-install-sublime-text-2.html

2013/06/20補充,無法輸入中文的解決方法:
在windows和linux(搭配ibus; scim;fcitx)都有不同狀況的無法輸入中文,
這裡只針對環境ubuntu+ibus,可以安裝plugin來解決。
安裝一個sublime text 2的插件InputHelper,用於輸入中文,安裝如下:
cd ~/.config/sublime-text-2/Packages 
git clone https:// github.com/xgenvn/Input Helper.git
重新啟動之後按Ctrl+Shift+Z可跳出一個中文輸入框(不好用但加減用)。

2013年4月26日 星期五

Copy a file to multiple directory.

Copy a file to multiple folder. Can use find command and type directory (-type d). 
Then use -exec run cp command copy to target {}.

e.g.
find . -name "folder_name" -type d -exec cp /xxx/filename.txt {} \;

2013年3月29日 星期五

Set user shell using ssh script to linux base system and sudo problem.

I using ruby ssh library to linux server. then run sudo command.
like "sudo usermod -s /sbin/nologin Chien-Ming-Wang".


centos:
  Set user shell: sudo chsh -s /sbin/nologin [login name]
  When error: "sudo: sorry, you must have a tty to run sudo"
    vi /etc/sudoers
    mark line: "Defaults    requiretty"


Debian & Ubuntu:
  Set user shell: usermod -s /usr/sbin/nologin [login name]
  When error: "sudo: no tty present and no askpass program specified"
    vi /etc/sudoers
    Add line: [login name] ALL=(ALL) NOPASSWD: ALL

FreeBSD:
  Set user shell: sudo pw usermod [login name] -s /usr/sbin/nologin
  When error: "sudo: no tty present and no askpass program specified"
    vi /usr/local/etc/sudoers
    Add line: [login name] ALL=(ALL) NOPASSWD: ALL

2013年3月18日 星期一

用ssh tunnel來突破公司的防火牆

用ssh tunnel來突破公司的防火牆

外部電腦能連至Server,但Server不能連至公司內電腦,但公司內電腦能連至Server,此時運用反向Tunnel。

  • 公司內電腦建立反向Tunnel連至Server: ssh -NfR 2222:127.0.0.1:22 server_ip_or_domain
  • 外部電腦建tunnel連至Server: ssh -NfL 4444:localhost:2222  server_ip_or_domain
  • 外部電腦 即可連至公司內電腦:  ssh -p4444 localhost


外部電腦不能連至公司內電腦,但內部電腦能連至外部電腦,此時運用反向Tunnel。

  • 公司內電腦建立反向Tunnel連至外部電腦 ssh -NfR 2222:127.0.0.1:22 external_ip_or_domain
  • 外部電腦 即可連至公司內電腦:  ssh -p2222 localhost

參數說明
  • -L [bind_address:]port:host:hostport
    • Specifies that the given port on the local (client) host is to be forwarded to the given host and port on the remote side.
  • -R [bind_address:]port:host:hostport
    • Specifies that the given port on the remote (server) host is to be forwarded to the given host and port on the local side.
  • -N      Do not execute a remote command. 
  • -f      Requests ssh to go to background just before command execution.



2012年4月6日 星期五

Working with Unicode in Ruby

ruby的irb中要顯示中文
輸入
irb> $KCODE = 'u'
就可以了

其它處理utf8字串的有
irb> require 'jcode'
irb> require 'rubygems'
irb> require 'unicode'

詳細參考 http://ideaharbor.org/notes/technical/working-with-unicode-in-ruby