2012-05-26

A Tech Geeker Dogma: Swapping Capslock Ctrl

Perm URL with updates: http://xahlee.org/kbd/emacs_keyboard_capslock_ctrl_rant_2012-05-26.html

The Caps Lock position for Ctrl is actually not bad. Excellent design in fact. For example, of the 3 keyboard designs i admire, one of them is “Truly Ergonomic” (TE). See: Ergonomic Keyboards Gallery.

on TE, it actually put Shift key on the Caps Lock position, on both sides of the keyboard! What a fantastic, great, thoughtful, design.

Question: Why are you against the Capslock position then? Answer: it's because the tech-geeking fuckheads.

There are certain class of programers, a subculture, who pride themselves around the term hacker. These people, collectively loosely have certain way or habit and thought pattern, and a subset of them are loud-mouthers on some issues (such as our Thad Floryan fellow here, who, every time would sting me about Caps Lock/Ctrl switch when i write about keyboard. Which, is perfectly fine, just don't blame me for my equally reasonable responses.)

The hacker types (for lack of better term), often insists on certain geek ways that are often scientifically baseless and harmful. For example, the advice to swap Caps Lock/Ctrl, the cry against GUI, the cry against mouse, the numerous unix slogans, the adoration of emacs, the slogan about laziness (perl), the slogan about lambda knight or adoration of lisp as god lang, usually given as dogma. Motherfucking fuckheads. For example, one slogan “Be conservative in what you send; be liberal in what you accept.” which damaged the web for 2 decade.

But what's technically wrong with swapping Caps Lock/Ctrl?

Here's the deal. On a newly designed keyboard such as that TE, the position to the left of A is a top valued position. Also, notice that TE keyboard is symmetric, fixing one of the major problem of traditional keyboard. So, Caps Lock or Shift are on the right side at the same place too. (similar to Enter key, but without extra key column in between)

If you are designing a new keyboard, it's great. But if you are creating workaround over standard PC keyboard, then the advice of swapping Caps Lock/Ctrl is a entire new story. For example, you could swap Ctrl/Alt. The Alt is used by thumb, and available on both sides. That is immediately superior workaround on most keyboards (except laptops). There are many issues, alternatives, i've analyzed in detail in my article and i won't repeat here.

But the thing about the motherfucking techgeekers, such as our Thad Floryan fellow here, is that they often blindly insists on hackerdom dogma.

Sure, on many situations, swapping Caps Lock/Ctrl is a perfect solution. For example, on laptops. On laptops, keys are tiny, especially the Alt key, and usually they are not available no right side. The Caps Lock key on laptop is a big key. It's really a great solution. But you see, tech geekers are not concerned about this. Thad, never give the qualifications about swapping Caps Lock/Ctrl. Instead, they typically go like this: “I type for decades, never had problem, you should swap CapsLock/Ctrl, it's how keyboard should be, look at Sun Micro keyboards, and all the keyboard of 1920s. God designed that way. And look at vi keyboard, h j k l. emacs and vi. and IBM Model M! God says. Therefore you should. KISS.”

For more about keyboarding, see:

For more about tech geekers, see:

2012-05-25

functional programing in bash complexity graph

Perm URL with updates: http://xahlee.org/comp/unix_pipes_and_functional_lang.html

funsh functional bash
A comic by Mike Ledger for his project fun.sh

Emacs Video Demo: forward-sexp beginning-of-defun …

David Capello demonstrates great use of {forward-sexp, backward-sexp, beginning-of-defun, end-of-defun} for coding languages with C-like syntax.

A video so funny and so educational you can't refuse! Love the music. Click on the CC to turn on English subtitle.

〈Comandos de programación básicos de Emacs (forward-sexp, beginning-of-defun)〉

David uses a customized version of ErgoEmacs keybinding. Code and layout here: http://dacap.com.ar/programming/keyboard-layout/

ErgoEmacs Keybinding also got a major update. Lots changes. Check it out and let me know what you think. svn checkout http://ergoemacs.googlecode.com/svn/trunk/ergoemacs/ergoemacs-keybindings ergoemacs-read-only

war of the worlds: chrome vs firefox

Perm URL with updates: http://xahlee.org/js/google_chrome.html

chrome vs firefox
Chrome vs Firefox. Artwork mimicking a theme from H G Well's The War of the Worlds. Artwork by elfoice

Google Picasa keyboard shortcuts

Perm URL with updates: http://xahlee.org/kbd/picasa_picture_viewer_keys.html

This page is a complete list of Google Picasa Picture Viewer keyboard shortcuts.

KeyAction
=】 or 【Zoom in
-】 or 【Zoom out
PageUpZoom in 4 ×
PageDownZoom out to previous
EnterToggle fullscreen
SpaceToggle background
Mouse WheelZoom or prev/next picture. (set in Configuration)
Ctrl+MouseWheel】Zoom
1Toggle 100% zoom
Ctrl+rRotate the image clockwise
Ctrl+Shift+rRotate counter-clockwise
KeyAction
】 or 【jPrevious image
】 or 【kNext image
⌦ DeleteDelete image (to trash)
KeyAction
cPreference/Configuration
eEdit in Picasa
KeyAction
bBlog
mMail photo
uUpload
Ctrl+uimage upload
KeyAction
8】 or 【Ctrl+8Toggle star
EscQuit

2012-05-22

The Roadmap to Completely Replace Emacs's Key System

Perm URL with updates: http://xahlee.org/emacs/emacs_keybinding_redesign.html

This post discusses a systematic way to replace emacs's one thousand keys.

Voice version of the blog at:

“roadmap to emacs key replacement”

The following is a text version.

massive update on the ergonomic keybinding.

It's dev version. Probably has bugs. More change coming in following days or weeks.

made few discoveries about keyboarding habit and health this week. Don't know where to begin… but i'll just start to ramble here. You can read on or just get the files there any try it. Read the history file there. More change will be done in next few days.

Ok, following will be rambling. (in the following, i'l use QWERTY notation. even though i use Dvorak.)

My left hand is fucked. emacs. Wasn't sure what's causing it. Now i know. It's the keys that require using 4th and 5th fingers, while hand is in standard touch-typing position. Actually, mostly the undo Z, cut X keys, and that standard save select all (S, A).

Here's a new thing i've learned. Normally, it's a good advice to press combination keys using both hands. That is, suppose you want to press 【Ctrl+x】. You should use right hand to hold right Ctrl and left hand to press x. But if you are a touch typer and leave your hand in standard position, so you press the x with 4th finger. That'll cause a major problem if done often.

Solution: set F1 F2 F3 F4 keys for undo cut copy paste.

there's lots of tricky details. Normally, for those who use Caps Lock for Ctrl, this particular issue doesn't happen, because you shift your left hand and make your left hand into some spider leg way to press 【Ctrl+x】. So, x is pressed by either 2nd or 3nd finger, both strong fingers. (though, i think given equal amount of typing, this method may develop other problems.)

also, there are certain things that made this issue worse: in about a year ago, a new feature is added to ergoemacs keybinding. That is, when there's no text selection, pressing cut or copy will simply cut/copy the whole line. (See: Emacs: How to Copy/Cut Current Line.) This is really a fantastic feature by itself. But there's a odd consequence. With this new feature, i noticed that i no longer use kill-line anymore. I simply use cut, which will cut the current line nicely. Also, when i need to cut/delete multiple lines, normally you mark, then move cursor, then cut or delete. But i noticed i don't do that anymore. I simply just cut multiple times, sometimes holding the cut key. Nice! Convenient and saves keystrokes. But the problem is, that my 4th finger now press the x key, many many times. In other words, indirectly, i'm putting a whole lots burden on the 4th finger on the left x. If i was hunt'n'peck, that may not be a problem because i just use index finger to peck x. But since i am touchtypest, and tend to follow proper ways, so to press x, i use 4th finger while whole left hand is in standard position. This is the the cause of my problem. Normally, standard typing won't type x much.

i find this particularly interesting, because seemingly good methods may create side effects that's bad.

so, in a summery, if you want to assign score for each key with respect to health, then the worst are Z X A S keys (and same for right hand). The interesting thing is that Home Row key ≠ good health key.

also, in past week, been spending days to think/search on what's the problem. Sometimes i think typing too much IS the problem, period, regardless all other health measures. That is certainly true to some degree. When you need to type more than certain load for years, one'll get problems regardless how good are the typing habits, keyboard, or personal health etc.

but anyhow, in past week's thinking, i came up with the thought of eliminating all combination keys. I've been on this road in recent years, but this week i made a more systematic approach, and added 30 or so sequential keys with the F key. By my analysis, i think sequential keys are much superior than key combos in many ways. Health, memorization, grouping... and i think even faster to operate on the long run on average. Here's a draft of reasons:

Advantages of sequential keys

  • easier to press
  • far more key possibilities (not technically, but indirectly due to the model of all single key, as opposed to mixed single/combo keys (e.g. 【Ctrl+x c】, 【Ctrl+x Ctrl+c】))
  • Easier to remember. (because now it's all single keys, as opposed to mixed single/combo)
  • commands can be grouped. e.g. 【F5 F6 …】 prefix for elisp related. 【F5 F7】 for editing related. 【F5 F8】 for rectangle* commands. 【F5 F9 …】 for modes. 【F5 F10 …】 for toggling commands, ….
  • help is easily available by pressing the sequence followed by F1. It'll show this group's commands, and each command are links to inline doc.

so, i've been using a draft system for a few days now. Been thinking to go thru the whole ~200 C-x keys to give them a sequential key, and make it part of ergoemacs. But that'll take months to design.

the one thing sequential keys can be faster is that, for example, 【Ctrl+x r k】 of kill-rectangle; you want to make the most frequently used commands to have the most easy keys. In this case, that key can be 【F7 F8 8】. So, 3 keys all nearby.

but 【Ctrl+x r k】 is easier to remember? Not necessarily. If you look at emacs's 【Ctrl+x r ‹key›】 (See: gnu_emacs_keybinding_C-x.txt) , you'll find it's a mixed bag. Some are about bookmark, some rectangle, some registry. While, 【F7 F8】 prefix can all be about rectangle commands. So, this is a example that i think sequential keys may not be worse with respect of ease of memorization.

but also, when it comes to keys, ease-of-press is more important than ease-of-memory. Because, once you know the key, you have to use it for the rest of your life. Also, the memory is muscle memory, not verbal citation of key sequence. When asking what's the key for a command, most emacs users may have difficulty, but will easily execute it the fingers.

so far, the system is such that for most frequently used commands, they'll have one single F key. e.g. F2=Cut, F3=Copy, F4=Paste, F5=Undo. Then, Secondary frequently used ones will have 2 keys, start with a F key then a number. e.g. 【F7 5】 for list-matching-lines. 【F7 6】for rect kill, 【F7 8】 for rect yank, etc etc. Then, others will have 3 keys, e.g. 【F7 F6 5】.

principle: 1 to 3 keys. The first few are always F keys. The last is digit or letter. (this makes it actually easier to remember than C-x, or C-c prefixes… many of them are more prefixes. Which is prefix is not predicable.)

Currently, the plan is that F6 to F9 are all prefixes. If we only use these 4 F keys, in our system, we'll have a total of 4*40+4*4*40 = 800 keys. Pretty much covers any need. (any emacs user, even advanced expert, probably use less than 200 keys.) (GNU emacs by default has about 800 usable keys. See: A Curious Look at GNU Emacs's 1000+ Default Keybinding.)

also note: combo keys are still necessary. Any command that needs to be called twice or more in one shot, must be combo keys. e.g. moving cursor, page up/down, undo, redo, paste, isearch-forward, tags-loop-continue, ... where you can hold it for repetition. (one single F key can also work, but there are not enough F keys for that, and plus F keys needs reach) So, these should be covered by 【Ctrl+‹key›】 or 【Alt+‹key›】.

Conversely, i think a principle of this is that if a command never needs to be called twice in a row, then it shall Not have one of 【Ctrl+‹key›】 or 【Alt+‹key›. That is, the combo keys will be exclusively for commands that may need to repeat by holding key. (many keys in emacs default violate this. e.g. query-replaceAlt+%】.) This way, we maximize the key space for any commands that needs it. While, once-off call commands such as {query-replace, goto-line, list-matching-lines, delete-matching-lines, grep, shell, calc, shell-command, find-file, dired, list-buffers, iswitchb-buffer, bookmark-bmenu-list, copy-to-register keyboard-quit, kmacro-start-macro, describe-function, …} will use the F key sequence space.

also, been thinking to abolish any key that needs pressing 3 keys simultaneously. e.g. emacs default regex replace, or lisp code navigation keys.

btw, this note apply to really heavy typers. there are huge number of misconceptions about typing. I have brushed with RSI in past years. Never seriously enough to experience pain, but seriously enough to do something about it. (tingling sensation, sore, etc. This time, it's soreness in forearm) About 2 years ago, there's a incidence of tingling, pretty bad. Blogged about that here: Programer Hand Health: vi Esc Key Syndrome, Emacs, RSI, My Experiences. In summery, that problem is caused by frequent side-to-side wrist motion. (like vi, reaching for esc) It was my bad habit of reaching for the 1 and ` key. This has since been corrected, but it's so interesting that today i developed other issue.

typing is such a complex and subtle thing... here's a blog i wrote that covers some common misconceptions of typing. It's a draft version, in bad shape... but anyway here it is Bad Advices from Programers about Typing and Keyboard (RSI)

this post is quickly written. I just want to get it out. Will edit and refine later. I actually typed the whole thing, lol, my hand didn't break (lol). Feel free to post your thoughts, even if disagree. Emacs keys needs to be based on scientific basis as much as possible, and it can be done…

PS check out the ergonomic keybinding update, give me your input. Thanks.

for a programer, as much as 70% of your typing is calling editing commands, not data entry.

that means, it's not QWERTY that wreck your hand. It's the emacs keys.

See: Emacs's Command Frequency.

Completely Replace Emacs's Key System

This leads to a key system that completely replace emacs's system. This i've been thinking for a few years now. But today, it seems i actually arrived at a sensible map. Here's a summery:

• First, start with ErgoEmacs Keybinding. This will take care of some 80% of key health issues.

• The Menu key will be emacs M-x. Single key. There will also be a combo key for this, provided in the rare situations when people don't have the Menu key. Currently, it's 【Alt+a】 in ErgoEmacs keybinding. There probably should be a single F key. (e.g. Mac users). Possibly F10.

F2=Cut, F3=Copy, F4=Paste, F5=Undo.

• The 【Ctrl+x ‹key›】 group will be mapped starting with a function key. Currently, the plan is F8.

• The 【Ctrl+c ‹key›】 group will be mapped starting with a function key. Currently, the plan is F9.

That leaves with emacs 【Ctrl+h】. But lucky for us, emacs already has F1 as equivalent.

The above is the sketch of the design. It's pretty much all already been implemented in ErgoEmacs keybinding. (except the C-c = F9 issue, probably due to a emacs bug, but we'll not discuss that for now)

What's really new, is to design the actualy F key sequence for each and every of GNU Emacs's 1000+ Default Keybinding, based on the principles in this article and that of ErgoEmacs. Also, the principles of this article is subject to change. The work will needs lots stats and experimentation.

I'll probably be working toward this, slowly, in coming months or years.

高级程序员装逼指南 (Zhuangbility Manual)

Perm URL with updates: http://xahlee.org/lit/Zhuangbility_Manual.html

前言

最近网上出了一个《程序员装逼指南》,觉得这个东西其实图样图森破

然后在下跟微博上的一些程序大牛讨论了一下如何装逼,深有感触

程序员嘛,外行人看起来已经是不可理解的奇怪生物了,自然也没必要跟他们再装逼

所以呢,如何对其他程序员装逼就是一门很有学问的事了

于是乎在下手痒写了个《高级程序员装逼指南》,请大家指正

编程语言

千万千万千万千万不要说自己是Java/C#/C++程序员

尽量学一些奇怪的语言,python已经有烂大街的趋势了,写写还是可以,装逼是用不上了

Lisp和Erlang都是装逼的好语言

当然你要是号称会Haskell就更牛逼了,实在不会也没关系,发发跟Haskell有关的状态别人也很装了

没事儿还可以在论坛里喷喷Java/C++有哪些缺点

可是,如果对方先发制人说他出了一种奇怪的语言名字怎么办?

你可以微笑地说,你可知道天下语言皆出自Lisp和Smalltalk?保准对方愣住3秒钟

操作系统

首先,妥妥儿的不能用Win,麻瓜才用Win呢

Linux嘛,ubuntu也差了点儿,现在不少人已经用Arch了

懂行儿的人都知道,gentoo和LFS才是真正的装逼利器啊

自己编译神马的,这逼还真不是人人都能装的

再深入的话,你要是用Lisp Machine工作,就近乎神了

编辑器

作为一个IDE去死团成员,我承认很大程度上我只是在装逼

纯文本编辑器才是你最终的归宿

Vim是标配,但是只有Emacs才能称得上是神器

“伪装成操作系统的编辑器”并非浪得虚名

当然,想要装逼装得好的话,你还需要学习它的配置语言Emacs Lisp

博客

在CSDN/ITeye/cnblogs这种地方写技术博客确实比在人人上写技术博客好多了

但是你要知道,大牛们都是有自己的个人网站的

而且,一个共同点是,他们的网站都是自己写的html(没有css)并且界面十分难看

整个网站散发着一种“我这的文章都很牛所以界面什么的都不重要”的气质

例如这个:http://xahlee.org/index.html

其它

我习惯称不会写代码的人为“麻瓜”,你也可以有你自己的称呼

不要写Linux/Unix,正确而专业的写法是*nix

手边不要放技术书籍,即使要摆一两本书也要那种自己打印的全英文的手册

或者用铅笔在纸上写代码也是个不错的选择

还可以养成某种奇特的习惯,例如号称自己是Lisper然后各种加(括号)

装逼进阶

老是装逼也不成,所以我一直在寻找一种秒杀一切程序员的装逼之法

说实话,程序员的世界里有三种人

大部分是不会写代码的麻瓜,然后是程序员这个群体本身

他们认为唯一比程序员牛逼的,就是搞数学的人了

所以嘛,你要真想装个牛逼,就去学好傅立叶变换吧

另,发明Lisp和Python的人都是数学家,高得纳大神也是数学教授

还有更多装逼之法,想到再加

C程序员装逼指南

文档名称:C程序员装逼指南(C Coder Zhuangbility Manual) 文档日期:2010.11.15

Notes from Xah Lee

I found this article online about 2011. It is mirrored in lots chinese blogs and forums. I don't know who's the original author. (if you know, comment please.)

The article is interesting partly because it's a joke, but partly due to its many use of chinese slangs, puns, and linguistic twists.

Thanks to Ben Luo, Thomas Yao, for mention.

2012-05-21

Cat, Eagle, Fox, in Unalaska, Alaska

Perm URL with updates: http://xahlee.org/funny/cat_eagle_fox.html

“An eagle, a fox and my cat all getting along fine on my porch (without the warping in it)”
“4 19 2010 Two Eagles, A Fox and My Cats on My Porch Not Getting Along!”
“March 22, 2012 George Defends His Breakfast From the Fox”
“2009 Mr. Brown Fox, Mr. & Mrs. Eagle and my Cats”
“Mr and Mrs Eagle and George on my Porch”

She has lots other videos. She lives in Unalaska, Alaska

2012-05-20

Prime Number Test by Regex

voice blog: prime_number_test_by_regex_2012-05-20.oga

the perl code is this:

perl -wle 'print "Prime" if (1 x shift) !~ /^1?$|^(11+?)\1+$/' ‹number›

How it works: given a number, say 7. Generate a string of 7 same chars, say "bbbbbbb". Then, use regex to test if repetition of 2 chars "bb" matches the string completely. If not, try 3 chars "bbb", then 4, etc.

The interesting thing is to put this into a single regex. The key regex is ^(bb+?)\1+$.

Two Robbery Prank Videos

Perm URL with updates: http://xahlee.org/funny/robbery_prank.html

“Roommate Robbery prank on 3 hot chicks! Worlds Worst Boyfriend”
“Scare Prank”

HTML5 Audio Tag Example

Perm URL with updates: http://xahlee.org/js/html5_audio.html

This page shows you how to embed audio using HTML5's “audio” tags.

Here's a example of embeded audio.

<audio src="i/Bach_WTC1_1_Martha_Goldstein.ogg" controls></audio>

Here's what your browser shows.

Bach's Well-tempered Clavier, Book I, prelude 1.

Raw file: Bach_WTC1_1_Martha_Goldstein.ogg.

As of , it works in Firefox 3.6.12, Chrome 7.0, Opera 10.63. (all on Windows)

As of , it does not work in Safari 5.0.5, IE 9. (probably due to the ogg format.)

HTML5 Audio Tag Attributes

Following are optional attributes.

AttributePossible ValuesComment
preloadnone, metadata, auto
controlsDoes not take any value
autoplayDoes not take any value
loopDoes not take any value

Note that the attributes {controls, autoplay, loop} do not take any value. Their existence or non-existence defines the behavior. It is incorrect to add a ="true" or ="false" in them. This type of attributes is called “boolean attributes”.

Test Your Browser

Here's different audio formats, using audio tag.

raw file: test.m4a
raw file: i/s/test.oga

As of , m4a (AAC) format is supported by: Chrome, Safari.

As of , ogg format is supported by: Chrome, Safari, Opera.