Skip to content

Instantly share code, notes, and snippets.

View JerryC8080's full-sized avatar
🇨🇳
Hi~!

JerryC JerryC8080

🇨🇳
Hi~!
View GitHub Profile
@JerryC8080
JerryC8080 / date.js
Created December 16, 2014 15:11
ghost date helper
// # Date Helper
// Usage: `{{date format="DD MM, YYYY"}}`, `{{date updated_at format="DD MM, YYYY"}}`
//
// Formats a date using moment.js. Formats published_at by default but will also take a date as a parameter
var moment = require('moment'),
date;
date = function (context, options) {
if (!options && context.hasOwnProperty('hash')) {
@JerryC8080
JerryC8080 / excerpt.js
Created December 17, 2014 03:38
Excerpt Helper
// # Excerpt Helper
// Usage: `{{excerpt}}`, `{{excerpt words="50"}}`, `{{excerpt characters="256"}}`
//
// Attempts to remove all HTML from the string, and then shortens the result according to the provided option.
//
// Defaults to words="50"
var hbs = require('express-hbs'),
_ = require('lodash'),
downsize = require('downsize'),
@JerryC8080
JerryC8080 / findOrCreate use way
Last active August 29, 2015 14:19
Sails Model.findOrCreate method use way with promise style
var Promise = require("bluebird");
return Promise.map(objects, function (object) {
sails.log.info('An object will be created:');
sails.log.info(object);
return Comment.findOrCreate(object.id , object);
}).then(function (objects) {
sails.log.info('The objects created or found goes here: ');
sails.log.info(objects);
return objects;
@JerryC8080
JerryC8080 / 邮箱字符遮罩
Created February 17, 2016 03:27
邮箱字符遮罩
/**
* 邮箱字符遮罩
* @param email
* @returns {string}
* @private
*/
function _hideEmail(email) {
var accounts = email.split('@')[0];
var suffix = email.split('@')[1];
var hideNums = Math.floor(accounts.length/2);
@JerryC8080
JerryC8080 / generateZhPhone.js
Last active March 21, 2016 08:06
使用Chance,随机生成中国电话号码
let chance = require('chance')();
function generatePhone(nums) {
if (!nums){
nums = 1;
}
return chance.unique(function generatePhone() {
let phone = '1';
phone+= chance.string({length: 1, pool: '34578'});
phone+= chance.string({length: 9, pool: '9876543210'});
@JerryC8080
JerryC8080 / gist:cbeb6011e33445ac2d5d
Created March 27, 2016 15:44 — forked from AliMD/gist:3344523
All github Emoji (Smiles)

All github Emoji (Smiles)

ali.md/emoji

:bowtie: | 😄 | 😆 | 😊 | 😃 | ☺️ | 😏 | 😍 | 😘 | :kissing_face: | 😳 | 😌 | 😆 | 😁 | 😉 | :wink2: | 👅 | 😒 | 😅 | 😓

😩 | 😔 | 😞 | 😖 | 😨 | 😰 | 😣 | 😢 | 😭 | 😂 | 😲 | 😱 | :neckbeard: | 😫 | 😠 | 😡 | 😤 | 😪 | 😋 | 😷

😎 | 😵 | 👿 | 😈 | 😐 | 😶 | 😇 | 👽 | 💛 | 💙 | 💜 | ❤️ | 💚 | 💔 | 💓 | 💗 | 💕 | 💞 | 💘 | ✨

@JerryC8080
JerryC8080 / index.javascript
Last active April 21, 2016 12:01 — forked from shanelau/index.javascript
中文转拼音
var unidecode = require('unidecode');
var safeString = function (string) {
string = string.trim();
// Remove non ascii characters
string = unidecode(string).trim();
// Remove URL reserved chars: `:/?#[]@!$&'()*+,;=` as well as `\%<>|^~£"`
string = string.replace(/[:\/\?#\[\]@!$&'()*+,;=\\%<>\|\^~£"]/g, '')
// Replace dots and spaces with a dash
@JerryC8080
JerryC8080 / git_toturial
Created May 26, 2016 02:21 — forked from guweigang/git_toturial
git命令大全
git init # 初始化本地git仓库(创建新仓库)
git config --global user.name "xxx" # 配置用户名
git config --global user.email "xxx@xxx.com" # 配置邮件
git config --global color.ui true # git status等命令自动着色
git config --global color.status auto
git config --global color.diff auto
git config --global color.branch auto
git config --global color.interactive auto
git config --global --unset http.proxy # remove proxy configuration on git
git clone git+ssh://git@192.168.53.168/VT.git # clone远程仓库
@JerryC8080
JerryC8080 / outOfHeap.js
Last active October 30, 2016 14:45
内存泄漏脚本
/**
* 泄露V8 Heap内存
*/
let total = [];
function useMem() {
let size = 1024 * 1024 * 20; // Per 20MB
let arr = new Array(size);
for (let i = 0; i < size; i++) {
@JerryC8080
JerryC8080 / proxy.js
Created November 30, 2016 04:41 — forked from ruanyf/proxy.js
使用 Proxy 实现观察者模式
// 实现
const queuedObservers = new Set();
const observe = fn => queuedObservers.add(fn);
const observable = obj => new Proxy(obj, {set});
function set(target, key, value, receiver) {
const result = Reflect.set(target, key, value, receiver);
queuedObservers.forEach(observer => observer());
return result;