Vantage Point of Queens
Meetup.Tweener (0.5.1)
- 2009-04-14 (Tue)
- JavaScript | Tech
Not really announcing yet, but I started a repository Meetup.Tweener on Github. Check it out, if you’re interested in. I will write more samples soon. Comments are all written in NaturalDocs compatible style in its source code. Once I finish styling for it, I will include that in the repository, which, I wish, will happen soon…
- Comments: 0
- Trackbacks: 0
Emacs Again (7): Using Emacs…
Now I really started to use Emacs as a daily life. Well, I only use it at home at this point, but I actually am getting used to it slowly but surely. Here’s the list of commands I most frequently use. By using search and tag jump, Emacs makes me so happy. The code completion runs a bit weird right now. I will try to figure out and will share with you.
Key Stroke |
Command Name |
Action |
|---|---|---|
C-s |
isearch-forward |
Do incremental Search forward. After typing some, it gets modal. You should see C-h k RET C-s to what you can do. |
C-r |
isearch-backward |
Do incremental search backward. |
M-g g |
goto-line |
Go to line. |
C-x k |
kill-buffer |
It’s equivalent to “close” of usual editors. |
M-. |
find-tag |
Find tag (in current tags table) whose name contains TAGNAME. |
|
tags-apropos |
Display list of all tags in tags table REGEXP matches. |
C-x o |
other-window |
Select next window on the frame |
C-x b |
switch-to-buffer |
Select buffer BUFFER in the current window |
C-x C-b |
list-buffers |
Display a list of names of existing buffers. |
- Comments: 0
- Trackbacks: 0
jsgrep (Mac OS X only!)
After Mac OS X 10.4, Mac has Spotlight, which is automatic metadata indexing for your data. By using its metadata, you can do grep, but only for JavaScript files. The command called mdfind (Meta Data FIND) does the job for you. I wrote a shell script, not to remember all the tedious options.
#!/bin/sh /usr/bin/mdfind "kMDItemContentTypeTree == 'public.source-code' && kMDItemFSName == '*.js' && kMDItemTextContent == '$1'"
It’s just verbose, but easy to understand, right? So, what if you want to do the same thing for… Ruby? Just find a ruby script you’re using, or make “test.rb” on your home directory. do “mdls test.rb”, which will probably give you something like follows:
% mdls test.rb
kMDItemContentCreationDate = 2009-04-XX XX:XX:XX -XXXX
kMDItemContentModificationDate = 2009-04-XX XX:XX:XX -XXXX
kMDItemContentType = "public.ruby-script"
kMDItemContentTypeTree = (
"public.ruby-script",
"public.shell-script",
"public.script",
"public.source-code",
"public.plain-text",
"public.text",
"public.data",
"public.item",
"public.content"
)
kMDItemDisplayName = "test.rb"
kMDItemFSContentChangeDate = 2009-04-XX XX:XX:XX -XXXX
kMDItemFSCreationDate = 2009-04-XX XX:XX:XX -XXXX
kMDItemFSCreatorCode = ""
kMDItemFSFinderFlags = 0
kMDItemFSHasCustomIcon = 0
kMDItemFSInvisible = 0
kMDItemFSIsExtensionHidden = 0
kMDItemFSIsStationery = 0
kMDItemFSLabel = 0
kMDItemFSName = "test.rb"
kMDItemFSNodeCount = 0
kMDItemFSOwnerGroupID = 20
kMDItemFSOwnerUserID = 501
kMDItemFSSize = 13
kMDItemFSTypeCode = ""
kMDItemKind = "Ruby Source File"
kMDItemLastUsedDate = 2009-04-XX XX:XX:XX -XXXX
kMDItemUsedDates = (
2009-04-XX XX:XX:XX -XXXX
)
So it should be like…
mdfind "kMDItemContentTypeTree == 'public.ruby-script' && kMDItemFSName == '*.rb' && kMDItemTextContent == 'SEARCH_QUERY'"
mdfind gives you many advantages of metadata search. You should definitely give a shot.
- Comments: 0
- Trackbacks: 0
Emacs Again (6): Learning GNU Emacs Chap 2
Here’s a list of commands I learned from Learning GNU Emacs, Third Edition Chapter 2.
Chpater 2 — Editing
Key Stroke |
Command Name |
Action |
|---|---|---|
C-x |
Control-X-prefix |
Try C-h v and type ctl-x-map |
M-x |
execute-extended-command |
Run a function by name. Try C-h f for each specific function name and what it does. |
C-f |
forward-char |
Move point one character right |
C-b |
backward-char |
Move point one characer left |
C-p |
previous-line |
Move point vertically up |
C-n |
next-line |
Move point vertically down |
M-f |
forward-word |
Move point forward by a word |
M-b |
backward-word |
Move point backward by a word |
C-a |
move-beginning-of-line |
Move point to beginning of current line as displayed |
C-e |
move-end-of-line |
Move point to end of current line as displayed |
M-a |
backward-sentence |
Move point backward to start of sentence |
M-e |
forward-sentence |
Move point forward to next "sentence-end". (The variable "sentence-end" is a regular expression) |
M-} |
forward-paragraph |
Move point forward to end of paragraph |
M-{ |
backward-paragraph |
Move point backward to start of paragraph |
C-x ] |
forward-page |
Move pointforward to page boundary |
C-x [ |
backward-page |
Move point backward to page boundary |
C-q |
quoted-insert |
Read next input character and insert it. This is useful for inserting control characters. For example, if you want to insert \?, you'll type C-q DEL |
C-v |
scroll-up |
Scroll text of current window upward |
M-v |
scroll-down |
Scroll text of current window down |
M-> |
end-of-buffer |
Move point to the end of the buffer; leave mark at previous position. |
M-< |
beginning-of-buffer |
Move point to the beginning of the buffer; leave mark at previous position. |
M-g M-g |
goto-line |
Goto line ARG, counting from line 1 at beginning of buffer. |
|
goto-char |
Set point to POSITION, a number or marker. |
M-(number) |
digit-argument |
Repeat following command (number) times. For example: M-3 C-f will move point 3 characters forward. |
C-u |
universal-argument |
Begin a numeric argument for the following command. For example: C-u 9 C-q DEL will insert nine \? at point, C-u 3 C-f will move point 3 chars forward. |
C-l |
recenter |
Center point in window and redisplay frame. |
C-d |
delete-char |
Delete the following character. Defaultly assigned on delete button |
M-d |
kill-word |
Kill characters forward until encountering the end of a word. |
M-DEL |
backward-kill-word |
Kill characters backward until encountering the beginning of a word |
C-k |
kill-line |
Kill the rest of the current line; if no nonblanks there, kill thru newline. |
C-y |
yank |
Reinsert ("paste") the last stretch of killed text. |
C-SPC or C-@ |
set-mark-command |
Set the mark where point is, or jump to the mark. |
C-x C-x |
exchange-point-and-mark |
Put the mark where point is now, and point where the mark is now |
M-h |
mark-paragraph |
Put point at beginning of this paragraph, mark at end |
C-x h |
mark-whole-buffer |
Put point at beginning and mark at end of buffer |
C-x C-p |
mark-page |
Put mark at end of page, point at beginning |
M-y |
yank-pop |
After C-y, Rotate Kill Ring. Let's say, you have ['latest', '2nd', '3rd'] as Kill Ring. When you do C-y, Emacs inserts latest at point. Then M-y will change latest to 2nd, and type M-y again, 2nd will be 3rd. M-y again, 3rd will be back to latest. |
C-t |
transpose-chars |
Interchange characters around point, moving forward one character |
M-t |
transpose-words |
Interchange words around point, leaving point at end of them |
C-x C-t |
transpose-lines |
Exchange current line and previous line, leaving point after both |
C-g |
keyboard-quit |
Signal a quit condition. |
C-x u |
advertised-undo |
Undo some previous changes |
Notes
Like other editors in Mac/Windows or even in vi… You know, when you start to select characters, background and foreground colors are inverted. In order to visualize where you are selecting (in Emacs way, it should say… make a region by using set-mark command), you have to add the following line in your .emacs.el. I just wonder why this is not default configuration… Anyway.
(setq-default transient-mark-mode t)
I’ve started my unix career with vi, like 1997? Even the first information technology class in my college taught me to use emacs, I liked vi better because, in that class, I think we have around 100 ~ 200 students one class, and all of them were connecting to “Clay Super Computer” with a few giga-bytes of memory space… It was just insane, to use a “memory sucker Emacs” with that terminal.
So, I still, when I did something wrong on editor, I type ESC! ESC! ESC!.. but instead, I should start to do C-g! C-g! C-g!!
Clipboard-Pasetboard interoperability/synchronization doesn’t work in my environment, Mac OS X 10.5 with Terminal Emacs 22.1.
Changing capital, Overwrite and Customization doesn’t seem to be important to me so I skipped it for now.
- Comments: 0
- Trackbacks: 0
Emacs Again (5): Showing line number
I found a nice elisp to show line number.
As you see on screenshot, it shows line number on left side of the emacs window. As usual .el files, download it into your elisp directory, and add some lines in your emacs.el file. I usually like to wrap line by window size. And here’s what I did on .el file.
(require 'wb-line-number) (setq truncate-partial-width-windows nil) ; wrap line by window size (wb-line-number-toggle)
- Comments: 0
- Trackbacks: 0
今日の英語: in layman’s terms.
- 2009-03-29 (Sun)
- translation
僕は会社でサポートの人と IM すること(僕が作ったプログラムの使い方などを聞かれる)も最近増えてきたのだけれど、その中で出てきた単語。
E: Can you put in layman’s terms?
Me: I personally call it Dock.
文脈から何となく想像して適当に答えましたが、要するに“もっと簡単な言い方はない?”と聞かれたわけです。
Wikipedia: Layman (英語)
Wikitionary: in layman’s terms
僕はてっきりなんかテレビホストで Layman とか云う人がいるのかと思ったのですけれど、宗教用語から来てたんですね。宗教者 clergy に対する俗人 laity。その別の言い方としての layman の意味が時代と共に変化して、エキスパートではない人、という意味なったようです。でも元々 lay はラテン/ギリシア語源の 人の/世間一般のという接頭辞のようです。
- Comments: 0
- Trackbacks: 0
Safari バグ: TD エレメントの間違った offsetTop 値
- 2009-03-20 (Fri)
- JavaScript
# 追記: このバグは最新の開発版では修正されています。WebKit Bugzilla を参照のこと→ WebKit Bugzilla 19094. Nightly でも既に修正されているみたいですね。もしこれに関してハックをしたなら(つまり僕のことですが)、以下のようなもう一つ、ハックが必要です。
var webkit = indow.navigator.userAgent.match(/WebKit\/([0-9]{3})/);
if (webkit && parseInt(webkit[1]) < 528) {
...
}
JavaScript ライブラリの多くは、HTML エレメントの(ページ上での)ピクセル位置(絶対座標)を返すメソッドを備えています。jQuery の jQuery.offset() しかり、MochiKit の MochiKit.Style.getElementPosition() しかり、MooTools の Element.getPosition() 等々… ほとんどの場合これらはうまく動くのですが、今日動かないケースを確認し、おそらく Safari のバグだと思うのでここに報告しておきます。
以下の条件が揃ったとき、ピクセル絶対座標を取得するメソッドは間違った値を返します。
- ブラウザは Safari
- 取得しようとしているエレメントは TD (あるいは display:table-cell)
- CSS で vertical-align を top 以外の値 (middle or bottom) が設定されている
次にこのケースの例を作りました。Safaribug: wrong offsetTop on TD. テーブルセルをクリックすると、アラートで、そのテーブルセルのピクセル座標を返します。Safari とその他のブラウザで開いてみてください。違いがあります。
ではコードで解説します。以下は Google doctype project で見つけた PageOffset: How to calculate the position of an element on the page (goog.style.getPageOffset) を下にしています。オリジナルの PageOffset のコードは非常に細かく説明してあるので、一度読んで見ることをお勧めします。長くないし。
function getPageOffset(el) {
var pos = {
x: 0,
y: 0
};
var viewportElement = document;
if (el == viewportElement) {
return pos;
}
var parent = null;
var box;
pos.x = el.offsetLeft;
pos.y = el.offsetTop;
parent = el.offsetParent;
if (parent != el) {
while (parent) {
pos.x += parent.offsetLeft;
pos.y += parent.offsetTop;
parent = parent.offsetParent;
}
}
if (el.style.position == 'absolute') {
pos.y -= doc.body.offsetTop;
}
parent = el.offsetParent;
while (parent && parent != document.body) {
pos.x -= parent.scrollLeft;
parent = parent.offsetParent;
}
return pos;
};
Safari では、指定したエレメントから、その相対目標(これを指定しなければ、document.body を相対目標とします。つまりページの絶対座標ですね。)まで、エレメントを上り詰めて、その間の offset を累積加算していきます。問題は、一番最初の el.offsetTop (15行目) で起こります。これは table cell で、padding/margin/border が設定されていませんから、0 であるべきなのですが、Safari は、子孫要素への offset を返しているようなんですね。
どうにもいい方法が見つからなかったので、実際のアプリケーションではダーティハックを入れましたが、WebKit チームの早急な fix を望みます!!。
- Comments: 0
- Trackbacks: 0
Safari Bug: wrong offsetTop on TD
- 2009-03-20 (Fri)
- JavaScript
# EDIT: This bug will be fixed soon. See WebKit Bugzilla 19094. It’s fixed already on Nightly. If you do have a tweak for this bug, (such as me) you need to add another sniff like follows.
var webkit = indow.navigator.userAgent.match(/WebKit\/([0-9]{3})/);
if (webkit && parseInt(webkit[1]) < 528) {
...
}
Most of JavaScript library comes with a method that returns pixel position of the given element. For example, jQuery has jQuery.offset(), MochiKit has MochiKit.Style.getElementPosition(), MooTools has Element.getPosition(). They work well in most cases, but today i found the situation that doesn't work and that, I think, is a Safari's bug.
Before going into detail, here's the condition that pixel position getter method doesn't work.
- The browser is Safari
- The element you try to work on is TD (or display:table-cell)
- It set vertical-align NOT as top (maybe middle or bottom)
Here I made examples for this case: Safaribug: wrong offsetTop on TD. When you click each table cell, it will return the pixel position of the clicked TD. Open the page with Safari and other browsers. There are differences.
How it happens? Let me introduce how JS lib calculate the pixel position of any given element. I found a nice code with comments on Google doctype project.
PageOffset: How to calculate the position of an element on the page (goog.style.getPageOffset)
It's really step-by-step good explain, you should go through with it. Here I extract how Safari runs the code:
function getPageOffset(el) {
var pos = {
x: 0,
y: 0
};
var viewportElement = document;
if (el == viewportElement) {
return pos;
}
var parent = null;
var box;
pos.x = el.offsetLeft;
pos.y = el.offsetTop;
parent = el.offsetParent;
if (parent != el) {
while (parent) {
pos.x += parent.offsetLeft;
pos.y += parent.offsetTop;
parent = parent.offsetParent;
}
}
if (el.style.position == 'absolute') {
pos.y -= doc.body.offsetTop;
}
parent = el.offsetParent;
while (parent && parent != document.body) {
pos.x -= parent.scrollLeft;
parent = parent.offsetParent;
}
return pos;
};
The problem happens on the very first access to el.offsetTop on line 15. It should be 0, since it's a table cell and no padding/margin/border set, but it seems Safari returns the vertical offset to the descendant element on that property.
I don't come up with any smart way to solve it... so I just tweak it.. Please WebKit, fix this bug!!
- Comments: 0
- Trackbacks: 0
Best Job Pitch
- 2009-03-08 (Sun)
- Life
Today I read an article on Presentation Zen: If you only had one minute to pitch your story and I see a very interesting approach by Tourism Queensland, Australia, in order to hire a new position called Caretaker of the Islands of the Great Barrier Reef. It really sounds like the best job in the world, right? Check out their web site: The Best Job In The World – Tourism Queenslan. If you wanna get a job there, you’ll make a one-minute video of yourself and post it on YouTube. They will pick up seats for final interview by themselves and there’s another one seat by audience popularity.
What’s interesting about is, as Presentation Zen mentions, such a great way to get people’s attention. And by using the external resource, YouTube for this time, the process is crystal clear to outside. I’m sure the job itself is not just hanging out on the beech job, it’s more like Survivor type of adventure maybe?
The site is a full-flash site, which usually doesn’t get my attention anymore, but it’s very well done. And it seems like developed by CumminsNitro.
- Comments: 0
- Trackbacks: 0
Emacs Again (4): Learning GNU Emacs Chap 1
- 2009-03-07 (Sat)
- emacs
I got Learning GNU Emacs, Third Edition. And here’s the summary I learned from Chapter 1.
| Key Stroke | Command Name | Action |
|---|---|---|
C-x C-f |
find-file |
Find file and read it into a new buffer. |
C-x C-v |
find-alternate-file |
Read an alternate file, replacing the one you’ve done with C-x C-f |
C-x i |
insert-file |
Insert file at point position. |
M-> |
end-of-buffer |
Move point to the end of the buffer; leave mark at previous position. By being followed by C-x i you can append file. |
C-x C-s |
save-buffer |
Save buffer with the current buffer name. |
C-x C-w |
write-buffer |
Emacs prompts you to set a new file name, and save it. |
C-x C-c |
save-buffers-kill-emacs |
Exit Emacs with asking you if there are any un-saved buffer. But *scratch* is different. Even you’ve editted *scratch*, Emacs discard it silently. |
C-h |
help-command |
Enter the online help. |
C-h ? |
help-for-help (or help-for-help-internal) |
Display a list of available help command? |
C-h f |
describe-function |
Display help for a given command. |
C-h k |
describe-key |
Display help for a given key stroke. |
C-h v |
describe-variable |
Display help for a given variable (a symbol). |
C-h t |
help-with-tutorial |
Start Emacs tutorial. |
- Comments: 0
- Trackbacks: 0
- Search
- Feeds
- Meta
- Links
- Ads!
-
