Skip to main content

Future proved Javascript and CSS

· 3 min read

This time, its different. The transpilers are build-time polyfills that fill the gap of current browser/server implementation and the newest JS/CSS specs.

Transpilers trans-compile Javascript and CSS to current workable version, so developers could be more productive with JS/CSS latest features and transpilers would translate them into current supported version of code.

From my opinion the most useful es6 feature is arrow functions (=>) which comes from coffeescript. This syntax sugar bind the this value automatically, so developer wont forgot the binding anymore.

The original code is

(function() {
‘use strict’;
document.addEventListener(‘DocumentLocalized’, function() {
// App.init();
}.bind(this));
}());

We can use arrow function to replace function() {}.bind(this) to () => {}

(function() {
‘use strict’;
document.addEventListener(‘DocumentLocalized’, () => {
// App.init();
});
}());

Currently the arrow functions only default enabled on Firefox. So developer could not use this directly on their project. With babel javascript transpiler the js could be translated to current workable version automatically.

(function() {
‘use strict’;
document.addEventListener(‘DocumentLocalized’, function() {
// App.init();
});
}());

The transpiler will know the content does not need 'this' reference and skip the binding. Note the Javascript transpiler still stick into vanilla javascript. It does not invent new syntax, but it make new specs could be used or experiment in current environment.

From CSS perspective, CSS variables brings variables into CSS. Pre-define some color and use everywhere on project is possible.

The origin style is

a {
color: #847AD1;
}

pre {
padding: 10px;
}

It's frustrated when the stylesheets expand larger and we need to change the new color or size everywhere.

We can use CSS variables to predefine the changeable stuff into pseudo ':root' element.

:root {
–maincolor: #847AD1;
–size: 10px;
}

a {
color: var(–maincolor);
}

pre {
padding: var(–size);
}

Looks good. But the same situation occurred. Currently the CSS variables only support on Firefox. So developer could not use this directly on their project. With myth CSS transpiler the CSS could be translated to current workable version automatically.

a {
color: #847AD1;
}

pre {
padding: 10px;
}

Note the CSS transpiler still stick into CSS specs. It does not invent new syntaxes like LESS or SASS does. It just make new CSS specs could be used or experiment in current environment.

Besides the feature polyfill, running transpiler before deploy also help developer catch out the error since transpiler will traverse the source and parsing syntaxes. Transpiler will bark you when any error in your source.

You may wonder setup an environment with above JS/CSS transpiler seems take some time. webapplate 2.3.0 already integrated with babel  and myth grunt tasks to auto transpile your JS/CSS code to current workable version. webapplate jshint/githook also support es6 syntax validation (yes the .jshintrc is exactly borrowed from gaia project), so your project is future proved and keep maintainable.

用 IFTTT 做自動生活紀錄 (LifeLog)

· 3 min read

我會想要把看過的書籍、電影,喜歡的 Youtube 影片,貼過的文章等記錄下來,之後可以方便回顧。過去要這麼做,少不了得手工紀錄,但手動紀錄其實是相當沒效率的。

過去幾年裡,我使用 Google 日曆紀錄簡單的一行日記,使用 Anobii 紀錄讀過的書與心得,使用豆瓣電影紀錄看過的影片,使用 Facebook/Google+、Blogger 等分享連結與寫文章。最近我的做法仍然沒有改變,但會利用 IFTTT 來自動將我更新的書、影片、分享過的連結等自動紀錄到我的 Google 日曆中。

IFTTT 是一個幫你連結各種不同網路服務的自動化工具,包括 Google Calendar、Facebook、Evernote、RSS 等各種服務。其運作方式是先指定一些需要的配方(Receipe)。

IFTTT 會定時追蹤你使用的一些服務的狀況。當你的配方中包含的服務的內容改變時(如 Blogger 上有更新的文章),IFTTT 可以自動將結果添加到你的另一個服務中(如加入至日曆)。

