Skip to content

Instantly share code, notes, and snippets.

@danharper
danharper / 1-sleep-es7.js
Created February 8, 2015 16:55
ES7's async/await syntax.
// ES7, async/await
function sleep(ms = 0) {
return new Promise(r => setTimeout(r, ms));
}
(async () => {
console.log('a');
await sleep(1000);
console.log('b');
})()
@danharper
danharper / Builder.php
Last active August 29, 2015 14:14
Simple Immutable Builder
<?php
abstract class Builder {
abstract function build();
function __call($name, $arguments)
{
if ( ! property_exists($this, $name))
{
@danharper
danharper / x.md
Created January 27, 2015 08:15
Symfony UploadedFile methods with FileBag notes

Three file inputs, last being "multiple". Let's say we upload a file on each, and three on the multiple input (upload3).

<input type="file" name="upload1">
<input type="file" name="upload2">
<input type="file" name="upload3[]" multiple> <!-- note the [] on name to indicate array -->

Getting files off Request:

@danharper
danharper / down.php
Created January 22, 2015 13:55
downtime
<?php
http_response_code(503);
$message = 'Temporary application maintenance in progress. Please try again shortly.';
if (isset($_SERVER['Content-Type']) && strpos($_SERVER['Content-Type'], 'json') !== false)
{
header('Content-Type', 'application/json');
echo json_encode(['error' => $message]);
@danharper
danharper / 1.Bus.js
Last active May 17, 2022 15:20
JavaScript Command Bus
const handlers = Symbol('handlers');
// adapts a handler class to a common interface
// (technically this one isn't required - the handler class already implements the same interface)
class ClassDispatchable {
constructor(theClass) {
this.theClass = theClass;
}
handle(command) {
return (new this.theClass).handle(command);
@danharper
danharper / ffo.html
Created October 23, 2014 19:38
191 chars. Not selectable due to psuedo elements.
<!doctype html>
<title></title>
<style>
*{display:block;}
title:before{content:"<!doctype html><title></title>";}
style:before{content:"<style>";}
style:after{content:"\3C/style>";}
</style>
<?php
// Version A: Facades everywhere - typical Laravel 4.2 style
// routes.php
Route::get('payments', 'BillingController@recentPayments');
// BillingController.php
class BillingController {
@danharper
danharper / keybase.md
Created September 23, 2014 20:36
keybase.md

Keybase proof

I hereby claim:

  • I am danharper on github.
  • I am danharper (https://keybase.io/danharper) on keybase.
  • I have a public key whose fingerprint is 4EC0 F75A E4A4 CF06 0F41 BCB9 9596 CB4A 8D08 3A0A

To claim this, I am signing this object:

#!/bin/sh
# deploy.sh
N="`readlink \"$1\"`"
mv -T "$1.stage" "$1"
ln -s "$N" "$1.stage"
rm -rf "$N"
cp -aH "$1" "$N"

OS X 10.10 Guide

Here's what I did to get things working.

1. Install Xcode 6

Yep, over at: https://developer.apple.com

2. Install the Command Line Tools (CLT)