Skip to content

Instantly share code, notes, and snippets.

Dan Sajin dansajin

Block or report user

Report or block dansajin

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@dansajin
dansajin / measureEventPerformance.js
Last active May 31, 2017
Measure Event Performance
View measureEventPerformance.js
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
Async queue pattern - helpful when you need server side parsing in your javascript
View Queue.js
'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 Apr 5, 2016
Javascript override method only once wrapper function
View overrideOnce.js
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 — forked from scottjehl/criticalcss.js
critical CSS devtool snippet
View criticalcss.js
/**
* 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,
You can’t perform that action at this time.