Skip to content

Instantly share code, notes, and snippets.

View icecreamliker's full-sized avatar

LeeY icecreamliker

  • Harbin Institute of Technology
View GitHub Profile
@icecreamliker
icecreamliker / fetch.js
Created August 1, 2016 01:46
simple ajax lib based on promise(similar to fetch)
/**
* Author: LeeY
*/
var RSVP = require('rsvp');
var Promise = RSVP.Promise;
var c = {
dataTypes: {
_default: '*/*',
@icecreamliker
icecreamliker / what-forces-layout.md
Created April 28, 2016 06:31 — forked from paulirish/what-forces-layout.md
What forces layout/reflow. The comprehensive list.

What forces layout / reflow

All of the below properties or methods, when requested/called in JavaScript, will trigger the browser to synchronously calculate the style and layout*. This is also called reflow or layout thrashing, and is common performance bottleneck.

Element

Box metrics
  • elem.offsetLeft, elem.offsetTop, elem.offsetWidth, elem.offsetHeight, elem.offsetParent
  • elem.clientLeft, elem.clientTop, elem.clientWidth, elem.clientHeight
  • elem.getClientRects(), elem.getBoundingClientRect()
@icecreamliker
icecreamliker / tokenizer.js
Created April 8, 2016 09:23
simple less tokenizer
var fs = require('fs');
function tokenizer(file) {
var content = fs.readFileSync(file, {
encoding: 'utf-8'
});
this.lines = content.split('\n');
}
tokenizer.prototype = {
@icecreamliker
icecreamliker / quicksort.js
Created December 3, 2015 05:17
quick sort
function sort(array, i, j) {
if (i == j) {
return;
}
var start = i,
end = j,
key = array[i],
flag = true;
@icecreamliker
icecreamliker / event.js
Created July 12, 2015 10:07
create custom event
var event = new Event('yaoli');
// Listen for the event.
elem.addEventListener('yaoli', function (e) { console.debug(e); }, false);
// Dispatch the event.
elem.dispatchEvent(event);
// =====================================
// Custom Event
var event = new CustomEvent('yaoli', { 'detail': 'yaoli is a good guy!' });
if (!Function.prototype.bind) {
Function.prototype.bind = function (oThis) {
if (typeof this !== "function") {
// closest thing possible to the ECMAScript 5 internal IsCallable function
throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable");
}
var aArgs = Array.prototype.slice.call(arguments, 1),
fToBind = this,
fNOP = function () {},
@icecreamliker
icecreamliker / invokable.js
Created April 25, 2015 14:46
invokable function
function calc(x) {
var _sum = x;
var fn = function(y) {
_sum += y;
return arguments.callee;
}
fn.toString = function() {
return _sum;
}
return fn;
@icecreamliker
icecreamliker / mediaquery.md
Last active August 29, 2015 14:15
media query for ipad, iphone, etc.

http://stephen.io/mediaqueries

@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 2dppx) {

}

@media only screen and (min-device-width : 320px) and (max-device-width : 568px) and (max-device-height: 568px) and (orientation : portrait) { /* iphone 5, 5s*/ }

Floats, absolutely positioned elements, block containers (such as inline-blocks, table-cells, and table-captions) that are not block boxes, and block boxes with ‘overflow’ other than ‘visible’ (except when that value has been propagated to the viewport) establish new block formatting contexts for their contents.