Showing posts with label note. Show all posts

grant group access on git server repository

關於 Linux 檔案群組存取權限的設定,有很多不同的方式可以完成。
我個人懶,目前團隊也還不需要過於複雜的控管,僅以以下方式設定。

$ mkdir [git-repos]
$ chgrp group_name [git-repos]
$ chmod g+rwxs,o+rx . [git-repos]
$ setfacl -m d:u::rwx,d:g::rwx,d:m:rwx,d:o:r-x [git-repos]


ubuntu: PPA & apt howtos

add ppa source

使用 ubuntu 好些時間,今天才花了點時間了解 PPA (Personal Package Archive) 的用法。

$ sudo add-apt-repository ppa:ppa_user/ppa_name
$ sudo apt-get update
$ sudo apt-get install


To make add-apt-repository use port 80 by default

公司有防火牆,在取得 gpg key 時老是無法連線,從這裡看到了解法。

Edit /usr/share/pyshared/softwareproperties/ppa.py
Search "keyserver.ubuntu.com"
Replace it by "hkp://keyserver.ubuntu.com:80"



apt-build
不一定要用swiftfox,如果你有 apt-build 這個程式,也可以自己在家裏面自己編譯最佳化的firefox。
sudo apt-get install apt-build

安裝好之後會問你CPU資訊以及你要強化到什麼程度(英文的訊息) 接著安裝
sudo apt-get build-dep firefox

這會安裝要編譯firefox的相關套件, 然後就可以
sudo apt-build install firefox --reinstall

這樣子就會從原始碼開始下載,並且針對你的電腦進行最佳化編譯。

不使用密碼的SSH連線 - ssh-keygen

ref: http://slv922.pixnet.net/blog/post/26419814

A電腦 192.168.1.1- 要被連線的主機
B電腦 192.168.1.2- 使用SSH連線到A電腦的主機

小明 在 A主機 有一個使用者帳號 A_min
在 B主機 有一個使用者帳號 B_min

  • 環境設定 - A主機

    # vi /etc/ssh/sshd_config

    RSAAuthentication yes
    PubkeyAuthentication yes
    AuthorizedKeysFile .ssh/authorized_keys
    PasswordAuthentication no (如果不想讓使用者使用密碼登入的話再設定)

    # service sshd restart

    .
  • 步驟一 - 於B電腦使用ssh-keygen 產生 兩把金鑰
    B電腦

    [B_min@B電腦 ~]
    $ ssh-keygen -t rsa

    (按三下Enter 不用設密碼)
    會在 /home/B_min/.ssh/ 目錄下產生2個檔案: id_rsa , id_rsa.pub
    .
  • 步驟二 - 將 B電腦產生的 id_rsa.pub 上傳到 A電腦的 A_min家目錄底下 (什麼方法都可以只要你把它放進去就對了)

    [B_min@B電腦 ~]$ cd ~/.ssh
    [B_min@B電腦 .ssh]$ scp id_rsa.pub A_min@192.168.1.1:~/


    關鍵的步驟三:接下來要在A主機上操作了,用SSH連線或是直接在A主機上操作,隨意!

    A主機

    [A_min@A電腦 ~]$ cd ~/.ssh
    [A_min@A電腦 .ssh]$ cat ../id_rsa.pub >> authorized_keys
    [A_min@A電腦 .ssh]$ chmod 644 ~/.ssh/authorized_keys

    .
  • 驗證

    [B_min@B電腦 ~]$ ssh A_min@192.168.1.1
    Last login: Fri Feb 27 21:40:00 2009 from 192.168.1.2

    .
恭喜你不用密碼登入囉

---
Windows Client - B電腦是Windows Client的話...

需要工具軟體:PuTTY , PuTTYgen 下載

金鑰產生方法
使用PuTTYgen產生金鑰

Generate > 滑鼠亂動進度列跑跑跑(很有趣XD) > 金鑰演算完成

Save Public Key > 存檔 → 步驟一的 id_rsa.pub
Save Private Key > 存檔 → 步驟一的 id_rsa


阿接下來就跟步驟二之後一樣,把id_rsa.pub丟到A電腦上的A_min帳號....自己看著辦

PuTTY使用金鑰連線方法

很簡單只要設定一個地方
設定畫面 > Connection > SSH > Auth
將key的位置放入Private key file for authentication
填好連線主機IP就Open吧

