Skip to content

Instantly share code, notes, and snippets.

View bravelincy's full-sized avatar
🎯
Focusing

Simon Lin bravelincy

🎯
Focusing
  • GuangZhou/CN
View GitHub Profile
@bravelincy
bravelincy / alfred_script_fi
Last active April 17, 2017 02:50
fi script content of alfred
on alfred_script(q)
tell application "Finder"
set pathList to (quoted form of POSIX path of (folder of the front window as alias))
set command to "clear; cd " & pathList
end tell
tell application "System Events"
-- some versions might identify as "iTerm2" instead of "iTerm"
set isRunning to (exists (processes where name is "iTerm")) or (exists (processes where name is "iTerm2"))
@bravelincy
bravelincy / Observer.js
Last active September 30, 2016 04:23
Observer.js
;(function(window) {
'use strict';
var isArray = Array.isArray,
isObject = function(value) {
return value !== null && typeof value === 'object';
},
each = function(map, iterator) {
'use strict';
const sliceArgs = function(args, beginIndex, endIndex) {
return Array.prototype.slice.call(args, beginIndex, endIndex);
};
const _ = Symbol('placeholder');
function partial(fn) {
let _args = sliceArgs(arguments, 1);
function pipe() {
let funcs = arguments;
return function() {
let length = funcs.length;
let index = 0;
let result;
while (index < length) {
let fn = funcs[index];
const slice = Array.prototype.slice;
const toString = Object.prototype.toString;
function isObject(value) {
return value !== null && typeof value === 'object';
}
function clone(value, deep) {
if (isObject(value)) {
let copy;
const isArray = Array.isArray;
const toString = Object.prototype.toString;
function isDate(value) {
return toString.call(value) === '[object Date]';
}
function isRegExp(value) {
return toString.call(value) === '[object RegExp]';
}
const isArray = Array.isArray;
const slice = Array.prototype.slice;
const toString = Object.prototype.toString;
function isObject(value) {
return value !== null && typeof value === 'object';
}
function isDate(value) {
return toString.call(value) === '[object Date]';
/** @jsx tag */
function tag(type, props, ...children) {
return {type, props, children};
}
function createElement(node) {
if (typeof node === 'string') {
return document.createTextNode(node);
} else {
let $root = document.createElement(node.type);
@bravelincy
bravelincy / require-new.js
Last active August 20, 2017 07:57
require node modules and don't cache anything
var path = require('path')
var context = path.dirname(module.parent.filename)
// only for relative path uri
module.exports = function (uri) {
var filename = path.resolve(context, uri)
var cachedModule = getCachedModule(filename)
if (cachedModule) {
cleanModulesCache(cachedModule)
@bravelincy
bravelincy / jsonp.js
Last active February 9, 2018 03:44
JSONP
function merge () {
var args = [].slice.call(arguments)
var obj = {}
args.forEach(function (arg) {
if (typeof arg === 'object' && arg) {
for (var k in arg) {
obj[k] = arg[k]
}
}
})