Skip to content

Instantly share code, notes, and snippets.

View lylijincheng's full-sized avatar

lylijincheng lylijincheng

View GitHub Profile
@lylijincheng
lylijincheng / cbind.js
Last active October 24, 2019 14:59
bind
var f = function(...args) {
console.log(this.value, ...args);
};
// 1
var bindA = function(fn, that) {
var sF = f.toString().replace(/\n/g, '');
@lylijincheng
lylijincheng / passive.js
Created July 25, 2019 03:45
Passive events
// 检测方法
var supportsPassive = false;
document.createElement("div").addEventListener("test", function() {}, {
get passive() {
supportsPassive = true;
return false;
}
});
@lylijincheng
lylijincheng / color.js
Created October 20, 2015 01:00
Random color generation
(~~(Math.random() * (1 << 24) )).toString(16)
@lylijincheng
lylijincheng / createRequest.js
Created December 2, 2014 04:16
Simple XMLHttpRequest
function createRequest(uri) {
var client = new XMLHttpRequest();
client.onreadystatechange = function() {
if(this.readyState == this.DONE)
if(this.status == 200 && this.responseText != null) {
return processData(this.responseText);
}
processData(null);
}
client.open("GET", uri);
@lylijincheng
lylijincheng / rAF.js
Created November 5, 2014 10:05
rAF example frome Google example.
function Box () {
var animationStartTime = 0;
var animationDuration = 500;
var target = document.querySelector('.box');
this.startAnimation = function() {
animationStartTime = Date.now();
requestAnimationFrame(update);
};
@lylijincheng
lylijincheng / display-flexbox.css
Created October 17, 2014 07:19
display flexbox compatable with old webkit.
/** flexbox parent and children style */
.display-flexbox {
display: -webkit-box;
display: -webkit-flex;
display: flex;
}
.flexbox-children {
-webkit-box-flex: 1;
-webkit-flex: 1;
@lylijincheng
lylijincheng / git
Created October 17, 2014 03:39
Git
// Create a new branch and fetch frome remote branch
$ git checkout -b hotfix origin/hotfix
// Create a branch based one commit
// Fix branch
$ git checkout -b hotfix 7bda10c6488835f4c54079cec78cc539a0c152c6
$ git push origin hotfix
// Create a new branch hotfix based on master
$ git checkout -b hotfix master
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title></title>
<style>
.text-ellipsis-2 {
overflow: hidden;
@lylijincheng
lylijincheng / unique.js
Created November 12, 2013 07:20
javascript array unique
function unique(array) {
return array.filter(function(entry, pos, entries) {
return entries.indexOf(entry) === pos;
});
}
@lylijincheng
lylijincheng / arraySum
Created October 25, 2013 05:18
arraySum update.
function arraySum(array) {
var index, entry, sum = 0, len = array.length;
for(index = 0; index < len; index += 1){
entry = array[index];
sum += (entry instanceof Array) ? arraySum(entry) : ((typeof entry === 'number' && !isNaN(entry)) ? entry : 0);
}
return sum;