Skip to content

Instantly share code, notes, and snippets.

Avatar

Mark Holtzhausen mholtzhausen

View GitHub Profile
@mholtzhausen
mholtzhausen / Readme.md
Last active Oct 5, 2021
DateTime Formatting made very very simple
View Readme.md

DateUtil

A very simple local-time only date formatting tool that lives in one file and does the minimum for mvp.

How to use

const {format} = require('./dateUtil.js')

let date=Date.now()
let formatStr='www, DD mmmm, YYYY H:I:s.SS'
@mholtzhausen
mholtzhausen / Readme.md
Created Jun 22, 2021
Clear all Cookies on Primary domain and Subdomains
View Readme.md

This function will remove all cookies that are:

  1. on the primary domain
  2. on the wildcard primary domain
  3. with the matching path (defaults to no-path or /)
  4. that is not an http cookie
@mholtzhausen
mholtzhausen / demo.js
Created Apr 21, 2021
Simple timer function
View demo.js
const {start, measure, create} = require('./timer.js')
const MAX=1000
var seed = Math.random()*1000;
function random() {
var x = Math.sin(seed++) * 10000;
return x - Math.floor(x);
}
@mholtzhausen
mholtzhausen / demo.js
Last active Apr 15, 2021
Compact pared down version of npm debug module
View demo.js
const debug=require('./qdebug.js')
const log1 = debug('log1')
const log2 = debug('log2')
const sublog = log1.ext('sublog')
log1.info('hello world', {test:Math.random()})
log2.info('hello world', {test:Math.random()})
sublog.info('hello world', {test:Math.random()})
@mholtzhausen
mholtzhausen / .git_info_exclude
Last active Feb 23, 2021
Default Git Excludes
View .git_info_exclude
# VsCode Local Settings :: The team is too cool to standardise IDE
.vscode/
# Temp-Folder ::I am so dumb I need a persistent scratch-pad
tmp/
# Dev Scripts :: The team is too advanced for this shit
dev/
# Unofficial Docs :: The team is too clever for this shit
View script.dir.sh
#!/bin/bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
@mholtzhausen
mholtzhausen / ts2ms.js
Last active Feb 23, 2021
Timespan to Milliseconds
View ts2ms.js
const timespanToMs=(timeSpan)=>{
let lut={'':1, ms:1, s:1000, m:60000, h:3600000, d: 86400000, w:604800000, y:31556952000 }
let ms=(`${timeSpan}`.match(/\d+[ywdhms]{0,2}\s?/g)).reduce((a,s)=>{
let [,v,m] =s.match(/(\d+)([ywdhms]{0,2})/)
return a + (v * lut[m])
},0)
return ms
}
let passTests=[
@mholtzhausen
mholtzhausen / Catch.js
Last active Sep 11, 2020
Catch -- try-catch wrapper for promises (with a bonus)
View Catch.js
const Catch = async (promise, errorHandler) => {
if (promise instanceof Promise) {
try {
let returnValue = await promise
return returnValue
} catch (e) {
if (typeof errorHandler === 'function') return errorHandler(e)
return errorHandler
}
}
@mholtzhausen
mholtzhausen / HOME_FOLDER_.bashrc
Last active Aug 11, 2020
A script to make a function <name> that will autocomplete when finding a /<script> folder upstream
View HOME_FOLDER_.bashrc
# ...
source ~/scriptfinder ss scripts
@mholtzhausen
mholtzhausen / ReadMe.md
Created Jul 28, 2020
Simple Js validation - schemas for objects - extensible
View ReadMe.md

Simple Js validation - schemas for objects - extensible

validation types work like this: [+]typename[(arg,[arg,...])]

The + in the beginning makes it required any arguments applied will be passed to that type's validation function