Skip to content

Instantly share code, notes, and snippets.

View stevewithington's full-sized avatar
⛑️
solving problems

Steve Withington stevewithington

⛑️
solving problems
View GitHub Profile
@stevewithington
stevewithington / passive-support.ts
Created August 11, 2020 16:51
TypeScript Passive Support Detection
/**
* Safety detection for passive support
* https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#Safely_detecting_option_support
*/
initPassiveSupport = (): boolean => {
let supported = false;
let options = {};
try {
@stevewithington
stevewithington / typescript-check-if-passive-is-supported.ts
Last active August 3, 2020 16:59
Check if `passive` is supported via TypeScript
/** In case your linter gives you a problem attempting to register listeners to `testEvent` */
declare global {
interface WindowEventMap {
testEvent: CustomEvent<{ event: any, options: any }>;
}
}
/** Inspired by: https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#Safely_detecting_option_support */
export const isPassiveSupported = () => {
let passiveSupported = false;
let x = 30.039853244;
Number(Math.round(x + 'e2') + 'e-2); // 30.04
const round = (num, digits) => {
return Number(Math.round(num + 'e' + digits) + 'e-' + digits);
}
let y = 3.141592653589793238;
round(y, 3); // 3.142
@stevewithington
stevewithington / getRandomPassword.cfm
Created July 2, 2020 16:58
ColdFusion / CFML Random Password Method / Function
<cfscript>
public string function getRandomPassword(numeric length=10, string charSet='special') {
var charLower = 'a|c|e|g|i|k|m|o|q|s|u|w|y|b|d|f|h|j|l|n|p|r|t|v|x|z'
var charUpper = 'A|C|E|G|I|K|M|O|Q|S|U|W|Y|B|D|F|H|J|L|N|P|R|T|V|X|Z';
var charNumbers = '0|2|4|6|8|9|7|5|3|1';
var charSpecial = "@|!|$|%|^|&|+|=|,'";
var charList = '';
var thisChar = '';
var randomPassword = '';
git log --graph --decorate --pretty=oneline --abbrev-commit
@stevewithington
stevewithington / find-replace-sed.md
Last active June 27, 2024 15:19
Find & Replace within an Entire Directory or Git Repo with sed

Find & Replace within an Entire Directory or Git Repo with sed

If replacing within a directory:

grep -rl 'apples' /dir_to_search_under | xargs sed -i 's/apples/oranges/g'

Or, within an entire git repository:

@stevewithington
stevewithington / fancy-tabs-demo.html
Created June 4, 2019 16:43 — forked from ebidel/fancy-tabs-demo.html
Fancy tabs web component - shadow dom v1, custom elements v1, full a11y
<script>
function execPolyfill() {
(function(){
// CustomElementsV1.min.js v1 polyfill from https://github.com/webcomponents/webcomponentsjs/tree/v1/src/CustomElements/v1.
/*
Copyright (c) 2016 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
@stevewithington
stevewithington / useful-git-commands.md
Last active June 3, 2019 15:07
Useful Git Commands I Don't Use Every Day

Useful Git Commands I Don't Use Every Day

Get the Size of a Git Repo, Excluding Ignored Files

git count-objects -vH

Produces something similar to:

@stevewithington
stevewithington / compare.js
Created May 22, 2019 04:42
JavaScript Compare
compare(a: number, b: number): number {
return a > b
? 1
: a < b
? -1
: 0;
}
@stevewithington
stevewithington / prettify-json.js
Last active May 10, 2019 19:14
Prettify JSON, the easy way!
// arbitrary js object:
var myJsObj = {a:'foo', 'b':'bar', c:[false,2,null, 'null']};
// using JSON.stringify pretty print capability:
var str = JSON.stringify(myJsObj, undefined, 4);
// Kudos: <https://stackoverflow.com/questions/26320525/prettify-json-data-in-textarea-input/26324037>