2014年10月29日 星期三

docker auto remove container after running

$ docker run --rm
--rm=true|false
 Automatically remove the container when it exits (incompatible with -d). The default is false.



References :

2014年10月27日 星期一

IE Javascript Array.indexOf() error

if (!Array.prototype.indexOf) {
Array.prototype.indexOf = function(elt, from) {
var len = this.length >>> 0;
var from = Number(arguments[1]) || 0;
from = (from < 0) ? Math.ceil(from) : Math.floor(from);
if (from < 0) from += len;
for (; from < len; from++) {
if (from in this && this[from] === elt) return from;
}
return - 1;
};
}




References :
[JS] IE 的 JS 陣列不可使用 indexOf() - 楓葉筆記本- 點部落 

javascript function argument default value

function func(a,b){
    if(typeof(a)==='undefined') a = 10;
    if(typeof(b)==='undefined') b = 20;
    alert("A: "+a+"\nB: "+b);
}
//testing
func();
func(80);
func(100,200);




References :
default argument values in javascript functions - Stack Overflow

2014年10月25日 星期六

Linux CPU fan speed control

Controlling fanspeeds in Linux on PWM motherboards, Thinkpads and ASUS Eee PC | tjansson.dk

install ibus input method for Chinese 安裝 ibus 中文輸入法

# apt-get install ibus ibus-chewing im-config

No outputs have backlight property

$ xbacklight -dec 10
No outputs have backlight property


try the option on boot :
acpi_backlight=vendor
or

video.use_native_backlight=1

 


References :
https://bbs.archlinux.org/viewtopic.php?id=177616
https://wiki.manjaro.org/index.php?title=Optimized_power_settings

debian / ubuntu sources list generator

Debian :
http://debgen.simplylinux.ch/

Ubuntu :
http://repogen.simplylinux.ch/

debian install chinese fonts

# apt-get install fonts-arphic-ukai fonts-arphic-uming fonts-ipafont-mincho fonts-ipafont-gothic fonts-unfonts-core




References :
Help:Multilingual support (East Asian) - Wikipedia, the free encyclopedia

shell script callback function

myfunc() {
    str=$1

    echo $str
}

callback_handler="myfunc"                                                                                                                  

if [ "$callbak_handler" != "" ]; then
    eval $file_handler asdfghjkl
fi




References :
Friends don't let friends program in shell script | TurnKey GNU/Linux Blog

2014年10月24日 星期五

shell script handle signal

my_signal_handler() {
    echo '....'
}

trap 'my_signal_handler' EXIT HUP TERM INT




References :
Work the Shell - Dealing with Signals | Linux Journal

shell script kill subprocess when exit

jobs=()
trap '((${#jobs[@]} == 0)) || kill ${jobs[*]} ; exit' EXIT HUP TERM INT
subscript1 & jobs+=($!)
subscript2 & jobs+=($!)
 
 
 
 
References :
zsh - Killing subprocesses after the script has finished or is killed - Unix & Linux Stack Exchange

append value to bash array

ARR=()
ARR+=(1)
ARR+=(2)




References :
Bash: add value to array without specifying a key - Stack Overflow

inotifywait background job pid

jobs=()
(echo "$BASHPID" > pid-file; exec inotifywait -m ...) | while IFS= read -r...
jobs+=(`pid-file`)
 
 
 
 

pipe out to shell script function

References :
Pipe output to function - Bash | Unix Linux Forums | Shell Programming and Scripting

git delete remote branch

$ git push origin --delete 





References :
github - How to delete a Git branch both locally and remotely? - Stack Overflow

2014年10月23日 星期四

2014年10月22日 星期三

irssi hide join part messages

/ignore #channel_name JOINS PARTS QUITS
/save

忽略所有系統訊息:
/ignore #channel CRAP NOTICES SNOTES CTCPS JOINS PARTS QUITS KICKS MODES WALLOPS NICKS DCC DCCMSGS CLIENTNOTICES CLIENTCRAP CLIENTERRORS HILIGHTS

套用至多個 channel:
/ignore -channels #roomA,#roomB,#etc * JOINS PARTS QUITS NICKS




References :
Hide join part messages - XKCD Wiki
LoCoDays/JoiningIn - Ubuntu Wiki
Irssi hacks | fossline

允許 systemd 將 acpi 事件轉交給其他程式處理


# vi /etc/systemd/logind.conf
# 讓 systemd 不處理 acpi 事件
HandlePowerKey=ignore
HandleSuspendKey=ignore
HandleHibernateKey=ignore
HandleLidSwitch=ignore
# 允許 acpi 事件轉交給其他程式處理
PowerKeyIgnoreInhibited=no
SuspendKeyIgnoreInhibited=no
HibernateKeyIgnoreInhibited=no
LidSwitchIgnoreInhibited=no
# vi /etc/rc.local
exec systemd-inhibit acpid
# reboot




References :
Arch Linux:使用systemd管理系統與服務 | 二三事
混乱的笔记本电源管理 (页 1) / 笔记本及其他便携设备 / Arch Linux 中文论坛


Bugs: lilyterm - The data got from socket seems incorrect

The data got from socket seems incorrect
The format of socket data is out of date

temporary solution
$ lilyterm -s




References :
不能开多个lilyterm · Issue #55 · Tetralet/LilyTerm

