發表文章

目前顯示的是 2014的文章

在一筆 Query 內,加入多筆資料到資料庫中

INSERT INTO example                  (id, name, value, other_value) VALUES (100, 'Name 1', 'Value 1', 'Other 1'),                 (101, 'Name 2', 'Value 2', 'Other 2'),                 (102, 'Name 3', 'Value 3', 'Other 3'),                 (103, 'Name 4', 'Value 4', 'Other 4'); 其中欄位名稱是可以省略的,如: INSERT INTO example VALUES (100, 'Name 1', 'Value 1', 'Other 1'),                 (101, 'Name 2', 'Value 2', 'Other 2'),                 (102, 'Name 3', 'Value 3', 'Other 3'),                 (103, 'Name 4', 'Value 4', 'Other 4');

Git - 同時 push 到多個 remote

倘若 Repository 中有多個 Remote 而且希望一次 push 操作同時丟到多個 Remote 上,可以輸入以下指令來編輯 config : $: git config -e 先前你如果已經設定好偏好的編輯器,則會使用設定好的編輯器進行編輯 。在檔案下方建立一個新的 Entry ,例如: [remote "all"] url=ssh://user@server/repos/g0.git url=ssh://user@server/repos/g1.git 然後 push 改指定 all 這個 Remote 名稱,就會發現同時丟往這兩個位置了!

如何更改 Git config 的編輯器

執行 git config -e ,預設是打開 GNU Nano 編輯器,不過操作上不太順手,可以更改設定,改為自己喜歡的編輯器: $: git config core.editor <editor name> 編輯器可以是任意的,環境變數中找得到的,如果沒有就要自己加進去。

遇到 "Error: Unable to initialize GTK+, is DISPLAY set properly?" 的解決方式

在 Linux Console 下執行圖形應用程式,如果打不開且出現錯誤訊息如下: $:  Error: Unable to initialize GTK+, is DISPLAY set properly? 試著執行以下指令: $:  declare -x DISPLAY=":0.0" 經驗法則 在 SUSE 上以 sudo 去執行程式而遇到這種狀況,可以試試改用 su -c <cmd> 即可成功開啟。

用 DJGPP 編譯 SQLite

$: cd path/to/sqlite $: ../configure --host=i586-pc-msdosdjgpp config_BUILD_CC=gcc config_TARGET_ CC=i586-pc-msdosdjgpp-gcc --disable-tcl --disable-threadsafe 其中  i586-pc-msdosdjgpp   是 cross compiler 的前綴,編譯完成後,可以用 file 查看物件檔屬性: $:  file where.o 80386 COFF executable not stripped - version 30821

在 Ubuntu 64bit 編譯 32 bit 程式

安裝所需 Libraries: $: sudo apt-get install gcc-multilib libc6-i386 lib6-dev-i386 編譯時加上 -m32 參數: $:  gcc -m32 a.c -o a

php/symfony - 在 ubuntu 執行 composer install 出現 "ext-curl *", "ext-gd *", "lib-icu" 的相依錯誤訊息

圖片
如圖,剛下載的專案在新的環境中需要執行 composer install 來安裝所需的套件,此時很可能會出現缺少某些系統套件,在 ubuntu 可以利用 aptitude 安裝這些套件: ext-curl * $: sudo aptitude install php5-curl ext-gd *  $: sudo aptitude install php5-gd lib-icu *  $: sudo aptitude install php5-intl 縮成一行: $: sudo aptitude install php5-curl php5-gd php5-intl

Mac OSX 上如何擷取螢幕?

Mac OS X 內建的 Screen Shot 熱鍵超好用,不需要安裝其他軟體,就能滿足各種快速抓圖的需求。 Command + Shift + 3 抓取整個螢幕畫面並儲存到桌面 Command + Shift + 4 選擇一個畫面區域後儲存到桌面 Command + Shift + 4、放開、再按空白鍵 選取一個視窗後儲存到桌面 Command +  Control  + Shift + 3 Command +  Control  + Shift + 4 Command +  Control  + Shift + 4、放開、再按空白鍵 功能同上;但多一個 Control 鍵,會儲存到剪貼簿而不直接存檔 如果要抓取整個視窗畫面,多按一個空白鍵切換成視窗選取模式,這樣就不會抓到視窗以外的內容,而且抓圖後還會自動將背景設為透明化、並加上陰影,效果真的非常棒! 對於進階使用者,想要在程式或 Shell Script 中自動抓圖,則可以搭配 Mac OS X 內建的「screencapture」指令: # 直接抓取整個畫面存檔 screencapture ~/screenshot.png # 抓取單一視窗畫面 screencapture -w ~/screenshot.png # 抓取單一視窗畫面、背景不要加陰影 screencapture -ow ~/screenshot.png 其他參數可以參考:   -c         force screen capture to go to the clipboard   -C         capture the cursor as well as the screen. only in non-interactive modes   -d         display errors to the user graphically   -i         capture screen interactively, by selection or window                control key - causes screen shot to go to clipboard                space key   - toggle between mouse selectio

