Skip to content

Instantly share code, notes, and snippets.

View pmcelhaney's full-sized avatar

Patrick McElhaney pmcelhaney

View GitHub Profile
....................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................+...........................................................
...............................................................................................................................................................................................................................................................................................................................................................................................................................................................................
@pmcelhaney
pmcelhaney / private-input.html
Created August 12, 2022 21:49
private inputs
<html>
<body>
<p>This is a quick proof of concept that turns any native input into a "private" input when we add `is="wh-secret"`. I may make it more realistic when I have some time. The button is supposed to be an eye icon. </p>
<label for="text">Text:</label
><input id="text" is="wh-secret" type="text" value="hello world" /><br />
<label for="date">Date:</label
><input id="date" is="wh-secret" type="date" value="2022-08-11" /><br />
<label for="time">Time:</label
><input id="time" is="wh-secret" type="time" value="12:00" /><br />
// Put this file in a directory where all of the ESLint repos are checked out
import fs from "fs/promises";
const packages = await fs.readdir("./");
const scripts = await Promise.all(
packages.map((directory) =>
fs
.readFile(`./${directory}/package.json`, "utf-8")
@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[] = [];

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 / 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)));
};
@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 / 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: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: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