Nodejs - 下載 csv 的注意事項

主要是res.write需要加入new Buffer('EFBBBF', 'hex')
不然從excel無法正確看到文字

var s = '報名序號'
var content = new Buffer(s);

res.set('Content-Type', 'text/csv; charset=utf-8');
res.set("Content-Disposition", "attachment;filename=teams.csv");

res.write(new Buffer('EFBBBF', 'hex')) // For excel, need BOM
res.end(content);

brew - 加強 terminal 功能

Website http://brew.sh

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew install bash-completion
brew install nvm

~/.bash_profile

if [ -f ~/.bashrc ]; then
source ~/.bashrc
fi

if [ -f $(brew --prefix)/etc/bash_completion ]; then
. $(brew --prefix)/etc/bash_completion
fi

export NVM_DIR=~/.nvm
. $(brew --prefix nvm)/nvm.sh

alias l='ls'
alias ll='ls -la'

export CLICOLOR=1
export LSCOLORS=dxfxcxdxbxegedabagacad

# Pretty terminal prompt
export PS1='\u@\H:\w$ '

Read More

我的 Sublime 設定

Preferences->Setting-User

{
"default_line_ending": "unix",
"draw_white_space": "all",
"font_size": 14,
"ignored_packages":
[
"Vintage"
],
"tab_size": 4,
"translate_tabs_to_spaces": true,
"trim_trailing_white_space_on_save": true,

// set vertical rulers in specified columns.
// Use "rulers": [80] for just one ruler
"rulers": [80],

// turn on word wrap for source and text
// default value is "auto", which means off for source and on for text
"word_wrap": true,

// set word wrapping at this column
// default value is 0
"wrap_width": 80
}

Preferences->Key Binding-User

[
{ "keys": ["f12"], "command": "reindent", "args": { "single_line": false } },
// Refresh folder list with F5
{ "keys": ["f5"], "command": "refresh_folder_list" },
{ "keys": ["alt+/"], "command": "auto_complete" }, {
"keys": ["alt+/"],
"command": "replace_completion_with_auto_complete",
"context": [
{ "key": "last_command", "operator": "equal", "operand": "insert_best_completion" },
{ "key": "auto_complete_visible", "operator": "equal", "operand": false },
{ "key": "setting.tab_completion", "operator": "equal", "operand": true }
]
}
]

在 c9.io 環境上運行 Node.js

需要注意的是,必須使用cloud 9的環境變數process.env.PORT, process.env.IP

server.js

var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(process.env.PORT, process.env.IP);

在 Ubuntu 12.04 安裝 Node.js

  • 安裝nvm並加入環境變數中
  • 用nvm安裝nodejs v5.1.0
  • 更新gcc, g++版本
#!/bin/bash
test "$(grep 'NVM_NODEJS_ORG_MIRROR' /etc/bash.bashrc)" || echo 'export NVM_NODEJS_ORG_MIRROR=http://nodejs.org/dist' >> /etc/bash.bashrc
test "$(grep 'NVM_DIR' /etc/bash.bashrc)" || echo 'export NVM_DIR="/etc/nvm"' >> /etc/bash.bashrc
test "$(grep 'nvm.sh' /etc/bash.bashrc)" || echo '[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm' >> /etc/bash.bashrc
NVM_DIR="/etc/nvm"
NVM_NODEJS_ORG_MIRROR="http://nodejs.org/dist"
git clone https://github.com/creationix/nvm.git $NVM_DIR && cd $NVM_DIR && git checkout `git describe --abbrev=0 --tags`

. $NVM_DIR/nvm.sh
nvm install v5.1.0
nvm alias default 5.1

echo 'deb http://cz.archive.ubuntu.com/ubuntu trusty main' >> /etc/apt/sources.list
apt-get update; apt-get install -y gcc-4.8 g++-4.8
update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.8 10
update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 10