Skip to content

Instantly share code, notes, and snippets.

View docluv's full-sized avatar
🏠
Working from home

Chris Love docluv

🏠
Working from home
View GitHub Profile
@prasidhda
prasidhda / common spam words 2020
Last active June 21, 2023 13:17
List of common spam words
0%
0% risk
777
99%
99.9%
100%
100% more
#1
$$$
100% free
@ebidel
ebidel / coverage.js
Last active September 24, 2023 10:25
CSS/JS code coverage during lifecycle of page load
Moved to https://github.com/ebidel/puppeteer-examples
@PaulKinlan
PaulKinlan / applyTemplate.js
Last active September 12, 2018 08:02
Simple Templating
const applyTemplate = (templateElement, data) => {
const element = templateElement.content.cloneNode(true);
const treeWalker = document.createTreeWalker(element, NodeFilter.SHOW_ELEMENT, () => NodeFilter.FILTER_ACCEPT);
while(treeWalker.nextNode()) {
const node = treeWalker.currentNode;
for(let bindAttr in node.dataset) {
let isBindableAttr = (bindAttr.indexOf('bind_') == 0) ? true : false;
if(isBindableAttr) {
let dataKeyString = node.dataset[bindAttr];
@gshackles
gshackles / parser.js
Last active October 14, 2017 12:35
Code Camp NYC 2017 - Schedule
const schedule = [...document.querySelectorAll("#tablepress-6 tbody tr")]
.map(row => ({
room: row.children[0].innerHTML,
time: row.children[1].innerHTML,
speaker: row.children[2].innerHTML,
title: row.children[3].innerHTML,
level: row.children[4].innerHTML,
abstract: row.children[5].innerHTML
}))
.reduce((slots, session) => Object.assign({}, slots, {

Parens And Performance

Years ago, some smart folks that worked on JS engines realized that not all JS that's loaded into a page/app initially is needed right away. They implemented JIT to optimize this situation.

JIT means Just-In-Time, which means essentially that the engine can defer processing (parsing, compiling) certain parts of a JS program until a later time, for example when the function in question is actually needed. This deferral means the engine is freer to spend the important cycles right now on the code that's going to run right now. This is a really good thing for JS performance.

Some time later, some JS engine devs realized that they needed to get some hints from the code as to which functions would run right away, and which ones wouldn't. In technical speak, these hints are called heuristics.

So they realized that one very common pattern for knowing that a function was going to run right away is if the first character before the function keyword was a (, because that usually m

@simonhearne
simonhearne / SPA.js
Last active November 25, 2016 02:01
Custom metric for WebPageTest to detect single page application frameworks
var SPA="none";
if (typeof(app)=="object") SPA = "unknown";
if (window.hasOwnProperty('require')) {
if(window.require.hasOwnProperty('defined')){
if(window.require.defined('troopjs-compose/decorator')) SPA = "troop";
if(window.require.defined('flight/lib/component')) SPA = "flight";
}
}
@Rich-Harris
Rich-Harris / service-workers.md
Last active April 21, 2024 16:24
Stuff I wish I'd known sooner about service workers

Stuff I wish I'd known sooner about service workers

I recently had several days of extremely frustrating experiences with service workers. Here are a few things I've since learned which would have made my life much easier but which isn't particularly obvious from most of the blog posts and videos I've seen.

I'll add to this list over time – suggested additions welcome in the comments or via twitter.com/rich_harris.

Use Canary for development instead of Chrome stable

Chrome 51 has some pretty wild behaviour related to console.log in service workers. Canary doesn't, and it has a load of really good service worker related stuff in devtools.

@jakubfiala
jakubfiala / custom_console.js
Created February 1, 2016 14:05
this small script intercepts the standard console methods and provides a way of accessing their messages, as well as stack traces, which is really cool. it formats the stack traces for popular browsers
//==========================================================
// CUSTOM JAVASCRIPT CONSOLE
// built by jakub fiala
//
// this small script intercepts the standard console methods
// and provides a way of accessing their messages,
// as well as stack traces, which is really cool.
// it formats the stack traces for popular browsers
//
// contributions welcome!
@bensie
bensie / imagemagick.bash
Last active November 20, 2023 10:13
ImageMagick Static Binaries for AWS Lambda
#!/usr/bin/env bash
# Must be run on an Amazon Linux AMI that matches AWS Lambda's runtime which can be found at:
# https://docs.aws.amazon.com/lambda/latest/dg/current-supported-versions.html
#
# As of May 21, 2019, this is:
# Amazon Linux AMI 2018.03.0 (ami-0756fbca465a59a30)
#
# You need to prepend PATH with the folder containing these binaries in your Lambda function
# to ensure these newer binaries are used.
@thensg
thensg / luhn-checksum.js
Last active November 30, 2021 19:27
Calculate or verify a Luhn (Mod10) checksum
/**
* MIT No Attribution
*
* Copyright 2015 Giovanni Thenstead
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is