Never ask how to use, just wonder how to make...

Dec 28, 2008

Every OS suck

Bài hát cũng có thể xem là một biên niên sử máy tính và hệ điều hành từ những năm 1970 đến nay. Tác giả của bài hát này là nhóm Three Dead Trolls in a Baggie.

Chúc các bạn cuối tuần vui vẻ ^^.



The lyric:

You see, I come from a time in the nineteen-hundred-and-seventies when
computers were used for two things - to either go to the moon, or play
Pong… nothing in between. Y’see, you didn’t need a fancy operating
system to play Pong, and the men who went to the moon — God Bless ‘em —
did it with no mouse, and a plain text-only black-and-white screen,
and 32 kilobytes of RAM.

But then ’round ’bout the late 70’s, home computers started to do a
little more than play Pong… very little more. Like computers started
to play non-Pong-like games, and balance checkbooks, and why… you
could play Zaxxon on your Apple II, or… write a book! All with a
computer that had 32 kilobytes of RAM! It was good enough to go to
the moon, it was good enough for you.

It was a golden time. A time before Windows, a time before mouses, a
time before the internet and bloatware, and a time…
before every OS sucked.

*sigh*

[singing]

Well, way back in the olden times,
my computer worked for me.
I’d laugh and play, all night and day,
on Zork I, II and III.

The Amiga, VIC-20 and the Sinclair II,
The TRS 80 and the Apple II,
they did what they were supposed to do,
wasn’t much… but it was enough.

But then Xerox made a prototype,
Steve Jobs came on the scene,
read “Of Mice and Menus,” Windows, Icons
a trash, and a bitmap screen.

Well Stevie said to Xerox,
“Boys, turn your heads and cough.”
And when no-one was looking,
he ripped their interfaces off.

Stole every feature that he had seen,
put it in a cute box with a tiny little screen,
Mac OS 1 ran that machine,
only cost five thousand bucks.

But it was slow, it was buggy,
so they wrote it again,
And now they’re up to OS 10,
they’ll charge you for the Beta, then charge you again,
but the Mac OS still sucks.

Every OS wastes your time,
from the desktop to the lap,
Everything since Apple Dos,
Just a bunch of crap.

From Microsoft, to Macintosh,
to Lin– line– lin– lie… nux,
Every computer crashes,
’cause every OS sucks.

Well then Microsoft jumped in the game,
copied Apple’s interface, with an OS named,
“Windows 3.1″ - it was twice as lame,
but the stock price rose and rose.

Then Windows 95, then 98,
man solitaire never ran so great,
and every single version came out late,
but I guess that’s the way it goes.

But that bloatware’ll crash and delete your work,
NT, ME, man, none of ‘em work.
Bill Gates may be richer than Captain Kirk,
but the Windows OS blows!
And sucks!
At the same time!

I’d trade it in, yeah right… for what?
It’s top of the line from the Compuhut.
The fridge, stove and toaster, never crash on me,
I should be able to get online, without a PHD.

My phone doesn’t take a week to boot it,
my TV doesn’t crash when I mute it,
I miss ASCII text, and my floppy drive,
I wish VIC-20 was still alive…

But it ain’t the hardware, man.

It’s just that every OS sucks… and blows.

Now there’s lih-nux or lie-nux,
I don’t know how you say it,
or how you install it, or use it, or play it,
or where you download it, or what programs run,
but lih-nux, or lie-nux, don’t look like much fun.

However you say it, it’s getting great press,
though how it survives is anyone’s guess,
If you ask me, it’s a great big mess,
for elitist, nerdy shmucks.

“It’s free!” they say, if you can get it to run,
the Geeks say, “Hey, that’s half the fun!”
Yeah, but I got a girlfriend, and things to get done,
the Linux OS SUCKS.
(I’m sorry to say it, but it does.)

Every OS wastes your time,
from the desktop to the lap,
Everything since the abacus,
Just a bunch of crap.

