隨手做筆記
時空背景:
在執行程式時,終端機上的訊息太多又跑太快,來不及看。(on CentOS)
Solution:
./exe | tee log
grep -rn Error log
在執行 "exe" 這個程式時透過 "|" pipeline 與 "tee" 這個 tool 將訊息同時顯示在終端機上並寫入 "log" 這個檔案
程式中斷後,透過 "grep" 這個 tool 在 "log" 這個檔案當中搜尋 "Error" 這關鍵字並顯示在終端機上
MAC
ref: https://unix.stackexchange.com/questions/145651/using-exec-and-tee-to-redirect-logs-to-stdout-and-a-log-file-in-the-same-time
./exe &> >(tee -a "$log_file")
2017年2月22日 星期三
2017年1月23日 星期一
golang cross-compiler on windows to...
Golang 本身就有提供cross-compile相關的工具
以下紀錄的是在windows x64下將golang cross-compiler 成 linux x86
1.先到 $GOROOT 底下的 src(我個人是 C:/go/src)建立一個build.bat檔
2.edit build.bat
set CGO_ENABLED=0
set GOROOT_BOOTSTRAP=C:/Go
:::::::x86:::::::
set GOARCH=386
set GOOS=windows
call make.bat --no-clean
set GOOS=linux
call make.bat --no-clean
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::::::x64:::::::
set GOARCH=amd64
set GOOS=linux
call make.bat --no-clean
set GOOS=windows
call make.bat --no-clean
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
set GOARCH=amd64
set GOOS=windows
go get github.com/nsf/gocode
pause
3.執行 build.bat
4.到 $GOROOT/bin 檢查是否有安裝相關檔案(ex:linux_386)
5.到要編譯程式的資料夾底下,我將指令寫成cross-compiler2linux_x86.bat檔
cd %~dp0
set GOOS=linux
set GOARCH=386
go build helloworld.go
pause
6.執行cross-compiler2linuxx86.bat 就會生成 "helloworld"檔案
7.將 "helloworld" 檔案複製到linux x86底下執行確認。
=======================================================================
本篇cross-compile工具只有設定windows x86, x64, linux x86, x64四種,其他平台請參考下列原文敘述進行修改。
ref:
以下紀錄的是在windows x64下將golang cross-compiler 成 linux x86
1.先到 $GOROOT 底下的 src(我個人是 C:/go/src)建立一個build.bat檔
2.edit build.bat
set CGO_ENABLED=0
set GOROOT_BOOTSTRAP=C:/Go
:::::::x86:::::::
set GOARCH=386
set GOOS=windows
call make.bat --no-clean
set GOOS=linux
call make.bat --no-clean
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::::::x64:::::::
set GOARCH=amd64
set GOOS=linux
call make.bat --no-clean
set GOOS=windows
call make.bat --no-clean
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
set GOARCH=amd64
set GOOS=windows
go get github.com/nsf/gocode
pause
3.執行 build.bat
4.到 $GOROOT/bin 檢查是否有安裝相關檔案(ex:linux_386)
5.到要編譯程式的資料夾底下,我將指令寫成cross-compiler2linux_x86.bat檔
cd %~dp0
set GOOS=linux
set GOARCH=386
go build helloworld.go
pause
6.執行cross-compiler2linuxx86.bat 就會生成 "helloworld"檔案
7.將 "helloworld" 檔案複製到linux x86底下執行確認。
=======================================================================
本篇cross-compile工具只有設定windows x86, x64, linux x86, x64四種,其他平台請參考下列原文敘述進行修改。
$GOOS and $GOARCH
The name of the target operating system and compilation architecture. These default to the values of
$GOHOSTOS and $GOHOSTARCH respectively (described below).
Choices for
$GOOS are darwin (Mac OS X 10.7 and above and iOS), dragonfly, freebsd, linux, netbsd, openbsd, plan9, solaris and windows. Choices for $GOARCH are amd64 (64-bit x86, the most mature port), 386(32-bit x86), arm (32-bit ARM), arm64 (64-bit ARM), ppc64le (PowerPC 64-bit, little-endian), ppc64 (PowerPC 64-bit, big-endian), mips64le (MIPS 64-bit, little-endian), and mips64 (MIPS 64-bit, big-endian). The valid combinations of $GOOS and $GOARCH are:$GOOS | $GOARCH | |
|---|---|---|
android | arm | |
darwin | 386 | |
darwin | amd64 | |
darwin | arm | |
darwin | arm64 | |
dragonfly | amd64 | |
freebsd | 386 | |
freebsd | amd64 | |
freebsd | arm | |
linux | 386 | |
linux | amd64 | |
linux | arm | |
linux | arm64 | |
linux | ppc64 | |
linux | ppc64le | |
linux | mips64 | |
linux | mips64le | |
netbsd | 386 | |
netbsd | amd64 | |
netbsd | arm | |
openbsd | 386 | |
openbsd | amd64 | |
openbsd | arm | |
plan9 | 386 | |
plan9 | amd64 | |
solaris | amd64 | |
windows | 386 | |
windows | amd64 |
ref:
2017年1月4日 星期三
openCV on VS2015
openCV教學網站
1.從官方網站下載openCV後,安裝。(一般都是直接安裝在C槽下)

