Search

3/31/2011

CSS 101: Block Formatting Contexts » Yahoo! User Interface Blog (YUIBlog)

CSS 101: Block Formatting Contexts » Yahoo! User Interface Blog (YUIBlog)

A block formatting context is a box that satisfies at least one of the following:

* the value of “float” is not “none”,
* the used value of “overflow” is not “visible”,
* the value of “display” is “table-cell”, “table-caption”, or “inline-block”,
* the value of “position” is neither “static” nor “relative”.

3/23/2011

Parallelism /= Concurrency | GHC Mutterings

Parallelism /= Concurrency | GHC Mutterings

A concurrent program is one with multiple threads of control. Each thread of control has effects on the world, and those threads are interleaved in some arbitrary way by the scheduler. We say that a concurrent programming language is non-deterministic, because the total effect of the program may depend on the particular interleaving at runtime. The programmer has the tricky task of controlling this non-determinism using synchronisation, to make sure that the program ends up doing what it was supposed to do regardless of the scheduling order. And that’s no mean feat, because there’s no reasonable way to test that you have covered all the cases. This is regardless of what synchronisation technology you’re using: yes, STM is better than locks, and message passing has its advantages, but all of these are just ways to communicate between threads in a non-deterministic language.

A parallel program, on the other hand, is one that merely runs on multiple processors, with the goal of hopefully running faster than it would on a single CPU.

So where did this dangerous assumption that Parallelism == Concurrency come from? It’s a natural consequence of languages with side-effects: when your language has side-effects everywhere, then any time you try to do more than one thing at a time you essentially have non-determinism caused by the interleaving of the effects from each operation. So in side-effecty languages, the only way to get parallelism is concurrency; it’s therefore not surprising that we often see the two conflated.

However, in a side-effect-free language, you are free to run different parts of the program at the same time without observing any difference in the result. This is one reason that our salvation lies in programming languages with controlled side-effects. The way forward for those side-effecty languages is to start being more explicit about the effects, so that the effect-free parts can be identified and exploited.

3/22/2011

[記食] 重溫記憶:誠屋拉麵 N訪

[記食] 重溫記憶:誠屋拉麵 N訪

誠屋拉麵
北市市民大道 4 段17號1 樓(復興南路口,微風廣場附近)
02-27529393
11:00-22:00

[記食] 東區巷內 老友記粥麵館

[記食] 東區巷內 老友記粥麵館 .

老友記粥麵館
北市大安區敦化南路一段232巷16號
02-27312269
AM11:30 - PM21:30

[記食] 美味依舊:西門町 田舍手打麵

[記食] 美味依舊:西門町 田舍手打麵

田舍手打麵
台北市萬華區昆明街99號
02-23894218

【台北】麻膳堂 麵.餃子.炒飯 - 超級好吃的麻醬麵、麻辣牛肉麵

【台北】麻膳堂 麵.餃子.炒飯 - 超級好吃的麻醬麵、麻辣牛肉麵

地址:台北市光復南路280巷24號1樓 (捷運國父紀念館站2號出口)
電話:02-2773-5559
營業時間:中午11:00-14:30、晚上17:00-22:00

【台北】阿財虱目魚肚

【台北】阿財虱目魚肚

台北市內江街52號
2370-3378
22:00~06:00

【台北】高家莊米苔目 - 超好吃的米苔目,大推!

【台北】高家莊米苔目 - 超好吃的米苔目,大推!

台北市中山區林森北路279號
02-2567-8012
營業時間:19:00~05:00

【台北】好記擔仔麵

【台北】好記擔仔麵

台北市中山區吉林路77號-83號
02-2521-5999
營業時間:11:30~03:00

【台北】雞家莊

【台北】雞家莊

台北市中山區長春路55號
02-25815954

3/21/2011

文慶雞 文東記海南雞飯

文慶雞 文東記海南雞飯

文慶雞
電話:(02)2731-5522
地址:台北市忠孝東路3段219-1號

3/20/2011

什麼是粉紅單? (What is Pink Sheet?)

什麼是粉紅單? (What is Pink Sheet?)

在了解粉紅單之前,要先知道股票交易的機制。