login as:A_min
Authenticating with public key "imported-openssh-key"

用誰登入就看你把id_rsa.pub丟到誰家
因為我們範例裡面丟到A_min家,當然是用A_min的帳號來連線

---
使用 ssh X-Forwarding

$ ssh -x ip_address

compile a kernel on ubuntu way

使用 Ubuntu/MacOS 一段時間了,逐漸習慣把系統管理雜事丟給 OS 去處理,專注於自己的工作開發,也比較不盲目追求 kernel 的版本更新。

近來使用 LTP 時遇到自行編譯 Ubuntu kernel 的需求,總手動編譯、複製檔案與修改 grub.cfg。猜想 Ubuntu 應該有更方便的工具用來包 kernel.deb 檔,求助 google 大神後看到 kernel-package 這個套件,以及相關的 scripts。

科技果然來自人性,重複煩雜的工作就應該丟給電腦去自動化處理。

操作大致參考 How to compile a kernel on Ubuntu 10.04

簡單紀錄如下:

install necessary packages for building kernel image
sudo apt-get install fakeroot kernel-wedge build-essential makedumpfile kernel-package libncurses5 libncurses5-dev

get kernel source tree
download from kernel.org
tar jxvf kernel-x.x.x.tar.bz2
cd kernel-x.x.x
or
sudo apt-get install linux-source
tar jxvf /usr/src/linux-source-x.x.x.tar.bz2
cd linux-source-x.x.x

start with the same .config ad the currently running kernel
make oldconfig
make menuconfig
or
cp -vi /boot/config-'uname -r' .config
make menuconfig

packing debain kernel package using kernel-package
sudo fakeroot make-kpkg clean
sudo fakeroot make-kpkg --initrd --append-to-version=-ltp kernel-image kernel-headers
--initrd create a image package suitable for initrd

install customized kernel
cd ..
sudo dpkg -i linux-image-x.x.x-ltp.deb
sudo dpkg -i linux-headers-x.x.x-ltp.deb

generate initrd to your kernel image
find the forder name to your kernel modules
ls /lib/modules
sudo update-initramfs -c -k x.x.x-ltp

add the initrdfs image to the grub.cfg
sudo update-grub

now, just reboot!
your new kernel should automatically load.
uname -r


下篇來寫寫 Linux Test Project 的簡單心得

stupid mistake/bugs

近來寫程式前總在腦中先模擬完整個程式的架構、演算法以及可能的最佳化方式。
為了最佳化執行效率,macro/inline function/function pointer/... 最近也用得兇!
好處是使用得當的話,程式效率會提高不少;缺點則是在 debug 時難找出問題~

說到 debug,最近鮮少遇到程式邏輯構思錯誤的情況,大多數時間反而花在一些很愚蠢小地方的 bug。
以下列出兩條出錯的程式片段,提點自己別再犯!

if (a = NULL) {
    ...;
}
== 打成了 = ,條件判斷變成 assignment。
這已經是近來第二三次犯這種錯了,謹記!

uint32 x = 0, y = 10;
for(y; y >= x; y--) {
    ...;
}
unsigned integer 減到小於零,segmentation fault!


兩個錯誤都是耍蠢的基本錯誤,剛好犯錯的地方都是在邊界條件判斷,
要重建出錯環境不容易,為此還寫了一大段程式來測試,也算有收穫。
果然程式、專案的成熟度,取決其測試環境的成熟度!

這樣的錯平時也許不會犯,專案越趕反而越容易出搥在不該犯錯的地方,
寫篇網誌記錄一下,下次不能再犯!

OSDC.tw 2010 note


週末第一次參加了 OSDC.tw,台灣 OpenSource 社群中活躍的高手都現身了。
聽完兩天的議程,深深發覺還有許多該加強的部份。
另外就是該趕快找個有趣的專案,進行開發。

fred 提到的 eServ 模組化概念很有趣,也來著手進行 eServ modularize 當做練功吧。
摘錄部分筆記如下,後續慢慢補充~


04.24

