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 / gist:7730183
Created December 1, 2013 09:02
fadein.onscroll
$(document).ready(function() {
/* Hide all elements outside the visible window */
$('body *').each( function(){
var top_of_object = $(this).position().top;
var bottom_of_window = $(window).scrollTop() + $(window).height();
if( bottom_of_window < top_of_object ){
@lili21
lili21 / good parts functions
Last active December 29, 2015 07:28
javascript good parts function
//原型继承
if (typeof Object.beget !== 'function') {
Object.create = function(o) {
var F = function() {};
F.prototype = o;
return new F();
};
}
//var new_o = Object.create(old_o);
@lili21
lili21 / gist:7355283
Created November 7, 2013 14:20
smooth scrolling
$(function() {
$('a[href*=#]:not([href=#])').click(function() {
if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
var target = $(this.hash);
target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
if (target.length) {
$('html,body').animate({
scrollTop: target.offset().top
}, 1000);
return false;
var BrowserDetect = {
init: function() {
this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
this.version = this.searchVersion(navigator.userAgent) || this.searchVersion(navigator.appVersion) || "an unknown version";
this.OS = this.searchString(this.dataOS) || "an unknown OS";
},
searchString: function(data) {
for (var i = 0; i < data.length; i++) {
var dataString = data[i].string;
var dataProp = data[i].prop;
@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);
}