一般投資人最熟悉的,是在交易所掛牌交易的股票。譬如紐約證交所(New York Stock Exchange,簡寫為NYSE)或是美國股票交易所(American Stock Exchange, 簡寫為AMEX),都是一個集中的股票交易所。

股票除了在交易所轉手買賣之外,也可以透過經紀人網絡(Dealer network)進行交易。透過這種方式成交的股票,稱作櫃檯交易股票(Over-the-counter stocks,簡寫為OTC Stocks)。

在交易所掛牌的股票,叫Listed stocks。相對於這些Listed stocks,OTC股票沒有在交易所掛牌交易,又稱Unlisted stocks。

櫃檯交易股票之所以會在櫃檯交易的最主要原因,在於這些公司的財務狀況與資訊揭露,尚未達到可以在交易所掛牌的要求。

回到粉紅單的主題。粉紅單(Pink sheet)是由National Quotation Bureau彙整的一張列表,上面列出了櫃檯交易的股票清單與買賣價。這個名稱的由來,在於當初這份名單是印在粉紅色的紙上。

National Quotation Bureau這家公司經過多年的延革,現在成為 OTC Market Group Inc. 。粉紅單也不是指全部的櫃檯交易股票,而僅是其中一個類別。

目前OTC Market Group這家公司,將櫃檯交易股票依據資訊揭露的透明程度,區分為三個類別(Market tiers),從揭露最充足到資訊最不透明的公司,依序為OTCQX OTCQB OTCPink 三個層級。如下圖:


在OTC Market Group網頁上的圖示也很有趣,從QX 、QB到Pink剛好用綠色、橙色與紅色。

其中OTC Pink是完全沒有要求財務標準與資訊揭露程度的公司。OTC Market Group的網頁上,直接稱其為”投機的交易市場”(The Speculative Trading Marketplace)。(依照現在許多投資人心中對於”投機”兩字的錯誤認知與過度美化,可能”投機的交易市場”一詞在他們眼中,不是警語,而是誘人的廣告詞。)

但須注意的是,就算是資訊揭露最多的OTCQX股票,公司的財務狀況與資訊揭露通常仍不足以讓它在交易所掛牌。投資人要進入這個市場,需三思而後行。(對大多投資人來說,不買賣美國OTC股票,也不會怎樣。)

要買賣美國櫃檯交易股票,可以透過FINRA登記有案的Broker-Dealer進行。

3/17/2011

How to play a sound in a web browser (it ain’t easy)

How to play a sound in a web browser (it ain’t easy)


Internet Explorer
Surprisingly, it’s pretty easy to play a mp3 on IE, even on version 6. The little known bgsound element does it for you, no questions asked. On IE9, with all the amazing HTML5 support, you can also use an audio tag, but IE9 misreports that it can play mp4 files when it can’t.

Safari
Can play mp3′s and m4a’s just fine with the audio tag, but behold: On Windows, if QuickTime is not installed also, not only will it not play any codecs, but the audio tag simply doesn’t exist, and the Audio object in JavaScript doesn’t either.

Firefox
Has support since 3.5, but it will only play OGG and WAVE files. Go figure.

Chrome
Has broad support and will play most stuff thrown at it. Also, no cross-platform differences.

Mobile devices
You can’t auto-play sounds, so forget about playing sounds as part of the UI now. On some devices (namely recent iOS devices) you can play sounds as a result of a direct user interaction (e.g. tap). It’s out of the scope of this article really.

When HTML5 is there, do this:

First, you need mp3, mp4 and ogg versions of your sound.

if("Audio" in window){
var a = new Audio();
if(!!(a.canPlayType && a.canPlayType('audio/ogg; codecs="vorbis"').replace(/no/, '')))
a.src = "/sounds/ping.ogg";
else if(!!(a.canPlayType && a.canPlayType('audio/mpeg;').replace(/no/, '')))
a.src = "/sounds/ping.mp3";
else if(!!(a.canPlayType && a.canPlayType('audio/mp4; codecs="mp4a.40.2"').replace(/no/, '')))
a.src = "/sounds/ping.m4a";
else
a.src = "/sounds/ping.mp3";

a.autoplay = true;
return;
}


