Skip to content

Instantly share code, notes, and snippets.

View legend80s's full-sized avatar
🎯
Focusing

legend80s

🎯
Focusing
View GitHub Profile
@legend80s
legend80s / myConsole.js
Last active March 23, 2017 04:46
Console with customized header which can be static or dynamic
/**
* Console with customized header which can be static or dynamic
*
* @example
* // static header
* const console = myConsole({ header: '[OpenSearch]' });
* console.log('App Type is %s', 'Advance'); // Output: "[OpenSearch] App type is Advance"
*
* // dynamic heade, current executed time
* const console = myConsole({ header: () => `[${new Date().toLocaleString()}]` });
@legend80s
legend80s / ui-codemirror-opts.js
Created March 17, 2017 02:55
Angular ui-codemirror editorOptions
{
lineWrapping: true,
lineNumbers: true,
readOnly: true,
// theme: 'mdn-like',
mode: 'application/json',
matchBrackets: true,
foldGutter: true,
gutters: ['CodeMirror-linenumbers', 'CodeMirror-foldgutter'],
}
@legend80s
legend80s / consoleWithHeader.js
Created March 10, 2017 05:33
console with header
/* eslint-disable no-console */
/**
* console with header,only method `log` is implemented
*
* @example
* const console = consoleWithHeader('[OpenSearch]');
* console.log('App Type is %s', 'Standard'); // outpu:App type is Standard
*
* @param {String} header 统一标示,常用来表示 log 来源
@legend80s
legend80s / cron-regex.js
Created March 2, 2017 08:36 — forked from andrew-templeton/cron-regex.js
Regex to validate cron expressions
"^\\s*($|#|\\w+\\s*=|(\\?|\\*|(?:[0-5]?\\d)(?:(?:-|\/|\\,)(?:[0-5]?\\d))?(?:,(?:[0-5]?\\d)(?:(?:-|\/|\\,)(?:[0-5]?\\d))?)*)\\s+(\\?|\\*|(?:[0-5]?\\d)(?:(?:-|\/|\\,)(?:[0-5]?\\d))?(?:,(?:[0-5]?\\d)(?:(?:-|\/|\\,)(?:[0-5]?\\d))?)*)\\s+(\\?|\\*|(?:[01]?\\d|2[0-3])(?:(?:-|\/|\\,)(?:[01]?\\d|2[0-3]))?(?:,(?:[01]?\\d|2[0-3])(?:(?:-|\/|\\,)(?:[01]?\\d|2[0-3]))?)*)\\s+(\\?|\\*|(?:0?[1-9]|[12]\\d|3[01])(?:(?:-|\/|\\,)(?:0?[1-9]|[12]\\d|3[01]))?(?:,(?:0?[1-9]|[12]\\d|3[01])(?:(?:-|\/|\\,)(?:0?[1-9]|[12]\\d|3[01]))?)*)\\s+(\\?|\\*|(?:[1-9]|1[012])(?:(?:-|\/|\\,)(?:[1-9]|1[012]))?(?:L|W)?(?:,(?:[1-9]|1[012])(?:(?:-|\/|\\,)(?:[1-9]|1[012]))?(?:L|W)?)*|\\?|\\*|(?:JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC)(?:(?:-)(?:JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC))?(?:,(?:JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC)(?:(?:-)(?:JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC))?)*)\\s+(\\?|\\*|(?:[0-6])(?:(?:-|\/|\\,|#)(?:[0-6]))?(?:L)?(?:,(?:[0-6])(?:(?:-|\/|\\,|#)(?:[0-6]))?(?:L)?)*|\\?|\\*|(?:MON|TUE|WED|THU|FRI|S
@legend80s
legend80s / server.js
Created February 8, 2017 09:11
resilent fault-tolerant server with cluster
/* eslint-disable no-console */
/* eslint-disable no-param-reassign */
const os = require('os');
const graceful = require('graceful');
const cluster = require('cluster');
const app = require('../app');
const isDev = process.env.NODE_ENV === 'development';
@legend80s
legend80s / Crypto.js
Last active April 8, 2022 07:28
AES/ECB/PKCS5Padding Cipher and Decipher of Node.js and can communicate with other languages
// modified based on [node.js AES/ECB/PKCS5Padding 与其他语言的加密解密通用](http://yijiebuyi.com/blog/13e2ae33082ac12ba4946b033be04bb5.html)
const crypto = require('crypto');
module.exports = class Crypto {
/**
* 加解密必须使用同一套 key 和 iv
* @param {String} algorithm 算法名称,比如 `aes-128-ecb`
* @param {String} key 秘钥
* @param {String} iv initialization vector,默认空字符串
*/
@legend80s
legend80s / Preferences.sublime-settings
Last active June 29, 2017 04:48
Preferences.sublime-settings
// edit ~/.gitconfig add
[alias]
co = checkout
ci = commit
st = status
{
"color_scheme": "Packages/User/SublimeLinter/Monokai Phoenix (SL).tmTheme",
"font_face": "Monaco",
@legend80s
legend80s / thunks.js
Created October 17, 2016 08:30
thunks for fs
// https://github.com/tj/co-fs/blob/master/index.js
const fs = require('fs');
function accessThunk(dir) {
return (cb) => {
fs.access(dir, (err) => cb(null, !err));
};
}
@legend80s
legend80s / scopes.txt
Last active October 17, 2016 05:03 — forked from iambibhas/scopes.txt
Sublime Text 2: Snippet scopes
Here is a list of scopes to use in Sublime Text 2 snippets -
ActionScript: source.actionscript.2
AppleScript: source.applescript
ASP: source.asp
Batch FIle: source.dosbatch
C#: source.cs
C++: source.c++
Clojure: source.clojure
CoffeeScript: source.coffee
@legend80s
legend80s / update-route-entry.js
Created October 15, 2016 09:46
update-route-entry.js called by init.js
/* eslint-disable no-console */
const fs = require('fs');
function updateRouteEntry(routePath, modules) {
if (modules.length === 0) return;
fs.readFile(routePath, (err, data) => {
if (err) {
throw err;
}