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 / 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 {
@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 / 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 / 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) {
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 / 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);
}
@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.js
Created June 1, 2015 09:13
base64 to blob
function b64ToUint6 (nChr) {
return nChr > 64 && nChr < 91 ?
nChr - 65
: nChr > 96 && nChr < 123 ?
nChr - 71
: nChr > 47 && nChr < 58 ?
nChr + 4
: nChr === 43 ?
@lili21
lili21 / gist:4c4edd06fd3f23d8c71e
Last active August 29, 2015 14:21
determine if an element is in the visible viewport, 判断元素是否在可视区域内
// Determine if an element is in the visible viewport
function isInViewport(element) {
var rect = element.getBoundingClientRect();
var html = document.documentElement;
return (
rect.top >= 0 &&
rect.left >= 0 &&
rect.bottom <= (window.innerHeight || html.clientHeight) &&
rect.right <= (window.innerWidth || html.clientWidth)
);
Array.apply(null, {length: N}).map(Number.call, Number)
Array.apply(null, {length: N}).map(Function.call, Math.random)