Skip to content

Instantly share code, notes, and snippets.

View lili21's full-sized avatar
🎯
Focusing

li.li lili21

🎯
Focusing
View GitHub Profile
@lili21
lili21 / saveAs.js
Last active August 29, 2015 14:22
save as (front end file saver)
;(function(self) {
'use strict';
/**
* 将base64数据转成Blob对象,
* @param {string} base64 base64字符串
* @param {string} type mime type
* @param {number} size slice size
* @return {object} Blob对象
*/
function b2b(base64) {
@lili21
lili21 / b2b-n.js
Last active August 29, 2015 14:22
base64 to blob (more readable)
function b2b(base64) {
var decode, i, length, byteArray;
i = 0;
decode = atob(base64);
length = decode.length;
byteArray = new Uint8Array(length);
for (;i < length;i++) {
byteArray[i] = decode.charCodeAt(i);
}
HTMLDocument.prototype.ready = function () {
return new Promise(function(resolve, reject) {
if (document.readyState === 'complete') {
resolve(document)
} else {
document.addEventListener('DOMContentLoaded', function() {
resolve(document)
});
}
});
@lili21
lili21 / di.js
Created September 1, 2015 05:27
dependency injection
var FN_ARGS = /^function\s*[^\(]*\(\s*([^\)]*)\)/m;
var FN_ARG_SPLIT = /, ?/g;
var STRIP_COMMENTS = /((\/\/.*$)|(\/\*[\s\S]*?\*\/))/mg;
var injector = {
store: {},
register: function(key, value) {
this.store[key] = value;
},
invoke: function(fn) {
@lili21
lili21 / gist:3a3edf5cd6f40ace78f08fe358c89e98
Created May 9, 2016 07:31
delete merged remote branch
git branch -r --merged master | sed 's/origin\///' | egrep -v 'master$' | xargs -n 1 git push origin --delete
@lili21
lili21 / gist:5bf6960d32b51db3922269eca1b2130b
Created January 11, 2017 05:04 — forked from schacon/gist:942899
delete all remote branches that have already been merged into master
$ git branch -r --merged |
grep origin |
grep -v '>' |
grep -v master |
xargs -L1 |
awk '{split($0,a,"/"); print a[2]}' |
xargs git push origin --delete
@lili21
lili21 / preload_feature_detection.js
Created February 28, 2017 05:33 — forked from yoavweiss/preload_feature_detection.js
Preload feature detection
var DOMTokenListSupports = function(tokenList, token) {
if (!tokenList || !tokenList.supports) {
return;
}
try {
return tokenList.supports(token);
} catch (e) {
if (e instanceof TypeError) {
console.log("The DOMTokenList doesn't have a supported tokens list");
} else {
git diff --name-only --cached --relative | grep '\\.js$' | xargs eslint
@lili21
lili21 / decorator-ng-di.js
Last active August 14, 2017 06:13
decorator-ng-di
@Inject('ServiceA', 'ServiceB', 'ServiceC')
class Ctrl {
fetchData () {
this.ServiceA.fetch()
}
}
function Inject (...args) {
return function (target, key, descriptor) {
const ctrl = function (..._args) {
args.forEach((v, i) => {
@lili21
lili21 / rx.js
Last active August 14, 2017 06:12
observable
const observer = {
next: function nextCb(data) {
console.log(data)
},
error: function errorCb(error) {
console.error(error)
},
complete: function completeCb(data) {