Skip to content

Instantly share code, notes, and snippets.

View mholtzhausen's full-sized avatar

Mark Holtzhausen mholtzhausen

View GitHub Profile
@mholtzhausen
mholtzhausen / Obj.js
Last active November 8, 2019 15:00
Object Tools
/**
* @example
* let testObject = {a:{b:{c:false}}}
* // instead of this:
* let v1 = null;
* if (
* testObject !== null &&
* typeof testObject == 'object' &&
* testObject.hasOwnProperty('a') &&
* testObject.a !== null &&

Nootropic Tools

Some tools to help with measuring out and keeping track of your nootropic stacks

Spoon Conversion table

Legend

A :: Large orange scoop with flat bottom
B :: Short white round-bottomed scoop
C :: Long-handled white scoop with partially flattened bottom
D :: Blue microscoop

@mholtzhausen
mholtzhausen / .bash_aliases
Last active November 7, 2019 09:28
My Bash Aliases
alias alias.edit='$EDITOR ~/.bash_aliases'
alias alias.load='. ~/.bash_aliases'
alias alias.save='alias > ~/.bash_aliases'
alias alias.to.here='f(){ alias ${@}="cd $(pwd)"; echo -e "\n Alias Created: ${@} -> $(pwd)\n"; unset -f f; }; f'
alias bash.edit='$EDITOR ~/.bash_profile'
alias bash.load='. ~/.bash_profile'
alias ll='ls -FGplah'
alias lls='du -sh * | sort -h'
alias gh='history|grep --context=0'
alias tree.size='f(){ level=${1-1}; shift; tree -vhaF -C --sort=name --dirsfirst -L ${#level} ${@}; unset -f f; }; f'
@mholtzhausen
mholtzhausen / v1.js
Last active November 1, 2019 14:58
Deep subscribe into an object for change alerts
const watch = (() => {
const isWatched = Symbol('watched')
const w = (tgt, obs = [], route = []) => {
const isObj = (x) => (typeof x === 'object' && x !== null) || typeof x === 'function'
const __path = (obj, prop, prefix) => prefix.join('.')
const __watched = (obj, prop, prefix) => isWatched in obj
const __unwatch = (obj, prop, prefix) => tgt
const mx = { __path, __watched, __unwatch }
@mholtzhausen
mholtzhausen / consoleOut.js
Created October 31, 2019 12:11
output formatting for the terminal
const output = (() => {
const o = (msg) => { o.w(`${msg || ''}\n`); return o }
o.w = (msg) => { process.stdout.write(msg); return o }
o.h1 = (msg = '') => { o.pad(msg.length, '#')()(msg).pad(msg.length, '#')(); return o }
o.h2 = (msg = '') => { o(msg).pad(msg.length, '-')()(); return o }
o.h3 = (msg = '') => { o.pad(5, '>')(msg)(); return o }
o.tab = (n = 1) => { process.stdout.write(Array(n).join('\t')); return o }
o.pad = (n = 1, char = ' ') => { process.stdout.write(Array(n+1).join(char || ' ')); return o }
o.nl = (n = 1) => { o.pad(n, '\n'); return o }
return o
@mholtzhausen
mholtzhausen / polyfill.js
Created April 1, 2019 09:47
Conditional Polyfill for async html
/**
* Conditional polyfill loading using dynamic import
*/
export default async () => {
if (window) {
if (
['fetch', 'Intl', 'Map', 'URL'].find(p => !(p in window)) !== undefined ||
['assign', 'entries', 'keys'].find(p => !(p in Object)) !== undefined ||
['endsWith', 'includes', 'startsWith'].find(p => !(p in String.prototype)) !== undefined ||
['forEach'].find(p => !(p in NodeList.prototype)) !== undefined ||
@mholtzhausen
mholtzhausen / $$.es6.js
Last active August 21, 2018 13:56
DOM Toolbox -- jQ
/**
Syntax for $(q,c)
$('div.someClass') // [<div.someClass />,<div.someClass />]
$$('div.someClass') // $$[<div.someClass />,<div.someClass />]
.first() // <div.someClass />
.$first() // $$[<div.someClass />]
.last() // <div.someClass />
.$last() // $$[<div.someClass />]
@mholtzhausen
mholtzhausen / classlist.es5.js
Last active July 18, 2018 11:19
classlist for ie9
var classList=function(elem){
return new function(){
var self=this
this._el = elem
Object.defineProperty(this,'classList',{
get: function(name){
return this._el.className.trim().replace(/\s+/ig,' ').split(' ')
}.bind(this)
})
@mholtzhausen
mholtzhausen / Class Module.js
Last active June 26, 2018 13:37
Class Utilities
const ClassName = (() => {
// Privately Accessible Data
const instancesData = new WeakMap()
let instanceData //Stores data by instance
let classData = {} //Stores data for the class
// Privately Accessible Functions
class Pvt {
constructor() { return Pvt; }// no instantiation
static somePrivateFunction() {
@mholtzhausen
mholtzhausen / Modal.js
Last active June 21, 2018 09:43
Modal Dialog
function tag(html){
return((html)=>{
let container=document.createElement('div')
let frag = document.createDocumentFragment()
container.innerHTML=html
Array.prototype.slice.call(container.childNodes).forEach(node=>{
console.log(`adding ${node}`)
frag.appendChild(node)
})
return frag