Skip to content

Instantly share code, notes, and snippets.

@JohnMarkT
JohnMarkT / timezones.js
Last active December 23, 2021 20:34
JSON array of timezones retrieved from http://www.timeanddate.com/time/zones/
/*
//retrieved from http://www.timeanddate.com/time/zones/
//with the following console code:
(function(){
var trs = $$('#tz-abb tbody tr'),
timeZones = trs.map(tr => {
var tds = $$('td', tr),
keys = ['abbreviation', 'name', 'location', 'offset'],
tz = {};
@JohnMarkT
JohnMarkT / dublincore.js
Last active April 2, 2023 20:39
JSON array of Dublin Core terms retrieved from http://dublincore.org/documents/dcmi-terms/
/*
// retrieved from http://dublincore.org/documents/dcmi-terms/
// with the following Chrome console code:
(function() {
Element.prototype.getAxis = function(axis) {
var td = this.querySelector('td[axis=' + axis + ']');
return td ? td.innerText : "";
}
var tbodies = $$('#H2 tbody'),
@JohnMarkT
JohnMarkT / loadenv.sh
Created October 11, 2016 14:11
Shell script to convert environment variables list file to single line to use on the command line
#!/bin/sh
if [ $# -lt 1 ]; then
echo "usage: loadenv filename"
exit 2
fi
HASH="#"
for ENV_FILE in "$@"; do
@JohnMarkT
JohnMarkT / getByProperty.js
Last active May 13, 2022 13:20
get deeply nested property
function getByProperty(obj, prop) {
if (typeof obj === "object") {
return Object.keys(obj).reduce( (a, c) => {
if (c === prop) {
a = a.concat(obj[c]);
}
return a.concat(
getByProperty(obj[c], prop) || []
);
}, []);
@JohnMarkT
JohnMarkT / cookies.js
Created December 14, 2017 16:10
Simple conversion of cookies to object
const cookies = document.cookie.split(';').reduce((a, c) => {const p = c.split('='); a[p[0]] = p[1]; return a;}, {});
@JohnMarkT
JohnMarkT / getFullname.js
Created July 13, 2018 18:53
Get full name from user object
const getFullname = u => [u.first, u.middle, u.last].filter(Boolean).join(' ')
@JohnMarkT
JohnMarkT / getDeep.js
Created September 18, 2018 15:29
get deeply nested property -- returns undefined if not found
function getDeep(obj, key) {
return key.split('.').reduce((o, x) => {
return (o || {})[x];
}, obj);
}
@JohnMarkT
JohnMarkT / validateJWT.js
Last active July 30, 2020 15:11
Only performs basic validation, not verification. Returns object original JWT, unencrypted and parsed payload, and valid boolean.
function validateJWT(jwt) {
let payload = {}, valid = false
try {
[, payload] = jwt.split('.').slice(0,2).map(p => JSON.parse(atob(p)))
valid = true
} catch (error) {}
return { jwt, payload, valid }
}
@JohnMarkT
JohnMarkT / del-el.js
Created March 1, 2021 14:30
Bookmarklet to delete distracting and annoying elements from web page
((j,b)=>{j.t=!j.t;const f=j.t?b.addEventListener:b.removeEventListener;console.log('remove mode %s',j.t?'on':'off');j.rE=j.rE||(({target:el})=>{console.log('removing:',el);el.parentNode.removeChild(el);});f('click',j.rE);})(window.JMT=window.JMT||{},document.body);
@JohnMarkT
JohnMarkT / 1to100.js
Created April 20, 2021 13:07
Print 1 to 100 without using numbers
const ten = 'no numbers'.length;
[...Array(ten * ten).keys()].forEach(i => console.log(++i));