Skip to content

Instantly share code, notes, and snippets.


Dan Harper danharper

Block or report user

Report or block danharper

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
danharper / background.js
Last active May 30, 2020
Bare minimum Chrome extension to inject a JS file into the given page when you click on the browser action icon. The script then inserts a new div into the DOM.
View background.js
// this is the background code...
// listen for our browerAction to be clicked
chrome.browserAction.onClicked.addListener(function (tab) {
// for the current tab, inject the "inject.js" file & execute it
chrome.tabs.executeScript(tab.ib, {
file: 'inject.js'
danharper / gulpfile.js
Last active May 25, 2020
New ES6 project with Babel, Browserify & Gulp
View gulpfile.js
var gulp = require('gulp');
var sourcemaps = require('gulp-sourcemaps');
var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');
var browserify = require('browserify');
var watchify = require('watchify');
var babel = require('babelify');
function compile(watch) {
var bundler = watchify(browserify('./src/index.js', { debug: true }).transform(babel));
danharper /
Last active Apr 16, 2020
Open native Maps apps on iOS and Android in Cordova
iOS (with pin, iOS will lookup address too and show that as label)
Android, no pin (just open at location)
danharper / CatchAllOptionsRequestsProvider.php
Last active Apr 8, 2020
Lumen with CORS and OPTIONS requests
View CatchAllOptionsRequestsProvider.php
<?php namespace App\Providers;
use Illuminate\Support\ServiceProvider;
* If the incoming request is an OPTIONS request
* we will register a handler for the requested route
class CatchAllOptionsRequestsProvider extends ServiceProvider {
danharper / 1-sleep-es7.js
Created Feb 8, 2015
ES7's async/await syntax.
View 1-sleep-es7.js
// ES7, async/await
function sleep(ms = 0) {
return new Promise(r => setTimeout(r, ms));
(async () => {
await sleep(1000);
danharper / CancellationTokenSource.js
Last active Oct 4, 2019
JavaScript "CancellationToken" for cancelling Async/Promise functions
View CancellationTokenSource.js
const CANCEL = Symbol();
class CancellationToken {
constructor() {
this.cancelled = false;
throwIfCancelled() {
if (this.isCancelled()) {
danharper /
Last active Aug 26, 2019
Laravel Queue Supervisor

Install Supervisor with sudo apt-get install supervisor. Ensure it's started with sudo service supervisor restart.

In /etc/supervisord/conf.d/ create a .conf file. In this example, laravel_queue.conf (contents below). Give it execute permissions: chmod +x laravel_queue.conf.

This file points at /usr/local/bin/, so create that file there. Give this execute permissions, too: chmod +x

Now update Supervisor with: sudo supervisorctl reread. And start using those changes with: sudo supervisorctl update.

danharper /
Created Jan 27, 2015
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 /
Created Jun 16, 2016
building an ionic/cordova android app on ubuntu. actually using circle, but needed to test something out on a fresh box
# starting with a Ubuntu 14 box on AWS
# increase swap
sudo fallocate -l 4G /swapfile
ls -lh /swapfile
sudo chmod 600 /swapfile
ls -lh /swapfile
sudo mkswap /swapfile
danharper / 1.Bus.js
Last active Oct 8, 2018
JavaScript Command Bus
View 1.Bus.js
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);
You can’t perform that action at this time.