2013-12-21

Wilt Thou Gallantly Tilt at Windmills

Tilting at windmills is an English idiom which means attacking imaginary enemies. The word “tilt”, in this context, comes from jousting.

The phrase is sometimes used to describe confrontations where adversaries are incorrectly perceived, or to courses of action that are based on misinterpreted or misapplied heroic, romantic, or idealistic justifications. It may also connote an importune, unfounded and vain effort against confabulated adversaries for a vain goal.

Wilt Thou Gallantly Tilt at Windmills?

2013-12-20

Writing Programing Tutorial vs Coding a Project

writing programing language tutorial isn't easy, and is extremely time consuming. Suppose you are reading a book or a doc. In few minutes, or even after a hour with coding, you understood it, and can employ it right away in your project or job. But, if you want to write a tutorial of what you just learned, it'll take 10 folds more time. Because, first of all you have to give context of why, and this aspect often takes some research by itself. Then, you have to have a good understanding of the whole instead of just the parts you just understood, because otherwise its like the blind men feeling the elephant and you can't say to readers that a elephant is pillar-like and period (this happens to haskell monad blogs). Then, you need to give good examples. Proper ones, and ones that are idiomatic, industrial accepted. So, it's like you have to have a survey of sorts, either from experience or have read tons about it. And, if you are like me, have idiosyncratic bent on things, you need to put things into style yet respect all the above mentioned issues. That doubles or triples the time and effort.

note that, this is not to imply that coding a project is easier. They are quite different endeavors. For example, if you are coding a project, once you read something, you can put to use right away, but, then you have 100 other details and complexities you need to solve, that you otherwise don't have to deal with if you are writing a tutorial. Tutorials typically deal only with clean, crystallized, account.

comment on g+

JavaScript Unicode Search box

major update on unicode search. You can search by name, codepoint (decimal or hexadecimal) or paste in Unicode characters. Search is now real-time. Result shows as you type. For example, try to find unicode related to christmas. 🎄 🎅.

Use the search box at Unicode Symbology ☢ ☯ ☭ ∑ ∞ ♀ ♂ ♥

unicode search screenshot 2013-12-17
Unicode search screenshot

2013-12-19

JavaScript Name Hosting and One-Liner Functional Style

JavaScript has name hosting. 〔☛ JavaScript: Variable & Function Declaration Order: Name Hoisting〕 and i think Douglas Crockford recommends to move all vars to the top, to reflect reality.

but look at the following code. Moving all var to the top would be silly.

function displaySearchResult (charArray, anchorNode) {
    // clear the result first
    while (anchorNode.hasChildNodes()) {
        anchorNode.removeChild(anchorNode.lastChild);
    }

    if ( charArray.length === 0 && searchBox.value.length !== 0) {
        var noResult = document.createElement("span");
        noResult.innerHTML = "none found. Try type more characters, or try “star”, decimal search “#97”, hexadecimal search “#x61”, or enter a Unicode “♥”";
        noResult.style.color="red";
        anchorNode.appendChild(noResult);
    } else {

        for (var ii = 0; ii < charArray.length ; ii++) {

            var uNum = charArray[ii];
            var uHex = uNum.toString(16);
            var uChar = String.fromCodePoint(uNum);
            var uName = unicodedata[uNum];

            var resultItem = document.createElement("table");
            resultItem.innerHTML = "<tr><td><span style='font-size:6ex'>" + uChar + "</span></td><td>" + uNum + "<br />x" + uHex + "</td></tr><tr><td colspan='2'>" + htmlEncode(uName) + "</td></tr>";

            resultItem.style.display="inline-block";
            resultItem.style.border="solid thin red";
            resultItem.style.width="18ex";
            resultItem.style.margin="0.2ex";
            resultItem.style.padding="0.2ex";
            resultItem.style.borderRadius="14px";

            anchorNode.appendChild(resultItem);
        } }}

i think to solve this, one'd do heavy functional style instead. That is, often just eliminate variables all together.

For example, this block:

var uNum = charArray[ii];
var uHex = uNum.toString(16);
var uChar = String.fromCodePoint(uNum);
var uName = unicodedata[uNum];

var resultItem = document.createElement("table");
resultItem.innerHTML = "<tr><td><span style='font-size:6ex'>" + uChar + "</span></td><td>" + uNum + "<br />x" + uHex + "</td></tr><tr><td colspan='2'>" + htmlEncode(uName) + "</td></tr>";

would be rewritten as:

resultItem = document.createElement("table");
resultItem.innerHTML = (function(uChar, uNum, uHex, uName ){return "<tr><td><span style='font-size:6ex'>" + uChar + "</span></td><td>" + uNum + "<br />x" + uHex + "</td></tr><tr><td colspan='2'>" + htmlEncode(uName) + "</td></tr>"})( charArray[ii], uNum.toString(16), String.fromCodePoint(uNum), unicodedata[uNum] )

yep. I think that's what i'll do. How this reminds me my Mathematica code days. My Mathematica code is all like that.

g+ discussion https://plus.google.com/+XahLee/posts/776XQf46CvZ