Skip to content

Instantly share code, notes, and snippets.

View brianarn's full-sized avatar

Brian Sinclair brianarn

View GitHub Profile
@brianarn
brianarn / dateformat-output.txt
Created August 29, 2023 23:32
Getting date format
❯ node dateformat.js
The date: 2023-08-29T23:30:01.758Z
Formatted array: [
{ type: 'month', value: '8' },
{ type: 'literal', value: '/' },
{ type: 'day', value: '29' },
{ type: 'literal', value: '/' },
{ type: 'year', value: '2023' },
{ type: 'literal', value: ', ' },
{ type: 'timeZoneName', value: 'MDT' }
@brianarn
brianarn / Gone.md
Last active June 14, 2021 21:26
A horrible lyric parody of Gone by 'N Sync

Gone

by 'R Sync

Lyric parody of Gone by 'N Sync

Inspired by this tweet

There's a thousand things that I could run
To restore my $HOME

@brianarn
brianarn / fibdent.js
Created March 22, 2017 16:45
Fibonacci-based indentation
function topLevel() {
{
{
{
{
{
{
{
// Pretty
}
@brianarn
brianarn / oneweirdtrick.md
Last active October 22, 2020 23:04
One Weird Trick to never missing a console.log's output

One Weird Trick to never missing a console.log's output

Friends! Have you ever been developing, littered your code with console statements, and then realized you couldn't find what you were looking for? Have you ever wondered, "How can I make this console.log statement stand out in a crowd?"

WONDER NO MORE!

You can provide a special %c prefix to your logged string, and then all magical and printf-like, you can then provide some CSS to style up that line!

Here's a couple of examples that I was JUST using!

@brianarn
brianarn / maths.js
Last active July 6, 2020 22:08
Module to wrap `console.group` around all methods
// A simple object with some methods,
// which throw errors when bad arguments are passed.
var maths = {
square : function (value) {
// Validity checking
if (arguments.length !== 1) {
throw new Error('square: Requires one and only one argument');
}
if (typeof value !== 'number') {
throw new Error('square: Requires numeric argument');
@brianarn
brianarn / README.md
Last active December 17, 2019 05:45
Xfinity Garbage Modal Injection

Xfinity Modal Garbage

This month (November 2017) I exceeded my bandwidth cap with Xfinity. They started injecting this garbage in a TON of my insecure requests.

Another good argument for HTTPS everywhere: It would stop vendors from injecting garbage like this into requests.

June 27, 2018

They're doing it again. https://twitter.com/brianarn/status/1012099526713270272

@brianarn
brianarn / README.md
Last active June 20, 2019 19:38
The Branch Not Merged

The Branch Not Merged

Apologies to Robert Frost

Original: The Road Not Taken


Two loads diverged in a red failed build
and sorry I could not debug both

@brianarn
brianarn / track-focus.js
Created June 6, 2017 03:40
Track focused element
(function () {
var focusedElement;
setInterval(function () {
if (focusedElement !== document.activeElement) {
focusedElement = document.activeElement;
console.log('Focused element changed:', focusedElement);
}
}, 50);
})();
@brianarn
brianarn / README.md
Last active October 24, 2018 16:11
Generative Shrek Art in Slack

Generative Shrek Art in Slack

A colleague took a Shrek image, sliced it into 100 emojis, and put it in our Slack. You can easily tile it.

So, I wrote a super gross terse piece of JS to generate new ... images ... of Shrek using this random art.

Here is that gross bit of art.

If you'd like to see an example, look at the screenshot in this tweet.

@brianarn
brianarn / objectPromiseAll.js
Created May 29, 2018 21:56
like `Promise.all` but for plain non-iterable objects
// Based on inspiration from some conversation in WeAllJS
// See wealljs.org for more info on the community!
// This is assuming a plain JS object which is why it's not using for-of, since
// plain objects aren't iterable
function objectPromiseAll(baseObject) {
return Promise.all(Object.values(baseObject)).then((resolvedValues) => {
const resolvedObject = {};
Object.keys(baseObject).forEach((key, index) => {