This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{"0.7669349809659356":"-----BEGIN PGP PUBLIC KEY BLOCK-----\r\nCharset: UTF-8\r\n\r\nxv8AAABSBAAAAAATCCqGSM49AwEHAgME0b5ofxFbwFsuDX+S26Fc5vclkP1NIu1B\r\n935+8V12CSu4iYmjamXdf6Cp9oquew2R7aadwpnxL3MmUd4+sHWAAs3/AAAACDxn\r\naXRodWI+wv8AAACOBBATCABA/wAAAAWCWgnILP8AAAACiwn/AAAACZCg4yCEZqNX\r\npv8AAAAFlQgJCgv/AAAABJYDAQL/AAAAApsD/wAAAAKeAQAA6HsA/2ahuiBgRKgh\r\nTEjbHxO1PVUSY5PYl6+If8ehiNIu6n8hAQDGEvXgqT/JE4kVhD+31ANwiSpElHh8\r\nKOcKWI9oynumZ87/AAAAVgQAAAAAEggqhkjOPQMBBwIDBCBem++V4+GlvZNdQZuM\r\n/wuVbhxeNbQePMTiVJ7wTApTUqZaGReeh9nEAHXVQ1wAig7Cmsnhj0dTxnDB6e/l\r\n44IDAQgHwv8AAABtBBgTCAAf/wAAAAWCWgnILP8AAAAJkKDjIIRmo1em/wAAAAKb\r\nDAAApLUA/1R8W9gl/H2X/1DueTOr0Cv/rInBfCzvdGdQB0WmPKllAP9215qBXsia\r\n9VWfRao3lG87EMYzrz7pzfTHZU3LEXvFfw==\r\n=A4Rt\r\n-----END PGP PUBLIC KEY BLOCK-----\r\n"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
function convertKeywordsToRegStr(keywords) { | |
return '(' + keywords.trim().replace(/[^\w\u4E00-\u9FA5]+/g, '|') + ')'; | |
} | |
function getHighlightFn(keywords, highlightClass) { | |
var regexpStr = convertKeywordsToRegStr(keywords); | |
if (regexpStr.length === 2) { | |
return function (sourceText) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var num=12; | |
//12 -> c | |
var hex=12.toString(16);//same for other conditions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
var Q = require('q'); | |
function prepare(data) { | |
// return Q(data); | |
return Q.reject(new Error('special error1')); | |
} | |
function judgeError(err) { | |
console.log('catch: ', err); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* always put errorHandler in the last 'then' with a 'null' logic handler, | |
* so that all errors will be caught | |
*/ | |
someModule.promiseFunc() | |
.then(function (data) { | |
//TODO other logic | |
}) | |
.then(null, errorHandler); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var request = require('request'); | |
function setDownloadName(req, res, fileName) { | |
var userAgent = (req.headers['user-agent'] || '').toLowerCase(); | |
if (userAgent.indexOf('chrome') > -1) { | |
res.setHeader('Content-Disposition', 'attachment; filename=' + encodeURIComponent(fileName)); | |
} else if (userAgent.indexOf('firefox') >-1) { | |
res.setHeader('Content-Disposition', 'attachment; filename*="utf8\'\'' + encodeURIComponent(fileName) + '"'); | |
} else { | |
res.setHeader('Content-Disposition', 'attachment; filename=' + new Buffer(fileName).toString('binary')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* cryptojs use WordArray (CryptoJS.lib.WordArray) as parameter/result frequently. | |
* A WordArray object represents an array of 32-bit words. When you pass a string, | |
* it's automatically converted to a WordArray encoded as UTF-8. | |
*/ | |
var CryptoJS = require("crypto-js"); | |
// convert String to WordArray | |
var wordArray = CryptoJS.enc.Utf8.parse('Hello, World!'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var CryptoJS = require("crypto-js");//replace thie with script tag in browser env | |
//encrypt | |
var rawStr = "hello world!"; | |
var wordArray = CryptoJS.enc.Utf8.parse(rawStr); | |
var base64 = CryptoJS.enc.Base64.stringify(wordArray); | |
console.log('encrypted:', base64); | |
//decrypt | |
var parsedWordArray = CryptoJS.enc.Base64.parse(base64); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var CryptoJS = require("crypto-js");//replace this with script tag in browser env | |
var encrypted = CryptoJS.AES.encrypt("Message", "Secret Passphrase").toString(); | |
console.log(encrypted); | |
var decrypted = CryptoJS.AES.decrypt(encrypted, "Secret Passphrase").toString(CryptoJS.enc.Utf8); | |
console.log(decrypted); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//最好总是使用带this绑定的q方法(相对保险) | |
Q.ninvoke(object, methodName, ...args); //直接执行 | |
Q.nbind(nodeMethod, thisArg, ...args); //返回绑定参数后的方法 | |
//不带直接绑定this作用域的,如果方法内用到了this,可能需要手动绑定 | |
Q.nfcall(obj.method.bind(obj), ...args) | |
Q.nfapply(obj.method.bind(obj), args) | |
//其他类似 ... |
NewerOlder