2014/03/20

[HTML5]利用ajax做檔案下載



同事說不可能用1個ajax去下載檔案

於是乎我就研究了一下
程式碼如下:

js code:
<script>
$(function(){
 $.ajax('/ajax/getFile', {dataType:'json', success:function(data){
   var bb = new Blob([data.content], {type: 'application/octet-binary'});
   $('#link')
   .attr({download:'file.bin',href:window.URL.createObjectURL(bb)})
 }});
});
</script>
其實這是利用<a>的download屬性(Working Draft:w3schools)
加上Blob這物件將檔案內容轉為blob格式使得瀏覽器可以下載

html:
<div id="main">
 <a id="link">Download File</a>
</div>

backend: (use nodejs express)

exports.getFile = function(req, res){
 fs.readFile('file', function (err, data) {
  res.json({status:'ok',content:data.toString()});
 });
};


reference:
http://caniuse.com/download
http://html5-demos.appspot.com/static/a.download.html

2014/01/27

[網站]好用的css icon網站



1. [http://findicons.com](http://findicons.com)

2. [http://www.webhostinghub.com](http://www.webhostinghub.com)

在linux下利用iptables做nat




由於最近有一個環境

guestA(external IP: 1.1.1.1, internal IP: 192.168.56.2)
guestB(internal IP: 192.168.56.3)

在同一個host下有兩台virtualbox guest中,只有一台有外部ip(1.1.1.1)

2013/08/20

手機 響一下就掛掉清單

2013/08/20 17:24 0936349011
2013/07/01 17:04 0982420559
2013/12/23 16:02 0981403774
2014/07/25 10:28 0937860253
2015/01/05 10:09 02-27421301

接起來就掛掉:
2014/05/12 16:49 0916506545

2013/04/18

[VirtualBox] 修改虛擬硬碟的UUID



要複製一份vm最快的方法就是直接clone你的虛擬硬碟檔了

可以VirtualBox會檢查這個虛擬硬碟檔的UUID是否已存在

若存在就不會讓你掛載到第二個VM中

在此提供一個指令可以修改虛擬硬碟中的UUID

VBoxManage internalcommands sethduuid "你的vdi檔案"

Example:
```
VBoxManage internalcommands sethduuid C:\test.vdi
```

2013/04/16

看justin/twitch實況很LAG?掛proxy就對了



其實網路上有一堆看實況掛proxy的教學

那為什麼我還要再寫一篇呢?

因為網路上的通常一掛proxy後,所有網站都會透過這個proxy作傳輸