Skip to content

Instantly share code, notes, and snippets.

View nkabrown's full-sized avatar

Nathan Brown nkabrown

View GitHub Profile
@nkabrown
nkabrown / aoc-node-starter.js
Last active December 8, 2023 17:39
Advent of Code Node/ESM starting template
// in package.json need to set type field to module { "type": "module" }
import { open } from 'node:fs/promises';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
// recreate Node globals for ESM modules
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
(async () => {
@nkabrown
nkabrown / LEARNINGS.md
Last active December 8, 2023 17:40
Advent of Code 2023 Learnings

2023 Advent of Code Learnings

The nature of the input data, files consisting of lines of text, means that regex often seems the perfect tool to accomplish subtasks needed for puzzle solutions. As I'm learning more about regular expressions this year I've found these resources helpful:

Day 01

@nkabrown
nkabrown / dependency-updates.md
Last active February 1, 2023 20:42
Regular dependency updates

Regular Dependency Updates

Regular dependency updates are important for long-lasting codebases. For short-term projects and one-off scripts nothing might ever have to change, but for software that is in use for a long enough period of time everything will likely have to change, eventually. Regular dependency updates are a good practice because they chunk the amount of changes we have to review and navigate into a managable amount and save us from problematic version migrations. They keep our systems in tip-top shape and help us avoid technical debt.

Make them regular because:

  • You want to keep the number of changes you have to review for any dependency at any one time minimal.
  • You want to avoid deferring breaking changes and gathering them all up into a problematic, complex, and hard to understand series of version migrations.
  • You want to resolve security vulernabilites promptly.
  • You want new improvements and fixes to flow into your project regularly.
@nkabrown
nkabrown / proxy-list-format.js
Last active June 5, 2019 03:09
Return a default value when passing empty arrays to Intl.ListFormat
var countryList = ['Mexico', 'United States', 'Canada'];
// prefer not to use the Oxford comma so use locale 'en-GB'
var phraseFormatter = new Intl.ListFormat('en-GB', {type: 'conjunction'});
phraseFormatter.default = 'North America';
// see http://exploringjs.com/es6/ch_proxies.html#_intercepting-method-calls
const handler = {
get(target, key) {
@nkabrown
nkabrown / README.md
Last active January 2, 2019 21:59
Pursuit Economic Impact Numbers

PURSUIT

Pursuit is a social impact organization that creates transformation where it’s needed most.

Through our four-year intensive program, we train adults with the most need and potential to get their first tech jobs, advance in their careers, and become the next generation of leaders in tech. Our graduates are hired by leading companies like Pinterest, Kickstarter, LinkedIn, BlackRock, and JPMorgan Chase, and increase their average annual salaries from $18,000 to over $85,000.

I volunteer at Pursuit and I recommend you do too!

@nkabrown
nkabrown / mental-engagement.md
Last active March 28, 2018 02:16
The Pragmatic Programmer – Tip 2 Think! About Your Work – mental engagement

Mental Engagement

Tip 2 – Think! About Your Work

Who feels like programming requires a tireless mindfulness? It kinda does, which is why it's important to take breaks.

Here are a couple of ideas to try that will help you become a better thinker about your work.

Git commit message forecasting

@nkabrown
nkabrown / diversification.md
Last active March 28, 2018 00:34
The Pragmatic Programmer § 5 – Your Knowledge Portfolio – learning plateaus & diversification

Learning Plateaus & Diversification

§ 5 — 'Your Knowledge Portfolio'

The authors of The Pragmatic Programmer talk about the importance of diversifying your knowledge base specifically in terms of guaranteeing your long-term success in a field that is always changing. I want to talk about the power diversification has to jump start your understanding even of those areas you already think you know well.

Probably those of you in class are desperately praying for a learning plateau and a chance to catch your breath. But after your program ends and when you are working you are going to experience some learning plateaus. When you feel this way, "I have a body of stuff I know and am competent with but I'm not learning how to do more", then you've hit a learning plateau. It's pretty common.

I've learned that diversifying your knowledge by learning something completely new is a great way to get your learning momentum moving again. And surprisingly learning something new always seems to shed light on the bundle

Currying Demonstrated and Explained

const getCommand = commands => word => key => key in commands ? commands[key](word) : null;

Wow! What is that? It sure looks cool but what is actually going on there?

That is a curried function and I hope to explain to you over the next page or two what that is and why you might prefer to write this function in that way rather than this:

function getCommand(commands, word, key) {

One line of grep explained:

grep 'TODO' -r -n --exclude-dir={node_modules,.git,lib} --exclude={"*bundle.js","*.map","*.min.js","*.csv",todos.txt} . > todos.txt

This command searches through a directory and its subdirectories for TODO comments and writes them to a text file.

grep is a file pattern searcher and 'TODO' is the pattern we are searching our directories and files for

-r – search recursively through a directory and its subdirectories

@nkabrown
nkabrown / Legend.js
Last active October 6, 2017 18:30
makeover monday - descending triangle bar graph
'use strict';
const d3 = require('./d3.min.js');
export class Legend {
constructor(el, d, r, rm, m, w, h) {
this.mount = el;
this.data = d;
this.regions = r;
this.regionsMap = rm;
this.margin = m;