讓 GDB 可以顯示完整程式碼除錯

圖片
方法一:         在執行到中斷點的時候,敲入指令 "l"(小寫L),就可以得到以目前執行位置為中心往上與往下擴展5行的程式碼: 方法二:         把程式碼與指令畫面切割,可以單步執行並顯示所在程式碼,則需要在啟動 gdb 時加入參數 "-tui",例如:         $: gdb -tui ./a.out         不過程式在執行過程如果有印出資料,可能會破壞掉現有的檢視畫面,建議把執行過程的輸出導入到 null 裝置,如:         $: (gdb) r > /dev/null         如此一來,就可以不被干擾。

Git - Diff 的小技巧,只比較特定檔案

        一般來說,git-diff 會把所有追蹤中的檔案差異顯示出來,如果我們只要顯示 *.c 副檔名的檔案差異呢? $: git diff --name-only <branch> -- '*.c'         如此一來,就會限制輸出C檔案的差異!其中 --name-only 是為了突顯出有哪些檔案有差異,而查看差異內容。

善用 Linux 的 history command

圖片
Linux console 的重度使用者一定不能忽略這個指令 -- history,他除了顯示出輸入指令的歷史紀錄之外,也可以利用這些資訊加速操作過程,例如: 執行前一道指令的方式: 輸入 "!!" ,然後按下 Enter 輸入 "!-1" ,然後按下 Enter 按下 Ctrl+P,然後按下 Enter 從歷史紀錄中執行特定指令         例如要重複執行如上圖的某道指令,只需 在數字前面加驚嘆號 :         $: !1095         又或者想直接執行某道歷史指令,而懶得打後面的參數,只需 在指令前面加上驚嘆號 :         $: !sudo 清除歷史紀錄         $: history -c

Heroku + Bootstrappers 快速佈署

Using `bootstrappers` to create an App $: bootstrappers <App> $: cd <App> $: git init $: git add . $: git commit -m 'Init' Modify Gemfile group :production do gem ‘pg' gem 'rails_12factor' end Update bundles with... $: bundle Deploy to Heroku $: heroku create <AppName> $: git push heroku master $: heroku run rake db:migrate $: heroku open => Check site.

Ubuntu 下掛載 Cpuid 與 Msr Module

/dev/cpu ├── 0 │   ├── cpuid │   └── msr ├── 1 │   ├── cpuid │   └── msr ├── 2 │   ├── cpuid │   └── msr ├── 3 │   ├── cpuid │   └── msr ├── 4 │   ├── cpuid │   └── msr ├── 5 │   ├── cpuid │   └── msr ├── 6 │   ├── cpuid │   └── msr ├── 7 │   ├── cpuid │   └── msr └── microcode 如上,要產生以上的樹狀結構,在 Ubuntu 下需要執行以下指令: $: sudo modprobe -v msr $: sudo modprobe -v cpuid 載入對應的 Module 才能讀取 CPUID 與 MSR 資訊。

在 Linux 下變更圖檔大小

$: convert <source.img> -resize <geometric> <new.img> Example:  $: convert Add.png -resize 16x16 AddSmall.png

Git - 指定 Branch 匯出原始碼不含版本控制資訊

匯出 master 的內容並打包:   $ git archive master | tar -x -C /somewhere/else 指定特定格式,匯出然後壓縮,如匯出成 *.zip:   $ git archive --format zip --output /full/path/to/zipfile.zip master

如何在 Heroku 設定自己的網域 (以 PcHome 為例)

圖片
Pchome 設定:   1. 更改 DNS 設定,參考下圖連結,進入網頁   2. 在表單中新增一筆 CNAME 紀錄,如下圖的 quic,並且指定地址為 example.herokuapp.com. , example 是你的 App 名稱,而且 地址最後務必加上一個「.」 Heroku 設定:   1. 在 Setting 頁面,找到 Domain 欄位,點擊 "Edit" 後會跳出新增 Domain Name 的表單如下,編輯完按下 「+」,然後儲存即可! 設定很簡單,而且建立後馬上生效!