Skip to content

Instantly share code, notes, and snippets.

View zanbaldwin's full-sized avatar
🦀

Zan Baldwin zanbaldwin

🦀
View GitHub Profile
@zanbaldwin
zanbaldwin / kill_ie6.html
Created August 3, 2010 16:04
Make IE6 crash and burn
<style>*{position:relative}</style><table><input></table>
@zanbaldwin
zanbaldwin / si.js
Last active March 15, 2017 13:22
Space Invaders in 17 Lines of Nostalgic Code
p=389;$=l=t=0;c=" _ ";
onkeydown=function(e){
(k=e.which)==39?p++:k==37?p--:!l&&(l=p)
};
setInterval(function(){
_="<pre>";l&&(l-=20)<0&&(l=0);
for(i=0;i<400;i++){
if(i%20==0)_+="\n";
if(~b[n="indexOf"](l))b.splice(b[n](l),1),$+=25,l=0;
if(~b[n](p))p=n,b=[],c="xxx";
@zanbaldwin
zanbaldwin / PS1.sh
Last active October 28, 2015 09:29
Useful variables and functions to use in your PS1 terminal prompt string.
# Inputs.
SHELL_NAME="\\v"
TERMINAL="\\l"
EXIT_CODE="\$?"
USERNAME="\\u"
WORKING_DIRECTORY="\\w"
DIRECTORY_BASENAME="\\W"
NEWLINE="\\n"
HOSTNAME_FULL="\\H"
HOSTNAME_SHORT="\\h"
@zanbaldwin
zanbaldwin / npm.sh
Last active March 8, 2017 15:07
Script to setup `node:*-alpine` containers so that node-gyp can build dependencies.
#!/bin/sh
# Really simple, but I need a Gist to remind me each time.
# Make sure the build dependencies of node-gyp are available before running NPM commands.
apk add --no-cache --virtual .npmdeps make python g++
if [ $# -gt 0 ]; then
npm $@
apk del .npmdeps
fi
@zanbaldwin
zanbaldwin / bookmarklet.js
Last active March 10, 2017 13:37
Insert a test email address into the active DOM element. Update with your email user and domain. Save to your bookmarks bar.
javascript:for(var n=new Date,m="Seconds Minutes Hours Date Month FullYear".split(" "),s="",i=m.length,a=document.activeElement;i;i--)f=n["get"+m[i-1]](),s+=10>f?"0"+f:f;if(a.isContentEditable||["input","textarea"].indexOf(a.tagName.toLowerCase())>-1)a.value="email.user+"+s+"@domain.tld";
@zanbaldwin
zanbaldwin / example.php
Last active September 13, 2017 09:50
Customisable FizzBuzz implementation in PHP.
<?php
$fizzbuzz = new \FizzBuzz\Application;
$fizzbuzz->addDefinition(new \FizzBuzz\Definition('Fizz', 3));
$fizzbuzz->addDefinition(new \FizzBuzz\Definition('Buzz', 5));
$fizzbuzz->run(1, 100);

Keybase proof

I hereby claim:

  • I am zanbaldwin on github.
  • I am zanbaldwin (https://keybase.io/zanbaldwin) on keybase.
  • I have a public key whose fingerprint is F59E C254 A2DA 8BE0 C135 126A 2100 8A6E D04D 2B52

To claim this, I am signing this object:

@zanbaldwin
zanbaldwin / Hierarchal CTE in SQL.md
Last active August 22, 2018 18:08
Playing around with Hierarchal Tree Structures and Common Table Expressions

Accessing Tree Hierarchies using Common Table Expressions

Examples have been tested with MySQL 8.0.12.

Table Structure

CREATE TABLE `nodes` (
  `id`      INT(11)       NOT NULL AUTO_INCREMENT,
  `parent`  INT(11)       DEFAULT NULL,
<?php declare(strict_types=1);
namespace Symfony\Component\Validator;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\Constraints\Collection;
use Symfony\Component\Validator\Constraints\Type;
use Symfony\Component\Validator\Mapping\ClassMetadataInterface;
use Symfony\Component\Validator\Mapping\MetadataInterface;
use Symfony\Component\Validator\Validator\RecursiveValidator;
<?php declare(strict_types=1);
if (!\function_exists('array_map_recursive')) {
function array_map_recursive(array $array, callable $function): array
{
$out = [];
foreach ($array as $key => $value) {
$out[$key] = \is_array($value)
? array_map_recursive($value, $function)
: \call_user_func($function, $value, $key);