When there’s no HTML5 around, do this

1. In case you’re on IE, use a bgsound element:

<bgsound src="/sounds/ping.mp3" loop="1" autostart="autostart">

2. Else, test for the availability of various plugins and generate object/embed tags:

// this code uses Prototype.js
if(navigator.plugins && $A(navigator.plugins).detect(function(p){ return p.name.indexOf('QuickTime') != -1 }))
Sound.template = new Template('<object id="sound_#{track}_#{id}" width="0" height="0" type="audio/mpeg" data="#{url}"/>');
else if(navigator.plugins && $A(navigator.plugins).detect(function(p){ return p.name.indexOf('Windows Media') != -1 }))
Sound.template = new Template('');
else if(navigator.plugins && $A(navigator.plugins).detect(function(p){ return p.name.indexOf('RealPlayer') != -1 }))
Sound.template = new Template('');


Basically, the code tries to use QuickTime, Windows Media and RealPlayer to play back the sound. You could add a Flash failover, but for that you need specially crafted Flash files, and then you get yourself into the whole Flash blocker madness. Avoid.

3/15/2011

三吉外賣烤雞腿

三吉外賣烤雞腿

(B) 三吉外賣
(02)2389-7063
台北市萬華區武昌街2段85號之7 (日新戲院旁)

3/04/2011

15 Hacks Every Dropbox User Should Know

15 Hacks Every Dropbox User Should Know

Use Symbolic Links to Unlock Dropbox’s Potential
Mklink is a command line command short for “make link.” It’s used to create symbolic or hard links, which allow you to connect files and folder. It’s sort of like creating shortcuts, except that they’re handled at the operating system level, so they work with any program. You can, for instance, use mklink to fool Steam into thinking that a game on a different hard drive is actually in your Steam games folder. You can link files on a single computer, or across a local network. You cannot, however, link files across the internet.
1. Find the directory containing your Firefox profile. A default installation places this folder in %APPDATA%\Mozilla\Firefox
2. Copy that Firefox directory into your Dropbox folder.
3. Delete the original Firefox folder.
4. Use Mklink to create a hardlink between the new and original Firefox folders, If your Dropbox folder is in C:/ you can use the following command:

mklink /J %APPDATA%\Mozilla\Firefox C:/dropbox/Firefox

Store All Your Passwords with Keypass
That’s where KeePass comes in. KeePass is a free, open source password safe. It allows you to generate a unique, totally random password for every site or service you use, while only requiring you to remember a single master passphrase. Whenever you attempt to log into a service, KeePass asks for your master passphrase, then automatically enters the appropriate password from your safe.

Use Dropbox to manage BitTorrent
First, make sure you have a BitTorrent client capable of automatically loading .torrent files from a folder. All the big ones are capable of this, including uTorrent, Vuze, and the standard BitTorrent client. Next, set it up to monitor your DropBox, or a folder in your DropBox (My Documents/My Dropbox/Torrents for instance) and automatically open any .torrent file added to that folder.

Now, if you see a file you want to grab, just download the .torrent file to your Dropbox/Torrents folder, and your home PC will start the download as soon as DropBox syncs. It’s as simple as that.

3/02/2011

Understanding the node.js event loop « Mixu's tech blog

Understanding the node.js event loop « Mixu's tech blog

So the largest waste with current programming technologies comes from waiting for I/O to complete. There are several ways in which one can deal with the performance impact (from Sam Rushing):

* synchronous: you handle one request at a time, each in turn. pros: simple cons: any one request can hold up all the other requests
* fork a new process: you start a new process to handle each request. pros: easy cons: does not scale well, hundreds of connections means hundreds of processes. fork() is the Unix programmer’s hammer. Because it’s available, every problem looks like a nail. It’s usually overkill
* threads: start a new thread to handle each request. pros: easy, and kinder to the kernel than using fork, since threads usually have much less overhead cons: your machine may not have threads, and threaded programming can get very complicated very fast, with worries about controlling access to shared resources.
The second basis thesis is that thread-per-connection is memory-expensive: [e.g. that graph everyone showns about Apache sucking up memory compared to Nginx]