2.在VS2015中開啟新專案(C++ -> Windows -> 一般 -> 空專案)
3.進行專案屬性設定
4.在VC++目錄 -> include目錄中加入openCV檔案路徑
C:\files\opencv\build\include
C:\files\opencv\build\include\opencv
C:\files\opencv\build\include\opencv2
5.在VC++目錄 -> 程式庫目錄中加入openCV函式庫
C:\files\opencv\build\x86\vc10\lib
6.在連結器 -> 輸入 -> 其他相依性 加入需要的 *.lib檔
C:\files\opencv\build\x86\vc10\lib\opencv_core231d.lib
C:\files\opencv\build\x86\vc10\lib\opencv_calib3d231d.lib
C:\files\opencv\build\x86\vc10\lib\opencv_contrib231d.lib
C:\files\opencv\build\x86\vc10\lib\opencv_features2d231d.lib
C:\files\opencv\build\x86\vc10\lib\opencv_highgui231d.lib
C:\files\opencv\build\x86\vc10\lib\opencv_imgproc231d.lib
7.加入系統環境變數 C:\files\opencv\build\x86\vc10\bin;
8.程式碼測試-開啟攝影機
#include <stdio.h>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace cv;
using namespace std;
int main() {
//抓取攝影機
VideoCapture cap(0);
//嘗試開啟攝影機
if (!cap.isOpened()) {
return -1;
}
//用矩陣紀錄抓取的每張frame
Mat frame;
//建立一個視窗,名稱為camera
namedWindow("camera", 1);
for (;;)
{
//把取得的影像放置到矩陣中
cap >> frame;
//顯示frame到camera名稱的視窗
imshow("frame", frame);
if (waitKey(30) >= 0) break;
}
system("PAUSE");
return 0;
}
搞定~~~~
1.從官方網站下載openCV後,安裝。(一般都是直接安裝在C槽下)
2.在VS2015中開啟新專案(C++ -> Windows -> 一般 -> 空專案)
3.進行專案屬性設定
4.在VC++目錄 -> include目錄中加入openCV檔案路徑
C:\files\opencv\build\include
C:\files\opencv\build\include\opencv
C:\files\opencv\build\include\opencv2
5.在VC++目錄 -> 程式庫目錄中加入openCV函式庫
C:\files\opencv\build\x86\vc10\lib
6.在連結器 -> 輸入 -> 其他相依性 加入需要的 *.lib檔
C:\files\opencv\build\x86\vc10\lib\opencv_core231d.lib
C:\files\opencv\build\x86\vc10\lib\opencv_calib3d231d.lib
C:\files\opencv\build\x86\vc10\lib\opencv_contrib231d.lib
C:\files\opencv\build\x86\vc10\lib\opencv_features2d231d.lib
C:\files\opencv\build\x86\vc10\lib\opencv_highgui231d.lib
C:\files\opencv\build\x86\vc10\lib\opencv_imgproc231d.lib
7.加入系統環境變數 C:\files\opencv\build\x86\vc10\bin;
8.程式碼測試-開啟攝影機
#include <stdio.h>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace cv;
using namespace std;
int main() {
//抓取攝影機
VideoCapture cap(0);
//嘗試開啟攝影機
if (!cap.isOpened()) {
return -1;
}
//用矩陣紀錄抓取的每張frame
Mat frame;
//建立一個視窗,名稱為camera
namedWindow("camera", 1);
for (;;)
{
//把取得的影像放置到矩陣中
cap >> frame;
//顯示frame到camera名稱的視窗
imshow("frame", frame);
if (waitKey(30) >= 0) break;
}
system("PAUSE");
return 0;
}
搞定~~~~
2016年12月6日 星期二
編譯Gstreamer ( on windows)
詳細的教學文件
首先嘗試編譯Gstreamer所提共的19個範例
1.下載Gstreamer的安裝檔,共兩個檔案(下載位置),選擇自己要的版本。
gstreamer-1.0-x86_64-1.10.2
gstreamer-1.0-devel-x86_64-1.10.2
皆選擇完整安裝即可。
2.下載Gstreamer的範例檔(下載位置)
下載回來後可以在 gst-docs\examples\tutorials\vs2010 找到"tutorials.sln"。
為了避免改到範例的內容,建議將tutorials資料夾複製到自己想要的位置。
3.用 VS2015 打開"tutorials.sln",選擇 "建置->建置方案",官網上說明應該19個範例都可以編譯成功,但我只成功了14個。檢查code後發現都是缺少某些Win32檔案造成,想嘗試的人或許可以試著用x86的版本試試看。
每個範例的說明網站(Eng),中文。
首先嘗試編譯Gstreamer所提共的19個範例
1.下載Gstreamer的安裝檔,共兩個檔案(下載位置),選擇自己要的版本。
gstreamer-1.0-x86_64-1.10.2
gstreamer-1.0-devel-x86_64-1.10.2
皆選擇完整安裝即可。
2.下載Gstreamer的範例檔(下載位置)
下載回來後可以在 gst-docs\examples\tutorials\vs2010 找到"tutorials.sln"。
為了避免改到範例的內容,建議將tutorials資料夾複製到自己想要的位置。
3.用 VS2015 打開"tutorials.sln",選擇 "建置->建置方案",官網上說明應該19個範例都可以編譯成功,但我只成功了14個。檢查code後發現都是缺少某些Win32檔案造成,想嘗試的人或許可以試著用x86的版本試試看。
每個範例的說明網站(Eng),中文。
2016年9月20日 星期二
centOS無法識別1280x960 解析度的解決方法
在 terminal 中使用cvt生成modeline信息(可以用#cvt -h查看cvt詳細訊息)
#cvt -v 1280 960
terminal 顯示訊息如下:
Modeline "1280x960_60.00" 101.25 1280 1360 1488 1696 960 963 967 996 -hsync +vsync
去掉 modeline 後,接著透過 xrandr 設定解析度
#xrandr --newmode "1280x960_60.00" 101.25 1280 1360 1488 1696 960 963 967 996 -hsync +vsync
#xrandr --addmode VGA1 "1280x960_60.00"
#xrandr --output VGA1 --mode "1280x960_60.00"
搞定~
#cvt -v 1280 960
terminal 顯示訊息如下:
Modeline "1280x960_60.00" 101.25 1280 1360 1488 1696 960 963 967 996 -hsync +vsync
去掉 modeline 後,接著透過 xrandr 設定解析度
#xrandr --newmode "1280x960_60.00" 101.25 1280 1360 1488 1696 960 963 967 996 -hsync +vsync
#xrandr --addmode VGA1 "1280x960_60.00"
#xrandr --output VGA1 --mode "1280x960_60.00"
搞定~
2016年8月11日 星期四
install Mono on ubuntu
install Mono on ubuntu
ref:
http://www.mono-project.com/docs/getting-started/install/linux/#debian-ubuntu-and-derivatives
http://alvin1016.blogspot.tw/2015/03/ubuntunetmono.html
========================================================================
sudo apt-get install mono-complete
sudo apt-get install mono-runtime
# sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
# echo "deb http://download.mono-project.com/repo/debian wheezy main" | sudo tee /etc/apt/sources.list.d/mono-xamarin.list
# sudo apt-get update
get Error :
GPG error: http://hyperrate.com eliu Release: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 5C577D59835AB0E3
# sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 5C577D59835AB0E3
try again
# sudo apt-get update
# echo "deb http://download.mono-project.com/repo/debian wheezy-apache24-compat main" | sudo tee -a /etc/apt/sources.list.d/mono-xamarin.list
# sudo apt-get install mono-devel mono-complete referenceassemblies-pcl
using System;
public class HelloWorld
{
static public void Main ()
{
Console.WriteLine (" Mono Mono ");
}
}
compile
# mcs hello.cs
Run hello.exe
# mono hello.exe
YO~~~~~~~ it's working ~~~~~
ref:
http://www.mono-project.com/docs/getting-started/install/linux/#debian-ubuntu-and-derivatives
http://alvin1016.blogspot.tw/2015/03/ubuntunetmono.html
========================================================================
sudo apt-get install mono-complete
sudo apt-get install mono-runtime
# sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
# echo "deb http://download.mono-project.com/repo/debian wheezy main" | sudo tee /etc/apt/sources.list.d/mono-xamarin.list
# sudo apt-get update
get Error :
GPG error: http://hyperrate.com eliu Release: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 5C577D59835AB0E3
# sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 5C577D59835AB0E3
try again
# sudo apt-get update
# echo "deb http://download.mono-project.com/repo/debian wheezy-apache24-compat main" | sudo tee -a /etc/apt/sources.list.d/mono-xamarin.list
# sudo apt-get install mono-devel mono-complete referenceassemblies-pcl
=======================================================================
testing mono (hello.cs)using System;
public class HelloWorld
{
static public void Main ()
{
Console.WriteLine (" Mono Mono ");
}
}
compile
# mcs hello.cs
Run hello.exe
# mono hello.exe
YO~~~~~~~ it's working ~~~~~
2016年7月5日 星期二
CentOS 變更開機順序
因為安裝雙系統的關係,所以,開機選單是由 Linux 的 Grub 來控管。
1.編輯Grub檔案決定開機順序(需要root權限)
sudo vim /boot/grub/grub.conf裡面最關鍵的兩行
default=0(預設的開機選項)
timeout=5(開機選單到數的秒數,在這裡設定為5秒)
至於 "default=0" 所代表的意思為設定第0個選項為預設開機選項。
舉例來說,進到 grub.conf 檔案後可以看到
title CentOS (xxxxx)
title windows (xxxxx)
title other (xxxxx)
其中 "CentOS"就是第0項,windows為第1項,以此類推
訂閱:
文章 (Atom)