以我自己為例,要將 Blogger 上的文章更新到我的日曆,只需先找出我的 Blogger RSS http://blog.gasolin.idv.tw/feeds/posts/default,然後建立「RSS -> Google 日曆」的配方即可。Anobii 或豆瓣的做法也類似。

   另一類則是從社群網站將文章加到日曆,也是建立簡單的規則即可做到。

我的生活紀錄 (LifeLog) 現在能自動記錄的資料有:

  • Facebook 貼文
  • Blogger 貼文
  • Anobii 書籍
  • 豆瓣書籍 / 音樂更新
  • Youtube 設為喜歡的影片

Update at 2016/12/19

  • Twitter 貼文
  • Todoist 完成的事項

如果你有其他自動生活紀錄 (LifeLog) 的想法,也歡迎與我分享。

Single line of style to bring (keypart of) f.lux on FirefoxOS

· 3 min read

Claim: this exercise is for experiment, not for product.

According to wikipedia, f.lux adjusts a computer display's color temperature according to its location and time of day. I always use it on my Mac to make my eyes more comfortable at night.

So, the topic is about if we can bring that experience on Firefox OS. Adjust display's color temperature generally is a system specific issue. But actually it can be categorized as an CSS trick if we like to make it on web (a gist to mimic the f.lux effect).

To quick experiment if it doable or not, the validation steps are:

1. open the WebIDE on Firefox Developer Edition 2. download and open emulator (I choose v2.2) on WebIDE. 3. To debug system app, choose System from top left selector in WebIDE. 4. once connected,  select the html tag and add style **filter: brightness(0.8) sepia(0.9);** into the element.

The live view changed to f.lux like color temperature.

So it works!

To make it persistent on real device, edit [gaia/apps/system/style/system/system.css](https://github.com/mozilla-b2g/gaia/blob/master/apps/system/style/system/system.css#L5), add above style into html tag. Run make reset-gaia then you have the style applied on device.

What's Next

The above experiment will change your device's color temperature permanently, which is not what f.lux do. To make it as option, you can add an option in settings > developer panel and add a observer in system to dynamically add such style into system html tag.

If you feel the strong desire to have such feature happen on Firefox OS device, fire a bug on bugzilla.

隱私與 Hololens

· One min read

近期最激動人心的新科技當屬 Hololens。

Kinect 動態捕捉 + AR 增強現實 + VR 虛擬現實,將這些令人讚嘆的系統縮小綑綁成一個頭戴裝置。這樣的技術與願景,可以說甚至超越了上個世紀我們對 21 世紀的想像。

如果價格與電腦相去不遠,實在令人難以拒絕這樣的裝備。

然而也不禁反省,有天當技術變成生活的一部分,人們可能會選擇自願放棄一部分隱私,以換取享受科技與網路帶來的便利。當使用的人多了,就形成了一股社會壓力,不用也不成。

「天地萬物﹐朕賜給你的才是你的﹐朕不給﹐你不能搶。」,你看到的,都變成某些公司或團體想讓你看的;你沒看到的,可能是某些公司 / 政府要求屏蔽下來不讓你看的。

OddWerx 與 ROMO

· 2 min read

我們先來看兩段影片,兩個產品都是為手機加裝底座,讓手機變成可移動,可和人互動的機器人。

OddWerx

OddWerx 在 2012/4 於 kickstarter 上募款失敗。

ROMO

ROMO 在 2011/112012/11兩次上 Kickstarter 募款都成功。

也許是算上包裝設計等成本,ROMO (170) 比起 OddWerx (99) 貴上不少。 即使 OddWerx 和 ROMO 提供的實際功能其實差不多,比較兩個「產品」,一個是需要動手組裝的套件,一個是買來即可用的玩具。

兩個專案的成功與否,是因為在眾籌網站上出沒的大眾還是偏好看起來立即可用的產品,還是因為在 OddWerx 之前 ROMO 已經出現了,比起來沒什麼新鮮感?