Home
Spoon which file been touched by opensnoop
opensnoop tracks file opens. As a process issues a file open, details such as UID, PID and pathname are printed out.
The returned file descriptor is printed, a value of -1 indicates an error. This can be useful for troubleshooting to determine if appliacions are attempting to open files that do not exist.
Since this uses DTrace, only users with root privileges can run this command.
17 Mar 2012
What's the meaning of '>/dev/null 2>&1'?
看到syslog里有这个 (nagios) CMD (/dev/shm/.b/cutitas >/dev/null 2>&1)
突然发现忘记 >/dev/null 2>&1
什么意思了,温习一下。
- 在linux里的默认file descripter
0 = stdin 1 = stdout 2 = stderr
>
代表重定向
-
/dev/null
空设备文件,用来丢弃输出结果的。 -
2>
表示stderr错误重定向 -
&
表示‘等同于’的意思。2>&1
表示2的结果等同于1
其实 > /dev/null 2> &1
== 1> /dev/null 2> &1
所以这个命令 echo "xxx" > /dev/null 2>&1
就是抛弃所有的输出结果,反正也看不到,要看去日志吧,如果你记了日志的话。
值得注意的地方:
command > file 2>file
与 command > file 2>&1
区别?
虽然同时输出到同一个文件,但是file会被打开两次, 这样stdout和stderr会互相覆盖, 这样写相当使用了FD1和FD2两个同时去抢占file的管道。 而command >file 2>&1 这条命令就将stdout直接送向file, stderr 继承了FD1管道后,再被送往file,此时,file 只被打开了一次,也只使用了一个管道FD1,它包括了stdout和stderr的内容。
从IO效率上,前一条命令的效率要比后面一条的命令效率要低,所以在编写shell脚本的时候,较多的时候我们会command > file 2>&1 这样的写法。
17 Mar 2012
ActiveRecord's composed_of method
I’m rare to use AR’s composed_of
method, but always writing a method to override the default attributes to make conversion for database attributes.
Let’s have look at this simple exmpale:
17 Mar 2012
Parslet a very cool Parsing Expression Grammar parser
Recently I made a japanese language learning tool, which is very cool :) . In this tool we need to create
a mark language parser to parse like this [kanji|furigana]
, My colleague zete, use his very professional regexp
skill to make a regexp to parse this text.
Look at above stunning regular expression. I never toughed this level of complexity of regexp.
But later on when I was looking at http header parser, then found a good tool, called parslet
.
It just do the exactly same thing, and even could do more complicated things like parsing a language.
Fantastic!!!
Reference: DSL doc Examples Get started Parslet intro - very good intro to parse erb
16 Mar 2012
HTML5 methods and properties audio and video element
Properties:
- paused (get)
- ended (get)
- seeking (get)
- duration (get)
- playbackRate
- defaultPlaybackRate
- seekable
- played
- muted (get/set)
- volume (get/set)
- currentTime (get/set)
- src (get/set)
Methods:
- play()
- pause()
- load()
Events
- loadeddata
- progress
- timeupdate
- seeked
- canplay
- play
- playing
- pause
- loadedmetadata
- ended
- volumechange
16 Mar 2012