2014年10月21日 星期二

Mounting a hard disk image with partitions

$ file mydebian.img
mydebian.img: DOS/MBR boot sector

$ fdisk -l mydebian.img

Disk mydebian.img.141022: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 cylinders, total 83886080 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00094e94

                   Device Boot      Start         End      Blocks   Id  System
mydebian.img.p1            2048    81790975    40894464   83  Linux
mydebian.img.p2        81793022    83884031     1045505    5  Extended
mydebian.img.p5        81793024    83884031     1045504   82  Linux swap / Solaris
$ mount -o loop,offset=$((2048 * 512)) mydebian.img /mnt




References :
Mounting a hard disk image including partitions using Linux | andremiller.net
Loop-mounting partitions from a disk image

2014年10月18日 星期六

X lock screen

xscreensaver :
  • run in normal user



install
# apt-get install xscreensaver
run xscreensaver
$ vi .xinitrc
$ xscreensaver -nosplash &
lock screen
$ xscreensaver-command -lock
 
 
slock : 
  • minimal screen locker
  • type your password directly 
 
# apt-get install suckless-tools
$ slock




References :
lock screen in wmii (Page 1) / Applications & Desktop Environments / Arch Linux Forums
DWM auto lock after inactivity (Page 1) / Applications & Desktop Environments / Arch Linux Forums

run X11 GUI application in docker


$ docker run -ti --rm -e DISPLAY=$DISPLAY.0  -v /tmp/.X11-unix:/tmp/.X11-unix -v $HOME/.Xauthority:/root/.Xauthority --net=host myimage xterm

add alias to .bashrc
$ alias dockerx11run='docker run -ti --rm -e DISPLAY=$DISPLAY.0 -v /tmp/.X11-unix:/tmp/.X11-unix -v $HOME/.Xauthority:/root/.Xauthority --net=host '

$ dockerx11run myimage xterm




References :
Running GUI apps with Docker – Fábio Rehm

GoLang hex IP to string

package main

import (
        "fmt"
        "encoding/hex"
)

func main(){
    a, _ := hex.DecodeString("0101A8C0")

    fmt.Printf("%v.%v.%v.%v", a[3], a[2], a[1], a[0])
}




References :
convert hex ip addres to net.IP - Google Groups

GoLang string to int

package main

import (
    "fmt"
    "strconv"
)

func main() {
    output, _ := strconv.Atoi("1234")

    fmt.Println(output)
}




References :
data - How do I use the strconv.Atoi() method in Go? - Stack Overflow

2014年10月17日 星期五

iwlwifi-6000g2a-5.ucode

Package: firmware-iwlwifi (0.36+wheezy.1) [non-free]

 * Intel Wireless 100 firmware, version 39.31.5.1 (iwlwifi-100-5.ucode)
 * Intel Wireless 105 firmware, version 18.168.6.1 (iwlwifi-105-6.ucode)
 * Intel Wireless 135 firmware, version 18.168.6.1 (iwlwifi-135-6.ucode)
 * Intel Wireless 1000 firmware, version 39.31.5.1 (iwlwifi-1000-5.ucode)
 * Intel Wireless 2200 firmware, version 18.168.6.1 (iwlwifi-2000-6.ucode)
 * Intel Wireless 2230 firmware, version 18.168.6.1 (iwlwifi-2030-6.ucode)
 * Intel Wireless 3945 firmware, version 15.32.2.9 (iwlwifi-3945-2.ucode)
 * Intel Wireless 4965 firmware, version 228.61.2.24 (iwlwifi-4965-2.ucode)
 * Intel Wireless 5100, 5300 and 5350 firmware, version 8.24.2.12 (iwlwifi-5000-2.ucode)
 * Intel Wireless 5100, 5300 and 5350 firmware, version 8.83.5.1 (iwlwifi-5000-5.ucode)
 * Intel Wireless 5150 firmware, version 8.24.2.2 (iwlwifi-5150-2.ucode)
 * Intel Wireless 6000 firmware, version 9.221.4.1 (iwlwifi-6000-4.ucode)
 * Intel Wireless 6005 firmware, version 17.168.5.3 (iwlwifi-6000g2a-5.ucode)
 * Intel Wireless 6030 firmware, version 18.168.6.1 (iwlwifi-6000g2b-6.ucode)
 * Intel Wireless 6250 firmware, version 9.201.4.1 (iwlwifi-6050-4.ucode)
 * Intel Wireless 6250 firmware, version 41.28.5.1 (iwlwifi-6050-5.ucode) 
 
 
 
 
References :
Debian -- Details of package firmware-iwlwifi in wheezy

 

Python @property decorator

References :
2. Built-in Functions — Python 2.7.8 documentation
python - How does the @property decorator work? - Stack Overflow

2014年10月16日 星期四

2014年10月14日 星期二

Job Queue / Task Queue / Message Queue

Job Queue
Client <-> Gearman <-> Worker
Synchronize, Asynchronous

Message Queue and Socket Programming

write in Python
no client and worker
queuing task and do task in background
Celery + RabbitMQ for "data" queue in Instragram
Celery doing task and queuing data in RabbitMQ

RabbitMQ :

Message Queue
Work queues : Publish (task) / Subscribe (worker)




Queues