Skip to content

Instantly share code, notes, and snippets.

View heroicyang's full-sized avatar
🎯
Focusing

Heroic Yang heroicyang

🎯
Focusing
View GitHub Profile
@heroicyang
heroicyang / gulpfile.js
Created July 25, 2014 02:08
Browserify task
var gulp = require('gulp');
var source = require('vinyl-source-stream');
var browserify = require('browserify');
var watchify = require('watchify');
gulp.task('setWatch', function() {
global.isWatching = true;
});
gulp.task('browserify', function() {
{
"vars": {
"@gray-base": "#000",
"@gray-darker": "lighten(@gray-base, 13.5%)",
"@gray-dark": "lighten(@gray-base, 20%)",
"@gray": "lighten(@gray-base, 33.5%)",
"@gray-light": "lighten(@gray-base, 46.7%)",
"@gray-lighter": "lighten(@gray-base, 93.5%)",
"@brand-primary": "darken(#428bca, 6.5%)",
"@brand-success": "#5cb85c",
@heroicyang
heroicyang / gist:5161470
Created March 14, 2013 13:51
树遍历操作
var id = 1;
(function loop (children) {
var nextChildren = [];
_.map(children, function (child) {
child.uid = child.name + '-' + id;
if (child.children && child.children.length > 0) {
nextChildren = nextChildren.concat(child.children);
}
id += 1;
});
@heroicyang
heroicyang / array uniq
Created May 17, 2013 12:15
数组去重(uniq)
function uniq (arr1, arr2) {
var result = arr1.concat(arr2)
, len = result.length;
for (var i = 0; i < len; i++) {
var firstIdx = result.indexOf(result[i])
, lastIdx = result.lastIndexOf(result[i]);
while (firstIdx !== lastIdx) {
result.splice(lastIdx, 1);
len = len - 1;
@heroicyang
heroicyang / test.js
Created May 26, 2013 04:32
“清华大学一名男生给女生写的明信片”之Node解码版
var _ = require('underscore')
, iconv = require('iconv-lite');
var codes = [214,247,210,170,190,205,202,199,207,235,202,212,202,212,184,248,212,219,195,199,188,196,208,197,202,177,181,216,214,183,191,201,210,212,208,180,181,195,182,224,188,242,194,212,161,173,161,173];
var str = _.map(codes, function (code) {
return String.fromCharCode(code);
}).join('');
console.log(iconv.decode(new Buffer(str, 'ascii'), 'gbk'));
@heroicyang
heroicyang / handlebars.debugHelper.js
Created June 19, 2013 04:00
Handlebars调试技巧:增加如下helper之后,在模板文件里使用{{debug}}或是{{debug someValue}}即可
Handlebars.registerHelper("debug", function(optionalValue) {
console.log("Current Context");
console.log("====================");
console.log(this);
if (optionalValue) {
console.log("Value");
console.log("====================");
console.log(optionalValue);
}
});
@heroicyang
heroicyang / jshint_options.json
Created June 24, 2013 03:42
My jshint options
"jshint_options":
{
"bitwise": false,
"camelcase": true,
"curly": true,
"eqeqeq": true,
"indent": 2,
"plusplus": true,
"undef": true,
"unused": true,
@heroicyang
heroicyang / open_chrome.sh
Created October 11, 2013 03:15
Chrome 30.0.1599.69 for Mac 崩溃解决办法
# 终端中输入下面命令来打开 Chrome
/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --winhttp-proxy-resolver
@heroicyang
heroicyang / ybjxbf.json
Created October 30, 2013 05:02
我的“眼不见心不烦”配置
{"whiteKeywords":[],"blackKeywords":[],"grayKeywords":[],"URLKeywords":[],"sourceKeywords":[],"sourceGrayKeywords":[],"userBlacklist":["1706976420"],"tipBackColor":"#FFD0D0","tipTextColor":"#FF8080","readerModeIndex":false,"readerModeProfile":false,"readerModeWidth":"750","readerModeBackColor":"rgba(100%, 100%, 100%, 0.8)","mergeSidebars":true,"floatSidebar":true,"unwrapText":true,"directBigImg":true,"directFeeds":false,"showAllGroups":true,"showAllMsgNav":true,"noDefaultFwd":true,"noDefaultGroupPub":true,"clearDefTopic":true,"overrideMyBack":false,"overrideOtherBack":false,"backColor":"rgba(100%, 100%, 100%, 0.2)","overrideMySkin":false,"overrideOtherSkin":false,"skinID":"skinvip001","filterOthersOnly":true,"filterPaused":false,"filterSmiley":false,"filterPromotions":true,"filterDeleted":true,"filterFeelings":true,"filterTaobao":false,"filterDupFwd":false,"maxDupFwd":"1","filterFlood":false,"maxFlood":"5","updateNotify":true,"autoSync":true,"floatBtn":true,"useCustomStyles":true,"customStyles":".WB_global_na
@heroicyang
heroicyang / express-fileuploader-intro.md
Created January 3, 2014 15:25
express-fileuploader 简介

这是我在开发 nodediscuss 的过程中实现的,现在单独拆分出来作为一个库,方便有文件上传需求的同学们。

GitHub: https://github.com/heroicyang/express-fileuploader

特性

  • 在上传成功之后自动删除临时文件(原因请参见这里
  • 不负责 multipart 解析,你可以自由选择 multipart parser
  • 插件式,可插拔
  • 可根据自己的需求自定义上传逻辑(Strategy),比如将文件上传至 Dropbox