Less is more - gugod


  • slide tool: http://ingydotnet.github.com/vroom-pm/
  • jQuery is a good API design:
    $(“p”).one(....), bind
  • dsl - domain-specific language
  • DOM API是底線..非常煩瑣 不好的API
    document.getElementById(“foo”)
    jQuery: $(“#foo”)
  • Good API: consistency is everything
    jQuery for example
    $(“noun”).verb(arg,arg1...,callback)
  • Programming is a process that: code<->document switching...


Programming Android Application in Scala - Brian Hsu


  • lecturer’s blog: http://bone.twbbs.org.tw/blog/
  • From wiki: To the JVM, Scala code and Java code are indistinguishable. The only difference is a single extra runtime library, scala-library.jar
  • ASE: android scripting language
    problem: runtime exception is bugging...
  • Scala: a postfunctional pl on JVM, compile to JVM .class bytecode
  • REPL, Scripting, Compiling...
  • Steps:
    scalac test.scala
    java -cp xxx.jar Sample
  • SBT: simple build tool for scala: http://code.google.com/p/simple-build-tool/
  • android-plugin: http://github.com/jberkel/android-plugin


Designing Website for Mobile Safari - hlb


  • lecture’s link: http://note.iamhlb.com/talks
  • minimize input, maximize output
  • focus on first function (don’t waste on secondary func)
  • native != best solution
  • html5 game, the js API is very good for example
    http://www.kesiev.com/akihabara/
  • http://bingo.handlino.com/machines/3586
  • http://www.quirksmode.org/compatibility.html
  • touch panel finger sensitivity zone: 50x50 pixels
  • use css animation instead of JS animation


eServ - jserv (0xlab)




04.25

Nonhierarchical OOP - Shawn M Moore



AnyMQ: Scalable and Simple Message Queues in Perl - clkao / K-9



SVG-based Application Development - 李圭烽/蔡志展/黃昭龍




0xdroid -- community-developed Android distribution by 0xlab - jserv (0xlab)



similar projects: android,android-x86,rowboat,cyanogenMod,OESF,ODroid
「0xdroid -- community-developed Android distribution by 0xlab」簡報上線
演講:0xdroid -- community-developed Android distribution by 0xlab


notes survey
OSDC.TW 2010 - Day1 by 邁向偉大航道的旅程
http://blog.chhsu.org/2010/04/osdctw-2010-day1.html
OSDC Taiwan 2010 Notes by Pedaling Upwards
http://tinyurl.com/3yv2fry
OSDC (Open Source Developers' Conference) 2010 筆記整理
http://tinyurl.com/3ytt729

Linux tips surf

ubuntu 8.10 下使用 IBM USB keyboard with UltraNav

買了 IBM USB Keyboard with UltraNav, 為了在 linux 下中鍵滾輪可以正常使用, 上網找了些資料
ubuntu 8.10 以後 X Server 透過 HAL 偵測並驅動硬體, xorg.conf 有些不再適用.

lshal | grep Touch
info.product = 'Synaptics Inc. Composite TouchPad / TrackPoint' (string)

sudo vi /etc/hal/fdi/policy/mouse-wheel.fdi


更詳細的說明, 還請 google ibm whell ubuntu
ref: http://tinyurl.com/78r7j4

ubuntu 下配置 VM bridge 上網

出處: http://tinyurl.com/5ve72w

Ubuntu下配置 VM 的bridge上網方式, 這種方式的優點是:外部主機可以直接訪問guest系統

步驟如下: (以下命令均用root用戶執行)

1. 安裝uml-utilities和bridge-utils和,這兩個工具分別含有tunctl和brctl命令
apt-get install uml-utilities bridge-utils

2. 生成一個新的TAP接口
tunctl -t tap1 -u

這裡是你想用bridge聯網方式啟動VirtualBox的那個用戶的用戶名
比如我的是: tunctl -t tap1 -u ypxing

3. 生成一個叫做br0的bridge
brctl addbr br0

4. 把你的真實網卡設成promiscuous模式,使得它能夠接收發送到別的MAC地址的幀
ifconfig eth0 0.0.0.0 promisc

5. 把你的真實網卡加到bridge br0的一端
brctl addif br0 eth0

6. 把你的真實網卡的配置設置到br0上, 比如我的eth0的ip地址是192.168.168.60
ifconfig br0 192.168.168.60
如果你的是通過DHCP配置的,則執行dhclient br0即可

7. 把上面生成的TAP接口加到 bridge br0的另一端
brctl addif br0 tap1

8. 激活TAP
ifconfig tap1 up

9. 設置/dev/net/tun的讀寫權限
chmod 0666 /dev/net/tun