From Microsoft, to Macintosh,
to lin– line– lin– lie… nux.
Every computer crashes,
’cause every OS sucks.

Every computer crashes… ’cause every OS sucks!

Dec 12, 2008

Làm chủ Linux Bash shell: Xử lý string trong Bash shell

Một trong những shell được sử dụng thường xuyên trong Linux là bash shell. Khi viết các shell script, công việc mà người sử dụng hay gặp phải nhất có lẽ là xử lý string (tìm file, xử lý tên file, xử lý log, xử lý chuỗi nhập vào,...). Sau đây tôi xin trình bày một số điểm mấu chốt thú vị trong xử lý string với bash shell.

Hai lệnh đầu tiên, đơn giản nhưng tương đối hữu ích, đó là dirnamebasename. Cho một biến có chứa 1 string dạng đường dẫn đến 1 thư mục D hoặc 1 file X, lệnh basename sẽ trả về đúng tên thư mục D hoặc tên file X, còn lệnh dirname trả về phàn đường dẫn đến thư mục mẹ của D hoặc X. Ví dụ:
$ basename /home/thangphamduy/workspace/foo.txt
foo.txt
$ dirname /home/thangphamduy/workspace/foo.txt
/home/thangphamduy/workspace
$ basename /home/thangphamduy/workspace
workspace
$ dirname /home/thangphamduy/workspace

/home/thangphamduy

$ ALPHA="/home/thangphamduy/temp/bar.txt"
$ BETA=`dirname $ALPHA`
$ echo $BETA
/home/thangphamduy/temp

Đó chỉ là xử lý xâu đơn giản, tiếp đây, chúng ta thử xử lý xâu một cách "pro" hơn với bash shell. Trong 1 biểu thức, ta thường bắt gặp một biến được đặt trong cặp dấu ngoặc nhọn kiểu như ${MYVAR}. Và bash cũng cho phép chúng ta xử lý biến đó ngay trong cặp ngoặc nhọn. Chúng ta có thể dễ dàng cắt bỏ hay lấy ra một phần của string chứa trong biến một cách rất dễ dàng. Để dễ hình dung, các bạn có thể xem ví dụ sau:

