顯示具有 General Programming 標籤的文章。 顯示所有文章
顯示具有 General Programming 標籤的文章。 顯示所有文章

2021年7月28日 星期三

Dev Tips - command line snippets

 

Command - equal to ldd

objdump -p <path/to/program> | grep -i needed

Command - while loop with date and sleep

while [ 1 ] ; do date +"%M:%S" ; sleep 1 ; done

Command - cp

merge one folder to another folder

if file exists in dummy_tmp, it will replace by file in origin_tmp

$ cp -RT origin_tmp/ dummy_tmp/
$ diff -ur dummy_tmp origin_tmp

2021年7月14日 星期三

Bash Tip - date 日期指令轉換 unix epoch time 範例

 

Command - date

Example 1 date - convert unix epoch timestamp to date string

$ date  --date='@1617694020'
Tue 06 Apr 2021 07:27:00 AM UTC

Example 2 date - convert unix timestamp to custom formatted date string


$ date +"%Y-%m-%d %H:%m" --date='@1617694020'
2021-04-06 07:04
$ date  --date='@1617694020.904'
Tue 06 Apr 2021 07:27:00 AM UTC

Example 3 date -- MacOS Mojave convert timestamp to date string


## MacOS Mojave not support --date
$ date  --date='@1617694020.904'
date: illegal option -- -
usage: date [-jnRu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ...
          [-f fmt date | [[[mm]dd]HH]MM[[cc]yy][.ss]] [+format]
## use -r to instead
$ date -r 1625043610 +"%Y%m%d %H:%M:%S"
20210630 17:00:10

2021年1月21日 星期四

bash tips - 使用部分執行檔名來發出終止程式指令 terminate processes by partial process name

在 Linux 系統中,時常會遇到需要終止執行中的程式,如果只有單一執行檔程式執行多個 Instances 時,可簡單使用下列指令例如:

killall <process name>

但若是有多個 prefix 相同的程式就要分別指定

killall test_a test_b test_c

為了方便使用,初步寫一版可使用部分執行檔來終止程式的腳本,下例腳本是使用以下 /bin/sh 測試:

  • busybox v1.31
  • dash 0.5.8-2.10

Script example


#!/bin/sh
pname="$1"
if [ "x$pname" = x ]; then
echo "syntax: <partial process name>"; exit 1 ; fi
ps -a | grep "$pname" | \
grep -v grep | \
sed -e "s/^[ ]*\([0-9][0-9]*\) .*$/\1/g" | \
while read pid ; do kill $pid ; echo "terminate $pid" ; done

 Test output

~$ sleep 86400 &
[1] 2824
~$ sleep 86402 &
[2] 2832
​
sh 加上 -x 可除錯執行


~$ sh -x terminate_pname.sh sleep
+ pname=sleep
+ [ xsleep = x ]
+ ps -a
+ grep sleep
+ grep -v grep
+ sed -e s/^[ ]*\([0-9][0-9]*\) .*$/\1/g
+ read pid
+ kill 2824
+ echo terminate 2824
terminate 2824
+ read pid
+ kill 2832
+ echo terminate 2832
terminate 2832
+ read pid
[1]- Terminated              sleep 86400
[2]+ Terminated              sleep 86402
​

參考文章


2020年9月11日 星期五

Bash Tip - 單行取得目前腳本檔絕對路徑的方法

Bash Tip - 單行取得目前腳本檔絕對路徑的方法

_t="${0%%`basename $0`}"; cd "$_t" ; sh_abs_path=`pwd`; echo "$sh_abs_path"

執行範例

  • 先將上列單行指令寫入到檔案
## 建立測試目錄
~$ mkdir -p /tmp/abspath_demo
## 將單行指令寫入到 demo.sh
~$ echo '_t="${0%%`basename $0`}"; cd "$_t" ; sh_abs_path=`pwd`; echo "$sh_abs_path"' >  \
   /tmp/abspath_demo/demo.sh

  • 執行 demo.sh
~$ sh "/tmp/abspath_demo/demo.sh"
/tmp/abspath_demo

2019年6月29日 星期六

Bash Tip - Why .bashrc (dot bashrc) not loaded after new user created?


Recently, I reinstalled ubuntu 16.04LTS on my desktop as a Linux server.

After a new user created, ssh into the server each time, but .bashrc (dot bashrc) not loaded after new user created? Please try to modify the profile as bellow.

Append some commands into ~/.profile

result of test-cases.sh example

~$ source .profile
load /home/ben/.bashrc by ~/.profile
.bashrc has been executed once

Appendix


2019年3月14日 星期四

Bash Tip - Run Command with multiple arguments with ssh




This is a note for logging my simple way to use ssh and bash with continuous integration on remote server.

You can execute the following test-cases.sh on your host.

It will execute remote script of the test with correct argument contents.

source code of test-cases.sh on host





directory layout of tester account on test-server



source code of tests.sh on test-server




result of test-cases.sh example

source ./test-cases.sh
➜  ~ run_cases "\"1\"\"" "b'\"" "c'#\"" "\"\"" "\'"
ssh test-server cd test-cases; /bin/bash ./tests.sh  "\"1\"\"" "b\'\"" "c\'\#\"" "\"\"" "\\'"
argv[1]=["1""]
argv[2]=[b\'"]
argv[3]=[c\'\#"]
argv[4]=[""]
argv[5]=[\\']

Notes

printf %q  is use to make safe quote the argument if hashtag(#), quote('), double quote(") and so on.

Appendix



2019年2月22日 星期五

Bash Tip - Use bash to implement like C's argc and argv

Test bash script capacity

I want to show how to write the advanced bash script with shift and array.
Feature:

  • filter the arguments with '-' leading character as options
  • the following inputs are the data arguments


Tested environments: - bash 4.3.48 x86_64-pc-linux-gnu ubuntu-16.04.4 LTS

2013年4月26日 星期五

初探 ﹣ 驗收測試驅動開發 (ATDD)






記得去年在JuluOSDev 與 Tossug 合辦聚會活動,曾探討了Tdd with python unittest for embedded c 這個主題,非常多朋友熱情參與。

最近這一段時間,筆者又接觸到ATDD (Acceptance Test-Driven Development),
之前大略看了,最近再花些時間研讀,溫故知新一下。

其中主要差異在於TDD 針對單元測試,
而 ATDD 則是對客戶要驗收的需求來實作單元測試。

有個真實小案例:

王小明是一個很盡責的工程小組長,他和小組完成整個程式專案,也都一一通過各成員所撰寫單元測試,整個程式運作穩定正常。

驗收當天,元大頭為主要客戶代表來驗收,交付程式前,產生如下的對話:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

元大頭說:「小明,可以讓我來試試程式符不符合我們的要求。」

王小明很有信心地說:「可以,程式經過我們嚴格的單元測試,目前版本已是穩定版了!」

元大頭試著輸入一些資料,他不小心把網路線弄掉,結果程式跑出一個錯誤,

他皺著眉說:「這是什是意思“Error:ECONNREFUSED”,我看不懂,這是火星文嗎?」

王小明立刻看了一下把線接上,不加思索,直接回說:

「因為網路連不上,網路線鬆掉了,現在接好,您再試試。」

元大頭按下OK後,待重新連線訊息完成,即能正常輸入後,過了一會有些不滿地說:

「咦?剛輸入資料怎麼全不見,小明你不說沒問題嗎?怎麼會這樣!
之前開需求時,不是有提到要讓使用者方便在常用頁快速輸入,也要讓使用者看得懂啊!」

王小明心虛地說:「抱歉!這是我們的失誤,會儘速修正。」
⋯⋯

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

小結:

以上述案例而言,小明的團隊其實有錯誤處理網路斷線的問題(曾見到沒處理的app程式直接閃退),但卻漏掉兩個需求。
  • 易懂的錯誤訊息
  • 常用頁的輸入時,錯誤處理應儘量保持使用者輸入的資料
若使用 ATDD,設法把需求轉成驗收測試單元,再寫程式來通過這些單元測試;
就比較不會發生遺漏使用者需求的情況。當然這個案例只是冰山一角,
ATDD 也不見得是萬靈丹,有任何想法,歡迎一同討論。



參考資料:



2011年12月30日 星期五

阿班私房菜-Design Pattern(DP)初探使用Python (1)


Design Patterns: Elements of Reusable Object-Oriented Software

最近使用Python 寫程式,心血來潮,使用 (DP) 套用看看。
以 Factory worker 為例。
首先建立一個物件Worker 包含姓名、屬性等等。
class Worker:
    def __init__(self, name=None):
        self.name = capfirst(name) if name else "The worker"
    def getName(self):
        return self.name
    def attrib(self):        return "Worker"
    def lookandfeel(self):
        print "%s is a %s" % (self.name, self.attrib())

Designer與Engineer繼承它,並覆寫attrib() Method。
class Designer(Worker):
    def attrib(self):        return "Designer"
class Engineer(Worker):
    def attrib(self):        return "Engineer"

當使用各自物件來建立,並執行lookandfeel() 時,會呼叫各自的attrib method。
以下使用 factory pattern 來實作僱用workers 的容器物件。
# factory pattern
class Factory:
    type_designer = 1
    type_engineer = 2
    def __init__(self):
        self.workers = []
    def employ(self, worker_type, name=None):
        if worker_type == Factory.type_designer:
            self.workers.append(Designer(name))
        elif worker_type == Factory.type_engineer:
            self.workers.append(Engineer(name))
    def workerCount(self):
        return len(self.workers)
    def browse(self):
        for a in self.workers:
            a.lookandfeel()
z = Factory()
z.employ(Factory.type_designer)
z.employ(Factory.type_designer, 'bill')
z.employ(Factory.type_engineer, 'sue')
z.browse()

執行結果:
$ python factory_dp1.py
The worker is a Designer
Bill is a Designer
Sue is a Engineer

承上篇重構一文:我們來重構一下它,並加入singleton pattern(利用@staticmethod 來實作)。
class Factory:
    # class static variable
    type_designer = "1"
    type_engineer = "2"
    _Factoryself = None
    _factorydict = {
           type_designer: Designer,
           type_engineer: Engineer,
        }
    def __init__(self):
        self.workers = []

    @staticmethod
    def singleton():
        if Factory._Factoryself == None:
            Factory._Factoryself = Factory()
        return Factory._Factoryself



    def employ(self, worker_type, name=None):
        caller = Factory._factorydict.get(worker_type)
        if caller:
            self.workers.append(caller(name))
        return None



    def workerCount(self):
        return len(self.workers)

    def browse(self):
        i = 0
        for a in self.workers:
            print " - Worker[%s]:%s" % (i, a.getLookandfeel())
            i+=1

def main():
    f = Factory.singleton()
    f2 = Factory.singleton()
    if f == f2:
        print "* Singleton pattern of Factory"



    print "* Factory pattern to employ"
    f.employ(Factory.type_designer)
    f.employ(Factory.type_designer, 'Bill')
    f.employ(Factory.type_engineer, 'Sue')
    print "* Factory pattern to browse"
    f.browse()
    print "* The factory has %s workers." % f.workerCount()

if __name__ == "__main__":
    main()

小結

使用python 來寫DP程式,功能強大,自由度高;
但這意味,寫其程式時,要有其紀律,遵守一定規範(coding convention)來寫;
不然程式會變得非常難讀及維護。 最近上列範例程式均可在github-class_dp中找到。
上述範例還可進一步,重構或修改為工廠人員管理系統的雛形,留待有興趣的讀者們來添加!

2011年11月30日 星期三

阿班私房菜-重構(Refactoring)的小技巧(1)


最近在看一本書"The Pragmatic Programmer",裡有不少與重構相關的範例,值得參考,有與趣人可以買來看看。因此書,筆者心血來潮,分享一下自己的開發經驗。


在專案開發程式的過程,常會因時間壓力或市場考量,不得不加入很多非計畫中的程式碼。
開發時間越久,就漸漸難以維護,增加新功能更為秏時;當人力不足以達成出貨時程,便開始增加人力,最後日積月累,專案程式變成一個大怪物;直至某一日砍掉重練。


而筆者近年來,使用重構方法,使得自己不用一直為解專案bug而加班。

重構(Refactoring) 英文是一個現在進行式,表示這個動作需要一直不斷發生。


其中,"重構"的最重要的基石就是自動化測試程式,如每當重構程式碼中重覆的部分時,執行一下自動化測試程式,便可很快的確認程式修改後的正確性。

接下來我們來看一些筆者常用的小技巧,以下範例使用Python語言。

def show_animal_info0(animal):
    if animal == 'dog':
        print("The dog has four legs")
    elif animal == 'chick':
        print("The chick has two legs")
    else:
        print("There is an unknown animal")
show_animal_info0("dog")
show_animal_info0("chick")
show_animal_info0("cat")


重構if-else

通常if-else會越加越長,慢慢變得難以除錯。
animal_info_dict = {
        "dog":   "four legs",
        "chick": "two legs"
        }
def show_animal_info1(animal):
    try:
        info = animal_info_dict[animal]
        print("The %s has %s." % (animal, info))
    except:
        print("There is unknown animal")
用dict結構表格取代if-else, 也可用來取代switch


重構重覆呼叫函式

這種函式大部分由copy and paste而來。
show_animal_info0("dog")
show_animal_info0("chick")
show_animal_info0("cat")
def main():
    animals = ["dog", "chick", "cat"]
    for name in animals:
        show_animal_info1(name)
if __name__== "__main__":
    main()

重構屬性
紅色legs部分也是重覆程式碼的狀況之一
animal_info_dict = {
        "dog":   "four legs",
        "chick": "two legs"
        }
def show_animal_info1(animal):
    try:
        info = animal_info_dict[animal]
        print("The %s has %s." % (animal, info))
    except:
        print("There is unknown animal")
animal_info_dict = {
        "dog":   {"leg": "four"},
        "chick": {"leg": "two"},
        "cat":   {"leg": "four"}
        }
def show_animal_info1(animal):
    try:
        info = animal_info_dict[animal]
        legs = info['leg']
        print("The %s has %s legs." % (animal, legs))
    except:
        print("There is unknown animal.")


自動化測試程式

要進行自動化測試,以本範例為例:

1. 將邏輯與資料顯示動作分離

def show_animal_info1(animal):
    try:
        info = animal_info_dict[animal]
        legs = info['leg']
        print("The %s has %s legs." % (animal, legs))
    except:
        print("There is unknown animal.")
def get_animal_info1(animal):
    try:
        info = animal_info_dict[animal]
        legs = info['leg']
        msg = "The %s has %s legs." % (animal, legs)
    except:
        msg = "There is unknown animal."
    return msg

2. 比對預期函式回傳值結果

使用pyunit 來實作自動測試
import unittest
from code_for_automation import *
class DefaultTestCase(unittest.TestCase):
    def testTestDog(self):
        sample="The dog has four legs."
        msg = get_animal_info1('dog')
        assert msg == sample , 'test dog message'
    def testTestChick(self):
        sample="The chick has two legs."
        msg = get_animal_info1('chick')
        assert msg == sample , 'test chick message'
    def testTestCat(self):
        sample="The cat has four legs."
        msg = get_animal_info1('cat')
        assert msg == sample , 'test cat message'
if __name__ == '__main__':
    myTestSuite = unittest.makeSuite(DefaultTestCase,'test')
    runner = unittest.TextTestRunner()
    runner.run(myTestSuite)

3. 統計測試結果
$ python 05_automation.py
...
----------------------------------------------------------------------
Ran 3 tests in 0.000s
OK
以上範例程式均可由tip1下載

結論

當有了自動化測試程式之後,可提高自行重構的信心,又不用花費手動一個個輸入測試的時間。
本文雖以python為例,但觀念是相通的,其他語言也有其自動測試函式庫可供使用,歡迎不吝指教。


2011年9月14日 星期三

Go 程式語言再探

go_webs_qrcode
  從官網中範例程式找到一段Go程式碼WebServer,加入我的編譯腳本檔如下:
GOCC=6g
GOLD=6l
PROJECT=webserver
all: $(PROJECT)
$(PROJECT).6: $(PROJECT).go
        $(GOCC) $(CFLAGS) $^
$(PROJECT): $(PROJECT).6
        $(GOLD) -o $@ $^
run: $(PROJECT)
        ./$^
clean:
        rm -f $(PROJECT).6 $(PROJECT)
當你輸入,make run 時,如果設定無誤(詳設定請參閱Go語言初探),將會啟動一個Web Server 在localhost:1718。
如上圖,筆者輸入本站網址,點按[Show QR],輕輕鬆鬆產生本站QRCode圖像。
結語
短短50行程式碼,其中包含20行網頁腳本,使用掛載flag, http, io, log, template等等套件大幅提高程式生產力。
若要學習Go,不容錯過Effective Go一文。

2011年9月7日 星期三

Go 程式語言初探

from http://golang.org



最近寫多篇與OS開發相關超硬的文章,來學習Go 語言換換口味輕鬆一下吧!參考英文說明,寫了以下心得:

使用平台為Mac OS X 10.6.8 + Xcode 4.2

前言

Go 程式語言是一個開放源碼的專案,以BSD-style授權發佈。
它以通用語言作為系統設計基礎想法。在強調於型別、垃圾回收及明確定義支持Concurrent程式設計的語言功能等等。並提供大量套件 ,提高寫程式效率。目前支援x86及ARM處理器,一個64位元及32位元x86的編譯套件(6g和8g),及支援ARM的編譯套件(5g)。


開發環境設定

安裝 Mercurial (hg)
 sudo easy_install mercurial
(註:easy_install 是python所內附一個好用安裝第三方工具的python腳本)

Mercurial versions 1.7.x 需要設定檔來指定憑證授權 Certification Authorities (CAs). 在筆者機器遇到下列警示訊息:
warning: go.googlecode.com certificate with fingerprint 28:92:... not verified (check hostfingerprints or web.cacerts config setting)

這表示你所使用的Mercurial沒有正確設定CAs. 參考configure the CAs一文,進行設定。
以下是OSX 10.6以上版本的設定

openssl req -new -x509 -extensions v3_ca -keyout /dev/null -out dummycert.pem -days 3650

使用openssl命令建立替代憑證(設定內容隨意打)
接著使用下列指令將dummycert.pem複製到/etc

sudo cp dummycert.pem /etc/hg-dummy-cert.pem

最後在~/.hgrc 或go/.hg/hgrc內容加入下列兩行。

[web]
cacerts = /etc/hg-dummy-cert.pem

下載Go 正式發佈版本源碼


 hg clone -u release https://go.googlecode.com/hg/ go


編譯Go

你將需要安裝Xcode,其中包含GCC, C libraries ...

$ cd go/src
$ ./all.bash
如果沒任何錯誤發生,訊息如下:


ALL TESTS PASSED

---
Installed Go for darwin/amd64 in /Users/you/go.
Installed commands in /Users/you/Go/bin.
*** You need to add /Users/you/Go/bin to your $PATH. ***
The compiler is 6g.

最後幾行顯示你的系統資訊,硬體架構,和所安裝的目錄,你需要將此目錄加到搜尋路徑中。詳請參閱英文文章環境變數environment variables.


使用Go來編譯Hello範例
$ make
6g hello.go
hello.go:2: can't find import: fmt
錯誤發生原因沒有指定環境變數。
筆者指定下列環境變數後,總算編譯成功。

export PATH=~/Go/bin:$PATH
export GOROOT=$HOME/Go
export GOARCH=386
export GOOS=darwin
export GOBIN=$HOME/Go/bin

$ make
6g hello.go
6l -o hello hello.6


執行結果
$ make run
./hello
hello, world


hello 範例可由此下載。

歡迎留言分享心得。

2011年8月25日 星期四

在Cygwin中設定並使用Qemu

mintty_cygwin_qemu
在看完前三篇編繹BOS文章之後,眼尖的讀者,應該有發現在Linux和MAC OS X平台都是使用qemu 來執行;可是一到Windows 怎麼變成VMWare Player呢!其實筆者曾試著編繹cygwin版的qemu, 卻有太多問題要解決,為求效率;使用其他虛擬機軟體來代替。
這篇算是補完"自製開發BenOS支援Windows+Cygwin"一文。

1. 下載所需qemu工具

在使用谷歌大神後,Qemu.org的友站連結中的非官方版已預先編繹好的程式,找到qemu 0.13版,由此下載 。(感謝他的分享,筆者少花數小時生命。)


2. 安裝Qemu
在下載完qemu-0.13.0-windows.zip後,將它解壓縮到cygwin安裝目錄中。
就筆者環境來說,路徑為C:\cygwin\usr\local\qemu
3. 開啟cygwin命令視窗
加入下列指令到 /etc/bash.bashrc
export PATH=/usr/local/qemu:$PATH
4. 重新開啟cygwin命令視窗
下載最新版bos,執行下列指令,便可看到如上所示執行畫面:
make run
本次在程式碼的編繹腳本修改所使用命令為qemu,主因是此版本qemu-system-x86_64.exe無法正常運作,但qemu卻是正常工作。
@@ -9,7 +9,7 @@ endif
all: run
run:
-ifeq ($(KNAME),CYGWIN)
+ifeq ($(KNAME),$(KNAME_CYGWIN))
        qemu -fda "$(IMG_NAME)"
else
        qemu-system-x86_64 -boot a -M $(MACHINE) -fda "$(IMG_NAME)"
結語

筆者歸納了最近使編繹流程跨平台的經驗,列出幾點供大家參考:
  1. 先到網上花5分鐘找看看,有無編繹好的開發用軟體;
  2. 如果沒有,看看有無編繹經驗分享,
  3. 也無經驗分享,最後才是自己編繹一版。
保持分享的美德,把編繹好的工具,公布出來。如此一來,基於眾人成果,大家互相會受益於時間成本的大大縮短。
當然這也筆者撰文的原因之一。

註:此次報名網址已建置好,請由此報名9/6星系主題活動。

更新0825

Dennis 有提出:
我覺得應該找qemu for win32, 用vc++或mingw compile。因為cygwin有些posix api模擬,並沒有做得很好,用native win32 api比較順。而且我很久以前有試過這個 http://www.h7.dion.ne.jp/~qemu-win/ ,它應該可以work。

ben 想:
不過這個qemu-win網址編繹的版本0.9.0有點老而且已停止更新,其實我文章中所用Qemu 可能同一人所維護,只是文中使用連結是較新的版本。若要最新版本,需要的人就要自行編繹了。


2011年8月23日 星期二

在Mac OS X上編繹BenOS並使用Qemu執行

bos_run_at_osx

續上篇自製開發BenOS支援Windows+Cygwin後,發現Mac上的使用者(當然筆者也是其中之一,不才也是半個蘋果迷)也想能直接編繹(另一個原因是,不想再開另一個Linux 虛擬機,太耗資源及電力,環保一下吧),於是乎有了這篇文章。

編繹環境設定

筆者的Mac 是Snow Leopard 10.6.8

1. 安裝Xcode

到http://developer.apple.com/下載並安裝Xcode (筆者用的是4.0.2)

2. 安裝HomeBrew

請參考把常用的UNIX 環境重建到MAC OS X (1) 一文。

3. 使用brew 安裝 nasm 和qemu

sudo brew install nasm qemu git

4.安裝cross gcc

測試使用Xcode 的gcc,並發現不能做完整靜態連結。也不能輸出ELF檔案。

正想把最後殺手鐧拿來,自己編繹gcc時,心血來潮google 一下,

發現下列的站台,有專門編繹給Mac OS X,二話不說,馬上拿來用,節省不少時間。

可從此處下載http://crossgcc.rts-software.org/doku.php

dmg 安裝至目錄

gcc-4.5.2-for-linux32.dmg (65.2 MB)

/usr/local/gcc-4.5.2-for-linux32/
gcc-4.5.2-for-linux64.dmg (71.7 MB) /usr/local/gcc-4.5.2-for-linux64/

筆者安裝是64位元版,但在編繹時需要加上-m32, 因為目前bos 尚未相容64位元模式。

5. 安裝mtools

在編繹過程,只有一個小問題,便是找不到iconv,極可能是script 的bug,加上-liconv,即可通過編繹。

另外為求保險,去除不必要的變數,故加上-arch i386,產生mtools i386 版。

env CFLAGS="-arch i386" LDFLAGS="-arch i386 -liconv" ./configure
make
sudo make install

結語

如此一來,便可在OSX上編繹及執行,可參考開頭畫面。

再則,感謝google 大神,讓我能省去編繹 toolchain時間。相對windows 來說,Mac OS X 對Unix-like開發者,較為友善。

然後,到本文筆者便寫完三個主要平台的OS開發環境Linux、Windows、OSX上設定。

希望對大家有所幫助,少走一彎路。

最後,筆者因為以前工作屬工友級,所以需要什麼,就學什麼。

想請問大家最常使用什麼平台和工具來進行程式開發呢?

說不定有更好的組合提高您的生產力;一人技窮,二人技長;快提出來大家討論,集思廣益吧。

註一:下次的大聚會9/6,有重量級的OS長老駕到,可來吸收一甲子功力,請大家踴躍參加。

註二:此次9/6活動已加入TOSSUG行程(請參閱http://www.tossug.org/2011)

2011年8月17日 星期三

自製作業系統 BenOS 原始碼公佈

bosv0dot2
最近把自製作業系統原始碼整理一下並修正部分問題,另附寫說明文件後,於今晚,發佈Ben OS v0.2,有興趣的朋友可從GitHub下載原始碼。
程式碼目前已在下列平台編繹並使用Qemu測試:
  • Ubuntu 10.04, 10.10, 11.04
  • Fedora 12
程式目錄說明
apps 應用程式,目前只有一個 bshell
blibc BOS用到的自製的C函式庫
boot 啟動程式
include 標頭檔案
kernel 系統核心相關
lib 核心相關函式庫
scripts 系統開發腳本檔
test 執行測試用
tools 預留工具程式
如何編繹請參閱?
Readme.md
Ubuntu + Qemu在VMWare Fusion Mac問題?
bosv0dot2-howtoquit
當Qemu執行時,跳離的快速鍵將會失效,造成無法正常使用Xwindow,可使用CTRL+ALT+2回到qemu monitor console,再輸入 "quit" + Enter 鍵離開Qemu 視窗。
BOS v0.2 編繹已不需要管理權限?
原來使用mount 磁片檔方式需要管理權限,現已修改為使用 mcopy (mtools)。(感謝社群成員Dennis 提供建議)
註:下次社群活動09/06/2011,詳請參閱社群首頁。
更新0821

2011年6月10日 星期五

新思維:讓來自世界各地的程式設計師,用GitHub 協同開發閉源程式!

姓名標示非商業用途授權分享 orkboi保留部分權利


今天看了37 Signals 的一篇原文有關於使用GitHub 來進行不限地域的Rails 開發工作的新思維。

你將需要全球性的程式碼版本代管服務來使全球員工可協同來開發程式,而經濟實惠的解決方案之一:GitHub 計畫與價格 
1. 開源的專案免費。
2. 入門級私人使用方案為每月7美元。(相對於自行架設要便宜不少。)
    看到這裡你是否有安全方面的疑慮呢?可參考GitHub的安全防護資訊。

另外看了37 Signals 求職版 (不限地區搜尋結果) ;多家公司要求你必須使用GitHub 且有一個開源的展示專案在上面;進而可評估你的程式設計能力符合要求;以及你對GitHub 的熟悉程度來決定是否僱用?

各路高手有興趣和來自世界各地的程式設計高手用GitHub 協同開發嗎?
趕快申請開源帳號來試試,建立自己第一個開源的"Hot"專案吧!!!


2011年6月6日 星期一

你是要加班當程式Bug 產生器吧!!!


Image from jef safi 姓名標示非商業用途謝絕衍生作品 保留部分權利 
常聽到公司同事說今天要加班趕程式,但我戲稱:"你是要加班當程式Bug 產生器吧!?"。

其實,現在公司常要程式設計師以責任制方式工作,但早上上班打卡,晚上做到爆肝。
按本人過去新人時的經驗,過了晚上七點,在連續八~九個小時腦力工作和會議後,這時寫程式會用最直覺方式去寫,一個函式會無識意寫得過長,共用部分也沒獨立為其他函式,註解自動省略(因為累了吧!!!)。然後,隔天早上一看昨晚寫的程式,直呼"這是啥鬼東西",只有基本函式功能正確,例外部分都沒處理完整,錯漏不斷;
而難以偵錯,也無法重覆使用一些共用程式碼函式。結果前晚三小時寫的程式,隔天花了三小時來修bug。

本人的一些小建議:
第一:好好安排在一天中你的精神最好時候來寫程式。(與時間管理有關,參考相關書籍。)

第二:程式本身也需要多些測試程式來自動檢查你的函式,這會讓你有信心來重構讓程式愈來愈好,當然也減少偵錯時間。例如:若要寫API,便對應寫API的測試程式(測試驅動開發TDD:Test-driven programming)

第三:累積功夫,自己的函式庫(如有現有函式庫可直接採用最好),我曾從程式前輩學到一句話"凡看過寫過,必留下紀錄",至今我還繼續保持這紀錄的習慣(Blog 也算其中之一)。

第四:勿當工作狂,除工作外;多些時間陪陪家人,家人是要在一起相處一輩子,且小孩的成長黃金時期需要父母雙方的照料才得以健全。


2010年2月8日 星期一

在 MAC OS X中,使用msgget() ENOSPC錯誤

如果你使用 msgget() 函式時, 你必須清楚瞭解到預設值為40。
你可使用使用 'ipcs -q' 指令來查看目前message queue 的當前狀況。

假如沒有處理好使用完的queue之回收,你的msgget()將會回傳 ENOSPC錯誤

原文為 
"message queue has to be created but the system limit for the maximum number of message queues would be exceeded"

意思是"已超過系統上限。"

你可使用 msqctl來移除未被正確移除的queue。