Skip to content

Instantly share code, notes, and snippets.

View dansajin's full-sized avatar

Dan Sajin dansajin

View GitHub Profile
@dansajin
dansajin / measureEventPerformance.js
Last active May 31, 2017 08:01
Measure Event Performance
function measureEventPerformance(event) {
const lag = performance.now() - event.timeStamp;
console.log(`Event took: ${lag} ms`);
}
// Usage
const submitButton = document.querySelector('button[type="submit"]');
submitButton.addEventListener('click', (event) => {
// Event listener logic here...
@dansajin
dansajin / Queue.js
Last active May 31, 2017 08:11
Async queue pattern - helpful when you need server side parsing in your javascript
'use strict';
function Queue(){
this.push = function(){
for (var i = 0, len = arguments.length; i < len; i++){
if (typeof arguments[i] !== 'function'){
throw new TypeError('Argument must be a function.')
}
arguments[i]()
}
@dansajin
dansajin / overrideOnce.js
Last active April 5, 2016 13:20
Javascript override method only once wrapper function
function overrideOnce(object, method, callback){
// override method with original as argument
object[method] = (function(original){
return function(){
// store whatever callback does
var result = callback.apply(this, arguments);
// restore method
object[method] = original;
@dansajin
dansajin / criticalcss.js
Last active May 3, 2019 09:34 — forked from scottjehl/criticalcss.js
critical CSS devtool snippet
/**
* criticalCSS by @dansajin. based on @scottjehl's criticalcss.js
* run this in a browser console or create a bookmarklet.
* lists rules per css file.
* does not include cross origin css files and inline css.
*/
(function(){
var sheets = document.styleSheets,
host = window.location.host,
maxTop = 1200,