$ MYVAR=foodforthought.jpg
$ echo ${MYVAR##*fo}
rthought.jpg
$ echo ${MYVAR#*fo}
odforthought.jpg

Trong lệnh thứ nhất, ở phía trong dấu ${}, đầu tiên chúng ta viết tên biến, sau đó là hai dấu #, rồi đến 1 chuỗi ký tự đại diện (*fo). Vậy lệnh này có nghĩa là gì và nó được bash shell thực hiện như thế nào? Lệnh này (echo ${MYVAR##*fo}) sẽ khiến cho bash thực hiện việc cắt bỏ chuối dài nhất, tính từ ký tự đầu tiên, khớp với chuỗi ký tự đại diện (còn gọi là wildcard), sau đó in phần còn lại ra stdout. Khi gặp lệnh này, bash shell sẽ thực hiện việc tìm kiếm tất cả các xâu con khớp với chuỗi ký tự đại diện *fo trong xâu được chứa bởi $MYVAR(tức là tìm tất cả các xâu kết thúc với 2 ký tự fo):
f
fo MATCHES *fo
foo
food
foodf
foodfo MATCHES *fo
foodfor
foodfort
foodforth
foodfortho
foodforthou
foodforthoug
foodforthought
foodforthought.j
foodforthought.jp
foodforthought.jpg

Sau khi kết thúc tìm kiếm (trong VD trên bash tìm được 2 kết quả), bash sẽ lấy xâu kết quả dài nhất (foodfo), rồi loại bỏ nó ra khỏi xâu gốc (phần còn lại: rthought.jpg), rồi in kết quả ra màn hình.

Trong câu lệnh thứ hai (echo ${MYVAR#*fo}), công việc cũng tương tự như trên, nhưng thay vì lấy kết quả dài nhất, bash shell lại lấy kết quả ngắn nhất (fo) rồi loại bỏ khỏi xâu gốc và in kết quả ra màn hình. Thực ra khi chỉ sử dụng 1 dấu # ở phần tùy biến, ngay khi tìm được kết quả đầu tiên, bash shell sẽ lập tức dừng việc tìm kiếm lại.

Để tìm kiếm từ cuối xâu thay vì tìm kiếm từ đầu xâu, chúng ta thay các tùy biến # và ## bằng các tùy biến % và %%, cách sử dụng hoàn toàn tương tự. Ví dụ:
$ MYVAR=thangphamduy/workspace/bar.foo.txt
$ echo ${MYVAR%.*}
thangphamduy/workspace/bar.foo
$ echo ${MYVAR%%.*}
thangphamduy/workspace/bar

Và một cách xử lý string nữa, ít được dùng tới hơn, nhưng nhiều lúc rất có ích, đó là cắt xâu theo vị trí:
$ MYVAR=http://thangphamduy.blogspot.com
$ echo ${MYVAR:0:13}
http://fotech
$ echo ${MYVAR:8:17}
fotech.org

Phần xử lý string xin được dừng lại tại đây, cảm ơn quý vị và các bạn đã quan tâm theo dõi >:).
(Tham khảo từ
Bash by example - IBM)

Dec 1, 2008

Vim mind share soaring: roundup of 10 vim articles, recent and older gems

(Copy from durdn.com)


Am I the only one to notice that there is a lot of vim love in the airwaves recently?

I saw the trend very clearly, spanning from reddit to news.yc and let me say that the material that came up recently is very good; those neat posts prompted me to improve my vimrc dramatically and I really like what I learned.

In this installment, instead than annotating my vimrc (another one? not that interesting, I’ll refrain) , I want to compile a roundup of the best vim articles I saw recently.

I’ll also add a few classics that changed me from a hater to a vim lover and will conclude with some minor tips out of my bag.

So here we go with the roundup.

Recent Vim Articles Roundup

Jamis Buck

Vim Follow Up

Coming Home To Vim

Jamis Buck switches back to vim from a period using TextMate and talks about his experience and his configuration. Many useful tips in there.

Stephen Bach

Configuring Vim Right

Sensible defaults for your vimrc, recommended.

Learnr dev blog

Configuring Vim Some More

Some additional configuration options that totally make sense and I incorporated in my config too.

Swaroop C H

A byte of vim

A new free e-book on vim, worth reading. Covers also advanced topics like writing your own plug-ins.

Effective Vim

This ends the recent vim trend spotting. But there are some older links that are worth sharing in my opinion.

Older Vim Gems

Jonathan McPherson

Efficient Editing With Vim

This is a true gem, an intermediate level tutorial that will convert you from a beginner vim user to a way more proficient one.

Jerry Wang

vi for smarties

Very good beginners guide to vim.

David Rayner

best of vim tips

Raw tips from a very long time vi/vim user

Vim is also great for Python development, 3 ideas…

vim omnicomplete awesomeness

How to make vim a modular Python IDE

How to replicate SLIME in vim

Finally a few tips from myself

vimperator: If you’re a heavy vim user you might want to checkout the great Firefox extension vimperator. You’ll find yourself browsing mouse-less with familiar vim keystrokes in a matter of minutes. I love it.

viPlugin for Eclipse: If you’re a Java developer (been there, done that) and you’re stuck with Eclipse, you definitely want to have viPlugin. It makes the Eclipse experience something much more pleasurable for one who has vi keystrokes embedded in the fingers.

cool color scheme: If you’ve seen “some” screen-casts and you have just a subterranean TextMate envy and you can’t stop thinking at that cool color-scheme, well think no more, you can use this one or my humbly tweaked version.

For delicious users here is the page of my bookmarks that made me notice the trend.

Ending note

For full disclosure I have to say that I have been - and still am sometimes - an Emacs user. One of the rebel ones daring enough to use Viper mode. So now you know.