Skip to content

Instantly share code, notes, and snippets.

View pmcelhaney's full-sized avatar

Patrick McElhaney pmcelhaney

View GitHub Profile
@pmcelhaney
pmcelhaney / ensureFTPDirectoryExists.cfm
Created August 9, 2010 17:42
Creates a directory on an FTP server if it doesn't already exist. If necessary, creates intermediate directories as well.
<!---
Creates a directory on an FTP server if it doesn't already exist. If necessary,
creates intermediate directories as well.
Usage:
<cfftp action="open" connection="conn" ... />
<cfset ensureFTPDirectoryExists("/path/to/a/dir", conn)>
--->
<cffunction name="ensureFTPDirectoryExists">
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Tab Test</title>
<meta name="author" content="Patrick McElhaney">
</head>
<body>
(function (Hope, _, empire) {
var $ = new Hope();
_(empire.replace(/\b[a-z]{4} /, ""));
return $;
}(
function () { this.prototype = Array; this[0] = "Luke"; this[1] = "Leia"; },
function (x) { console.log(x); },
"Quit fooling around and get back to work."
));
@pmcelhaney
pmcelhaney / gist:2870503
Created June 4, 2012 19:59
Development Tools

A few of my favorite tools

Some of my favorite tools that remove friction from web development. Thanks to @jMoo and @vernonk who pointed me to a lot of these originally.

A lightweight but powerful and extensible editor. $59

Codekit

Automatically reloads browser when a source file is saved. Also compiles, minifies, etc. $20

@pmcelhaney
pmcelhaney / gist:2875523
Created June 5, 2012 15:01
map() is your friend
/*
map() is cool!
This function essentially loops over each row of a table and puts
its data in an array of objects.
It returns something like this:
[
{rate: 1.0, apy: 1.0, productLabel: '3 month CD', earnings: 123.45},
{rate: 1.12, apy: 1.13, productLabel: '6 month CD', earnings: 543.21},
@pmcelhaney
pmcelhaney / gist:3034111
Created July 2, 2012 16:30
requestAnimationInterval
/*
requestAnimationInterval()
A sort of replacement for setInterval that uses requestAnimationFrame.
var myFunction = function (timestamp) {
// do some stuff
}
@pmcelhaney
pmcelhaney / gist:3085144
Created July 10, 2012 17:57
createPromise() -- use promises with libraries that only support callback arguments
var createPromise = function (wrapper) {
var deferred = $.Deferred();
wrapper(
function () { deferred.resolve.apply(deferred, arguments); },
function () { deferred.reject.apply(deferred, arguments); }
);
return deferred.promise();
}
@pmcelhaney
pmcelhaney / gridlines.js
Created July 18, 2012 17:44
Find a round numbers for gridlines, given minimum and maximum values and an optional minimum number of lines.
define(function () {
var log10 = function (val) {
return Math.log(val) / Math.log(10);
};
var scale = function(domain) {
return Math.pow(10, Math.ceil(log10(domain)));
};

Day 7

https://adventofcode.com/2021/day/7

Part 1

This is two steps. First we have to find the final position of all crabs. Then get the sum of steps each crab had to take.

Find the final position of all crabs.

@pmcelhaney
pmcelhaney / clock-controller-test.ts
Last active December 22, 2021 17:10
Reactive controller with unit test
import type { ReactiveControllerHost } from "lit";
import { ClockController } from "../../src/controllers/clock-controller";
class Host implements ReactiveControllerHost {
updateComplete: Promise<boolean>;
clock: ClockController;
emittedTimes: string[] = [];