Apache is multithreaded: it spawns a thread per request (or process, it depends on the conf). You can see how that overhead eats up memory as the number of concurrent connections increases and more threads are needed to serve multiple simulataneous clients. Nginx and Node.js are not multithreaded, because threads and processes carry a heavy memory cost. They are single-threaded, but event-based. This eliminates the overhead created by thousands of threads/processes by handling many connections in a single thread.

An event loop is “an entity that handles and processes external events and converts them into callback invocations”. So I/O calls are the points at which Node.js can switch from one request to another. At an I/O call, your code saves the callback and returns control to the node.js runtime environment. The callback will be called later when the data actually is available.

Of course, on the backend, there are threads and processes for DB access and process execution. However, these are not explicitly exposed to your code, so you can’t worry about them other than by knowing that I/O interactions e.g. with the database, or with other processes will be asynchronous from the perspective of each request since the results from those threads are returned via the event loop to your code. Compared to the Apache model, there are a lot less threads and thread overhead, since threads aren’t needed for each connection; just when you absolutely positively must have something else running in parallel and even then the management is handled by Node.js.

Other than I/O calls, Node.js expects that all requests return quickly; e.g. CPU-intensive work should be split off to another process with which you can interact as with events, or by using an abstraction like WebWorkers. This (obviously) means that you can’t parallelize your code without another thread in the background with which you interact via events. Basically, all objects which emit events (e.g. are instances of EventEmitter) support asynchronous evented interaction and you can interact with blocking code in this manner e.g. using files, sockets or child processes all of which are EventEmitters in Node.js. Multicore can be done using this approach; see also: node-http-proxy.

Internal implementation

Internally, node.js relies on libev to provide the event loop, which is supplemented by libeio which uses pooled threads to provide asynchronous I/O. To learn even more, have a look at the libev documentation.


http://creationix.com/jsconf.pdf

3/01/2011

vim hacks

銀狐 Silver Fox 的碎碎唸: 轉載:『績效主義』毀了新力公司

銀狐 Silver Fox 的碎碎唸: 轉載:『績效主義』毀了新力公司

首先,『激情集團』不存在了。所謂『激情集團』,是指我參與開發CD技術時期,公司中那些不知疲倦、全身心投入開發的集體。在創業初期,這樣的“激情集團”接連不斷地開發出了具有獨創性的產品。我認為,新力當初之所以能做到這一點,是因為有井深的領導。

井深最讓人佩服的一點是,他能點燃技術開發人員心中之火,讓他們變成為技術獻身的『狂人』。在剛剛進入公司時,我曾和井深進行激烈爭論。井深對新人並不是採取高壓態度,他尊重我的意見。

為了不辜負他對我的信任,我當年也同樣潛心於研發工作。比我進公司更早,也受到井深影響的那些人,在井深退出第一線後的很長一段時間,仍以井深的作風影響著全公司。當這些人不在了,新力也就開始逐漸衰敗。

從事技術開發的團體進入開發的忘我狀態時,就成了『激情集團』。要進入這種狀態,其中最重要的條件就是『基於自發的動機』的行動。比如『想通過自己的努力開發機器人』,就是一種發自自身的衝動。

與此相反就是『外部的動機』,比如想賺錢、升職或出名,即想得到來自外部回報的心理狀態。如果沒有發自內心的熱情,而是出於『想賺錢或升職』的世俗動機,那是無法成為『開發狂人』的。


但是井深的想法與績效主義恰恰相反,他有一句口頭禪:『工作的報酬是工作。』就是說,如果你幹了件受到好評的工作,下次你還可以再幹更好、更有意思的工作。在井深的時代,許多人都是為追求工作的樂趣而埋頭苦幹。


2004年2月底,我在美國見到了『涌流理論』的代表人物奇凱岑特米哈伊教授,並聆聽了他的講演。講演一開始,大螢幕上放映的一段話是我自進入新力公司以來多次讀過的,只不過被譯成了英文。

『建立公司的目的:建設理想的工廠,在這個工廠裡,應該有自由、豁達、愉快的氣氛,讓每個認真工作的技術人員最大限度地發揮技能。』這正是新力公司的創立宗旨。新力公司失去活力,就是因為實行了績效主義。