Skip to content

Instantly share code, notes, and snippets.

@Fandora
Fandora / htmlEscape.js
Created July 21, 2012 09:00
htmlEscape.js
function htmlEscape(html) {
return String(html)
.replace(/&/g, '&')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;');
}
@Fandora
Fandora / metro-color.less
Created June 29, 2012 09:56
metro-color.less
@metro-blue : #1BA1E2;
@metro-red : #E51400;
@metro-green : #393;
@metro-orange : #F09609;
@metro-purple : #A200FF;
@metro-pink : #E671B8;
@metro-magenta : #FF0097;
@metro-brown : #A05000;
@metro-lime : #8CBF26;
@metro-teal : #00ABA9;
@Fandora
Fandora / gist:2981942
Created June 24, 2012 06:22
mongoose ObjectId
var ObjectId = require("mongoose").Types.ObjectId;
module.exports.toObjectId = function(idstr) {
try {
return ObjectId(idstr);
} catch (err) {
console.log(err);
throw new errors.BadRequest("錯誤的序號");
}
}
@Fandora
Fandora / animatedScroll.js
Created May 3, 2012 07:28
Animated Scroll
$('.scrollPage').click(function() {
var elementClicked = $(this).attr("href");
var destination = $(elementClicked).offset().top;
$("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination-20}, 500 );
return false;
});
@Fandora
Fandora / node-paypal-expresscheckout.js
Created March 16, 2012 02:47
node.js + paypal express checkout
var Request = require("request");
// USER: API 用戶名稱
// PWD: API 密碼
// SIGNATURE: 簽名
/* METHOD: SetExpressCheckout
RETURNURL:當於PayPal 網站完成明細確認後,瀏覽器將帶顧客返回至此網址。
CANCELURL:當顧客選擇終止付款時,瀏覽器將帶顧客返回至此網址。
@Fandora
Fandora / foreach_and_log_hack.js
Created January 12, 2012 08:27
foreach_and_log_hack.js
var _alert_fallback = false;
if (typeof console === "undefined" || typeof console.log === "undefined") {
console = {};
if (_alert_fallback) {
console.log = function(msg) {alert(msg);};
} else {
console.log = function() {};
}
}
@Fandora
Fandora / xssQQ.js
Created December 24, 2011 14:30
escape物件裡的每一個屬性
var htmlEscape = function(html){
return String(html)
.replace(/&(?!\w+;)/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;');
};
var xssQQ = function(obj) {
console.log("before xssQQ");
console.dir(obj);
@Fandora
Fandora / MVC or not-MVC.js
Created December 19, 2011 03:25
MVC or not-MVC
app.post("/api/upload-picture", function(req, res) {
if(!req.session.signined) {
throw new BadRequest("signin first");
}
if(!req.files.picture) {
throw new BadRequest("illegal file element name");
}
var h = new UploadPictureHandler(req, res);
h.run();
});
@Fandora
Fandora / Dict.js
Created November 29, 2011 01:34
字典檔範例
var zhTW = {
_name : "繁體中文"
, home : "首頁"
, contactUs : "聯繫我們"
, feedback : "意見回饋"
};
var en = {
_name : "English"
, home : "home"
@Fandora
Fandora / app.js
Created November 29, 2011 01:25
在express.js添加處理locale的middleware
app.configure(function(){
...
// i18n
var Dict = require("./Dict");
app.use(function(req, res, next){
// 取得語系
var localestr = req.headers["accept-language"];
var arr = localestr.split(",");