2015年12月21日 星期一

Javascript - ES7 包著糖衣的 async

webber0928

ES7 的新功能 -  async ... awite

但是在做 foreach 的時候卻碰到問題,我的觀念是 async 幫我做到平行處理的機制,

但是加上 foreach 後完全不是這麼回事...

詢問一下古哥,他幫我找到了這篇 Taming the asynchronous beast with ES7

他一樣有碰到 Loop 的問題

However, if you try to use an async function, then you will get a more subtle bug:
let docs = [{}, {}, {}];

// WARNING: this won't work
docs.forEach(async function (doc, i) {
await db.post(doc);
console.log(i);
});
console.log('main loop done');
This will compile, but the problem is that this will print out:
main loop done
0
1
2
解法如下:
let  docs  =  [{},  {},  {}]; 
let promises = docs . map (( doc ) => db . post ( doc ));

let results = [];
for ( let promise of promises ) {
results . push ( await promise );
}
console . log ( results );

筆記...


Javascript - ES7 包著糖衣的 async

webber0928

ES7 的新功能 -  async ... awite

但是在做 foreach 的時候卻碰到問題,我的觀念是 async 幫我做到平行處理的機制,

但是加上 foreach 後完全不是這麼回事...

2015年10月30日 星期五

設定 domains 在你的 GitHub Pages

webber0928
最近發生了一件事情,就是以前幫我的 github.io 綁的網域過期了,然後我的所有頁面都會變成 404 page,讓我困擾很久,最近想說 github 的文件上可能有就去看了一下




他只教我怎麼設定,卻沒教我怎麼移除...,不過就在昨天我突然開竅了,其實設定就是在你的 github 裡面放一個檔案名為 CNAME 的文件,再把 Domains 寫進檔案裡( cc.bird123.ml )就可以了.....

所以....只要移除 CNAME 這個檔案就可以移除綁定了!!

||orz....

2015年9月18日 星期五

Bootstrap 的工具 Social Buttons

webber0928



最近剛好要做 github 的按鈕,想說網路上應該有人做好了吧!

果然已經有人做好了,就是這個  Social Buttons for Bootstrap

幾乎各大網站的 icon button 都有,一下就搞定了~潮爽der


github: https://github.com/lipis/bootstrap-social

web: http://lipis.github.io/bootstrap-social/

Bootstrap 的工具 Social Buttons

webber0928



最近剛好要做 github 的按鈕,想說網路上應該有人做好了吧!

果然已經有人做好了,就是這個  Social Buttons for Bootstrap

幾乎各大網站的 icon button 都有,一下就搞定了~潮爽der


2015年9月17日 星期四

[ github ] 忽略目錄裡的文件但不忽略目錄的方法

webber0928

有時候我們想保留一個目錄在Git版本庫上,但不需要其中的文件。
log --
|- 1.log

|- 2.log



而Git本身不允許空目錄提交上去,一個方法是在目錄下創建一個文件
    mkdir log && touch log/.gitkeep && git add log/.gitkeep

Coprights @ 2016, Blogger Templates Designed By Templateism | Distributed By Gooyaabi Templates