Skip to content

Instantly share code, notes, and snippets.

@zackdouglas
zackdouglas / README.md
Last active April 3, 2023 07:44
Universal JS atou/utoa

Utoatou

A better btoa and atob that supports non-ASCII characters in a healthy manner.

Compatible with AMD, CommonJS, and ES2015 module loaders.

@zackdouglas
zackdouglas / ExpandableClass.php
Created April 14, 2011 05:52
A simple PHP logger for ease of use with the decorator design pattern. This contains the abstract base class which should be extended in the least implementing _BaseLogger::resolveMessage(). As an example, this includes a sample stream logger.
<?php
/*******************************************************************************
* Expandable Class
*
* Authors:: anthony.gallagher@wellspringworldwide.com
*
* Copyright:: Copyright 2009, Wellspring Worldwide, LLC Inc. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@zackdouglas
zackdouglas / Lazy or short switch.js
Created March 28, 2018 23:42
A silly switch transpilation target
(f={f () { return 'f' }, g () { return 'g' }}['f'],f&&f()||new Error)
@zackdouglas
zackdouglas / jsTemplatedQuine.js
Created June 7, 2017 20:21
So close to a quine…
var expose=(strings,...expressions)=>{return{strings,expressions}};
JSON.stringify((expose`var ${expose(`expose=${expose}`)};`),undefined,2);
@zackdouglas
zackdouglas / detectPrivateMode.js
Created May 19, 2017 16:33
Detect if a user is in Private Browsing mode
function detectPrivateMode(a){var b;if(window.webkitRequestFileSystem)window.webkitRequestFileSystem(window.TEMPORARY,1,function(){b=!1},function(a){b=!0});else if(window.indexedDB&&/Firefox/.test(window.navigator.userAgent)){var c;try{c=window.indexedDB.open("test")}catch(a){b=!0}void 0===b&&t(function(){return"done"===c.readyState},function(a){a||(b=!c.result)})}else if(o(window.navigator.userAgent)){b=!1;try{window.indexedDB||(b=!0)}catch(a){b=!0}}else if(window.localStorage&&/Safari/.test(window.navigator.userAgent)){if(window.safariIncognito)b=!0;else try{window.localStorage.setItem("test",1)}catch(a){b=!0}void 0===b&&(b=!1,window.localStorage.removeItem("test"))}t(function(){return void 0!==b},function(c){a(b)})}
@zackdouglas
zackdouglas / css-content-attr-fails.html
Created February 9, 2017 00:25
Why does CSS attr() fail for input elements?
<html>
<head>
<style>
body *:before {
content: attr(value) ' '
}
</style>
</head>
<body>
<div value=works />
@zackdouglas
zackdouglas / README.md
Last active January 27, 2017 15:21
Make any page look like-ish Markdown
@zackdouglas
zackdouglas / launchWorker.js
Created January 17, 2017 18:42
Launch a function as a Worker
function launchWorker(f) {
if (! (f instanceof Function)) {
throw new Error(`Cannot launch ${typeof(f)} as Worker`);
}
const src = `(${f})();`;
const blob = new Blob([src], {type: 'application/javascript'});
const url = URL.createObjectURL(blob);
return new Worker(url);
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Building a router</title>
<script>
// Put John's template engine code here...
(function () {
// A hash to store our routes:
@zackdouglas
zackdouglas / hack.sh
Created August 13, 2013 14:49 — forked from DAddYE/hack.sh
#!/bin/sh
##
# This is a script with usefull tips taken from:
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
#
# Run in interactive mode with:
# $ sh -c "$(curl -sL https://raw.github.com/gist/2108403/hack.sh)"
#
# or run it without prompt questions: