Linode StackScripts

My side project bracket.club is a mostly static, client heavy webapp, but still requires a few backend pieces to run during its production.

As a primarily frontend developer without a ton of spare time, I try to use as much hosted stuff as possible. I'm currently using a hosted Postgres database at Heroku and a hosted Node.js API at now.sh.

But it's always nice to be able to run a VPS for somethings. In the case of bracket.club, there's a few watchers to check for entries on Twitter and to get the latest results and save them to the DB. This is something that only needs to happen for a few days at a time and even on those days, the watchers might only need to run for a few hours.

This makes these watchers a perfect candidate for Linode's hourly pricing. One of the caveats of hourly pricing though is that you are still charged for the instance even if it's powered off or not in use. So it's essential to be able to easily and effortlessly spin up and teardown these watcher instances in order to take full advantage of hourly pricing.

Read more

Webtasks as Single Serving Backends

(so you can listen to the same song over and over)

TL;DR

I built the repeatone.club using a webtask as the single serving backend.

webtask.io gives you the ability to run some arbitray code with any HTTP call. One of the features of this that I love is the ability to pass secret parameters to your code, such as auth tokens. In the end this gives you the ability to call authenticated APIs that you couldn't from your browser without shipping your API client/secret. Think of them as partially applied functions that can be accessed via a simple GET request.

This perfectly fits the bill for any small single page application that has only a few API calls. This is where one of my favorite bands, The National, comes into play.

Read more

Building a Day One Journal as a Static Site

TL;DR

I built metalsmith-dayone to add Day One data to a metalsmith blog.

Over the past year I've found that Day One is a great app to keep me "journaling". It's easy to use and has a lot of great features that I use to write. It keeps everything private which is what I want most of the time, but I do use it to flesh out ideas for things I might blog or for memories that I might want to share.

This left me wanting to ability easily publish a subset of entries.

Day One does have an export feature, but I found that the publishability of the exports left a lot to be desired. It can do text or HTML, but both of these end up with just one page, even if you export hundreds of entries.

But there's also a JSON export option! Which meant all I had to do was spend a few nights writing (and rewriting and rewriting) some code, and I'd soon be able to publish a site about all the cute things my daughter does.

Read more

Fun with ES2015: Pascal

Just some fun code to determine Pascal's triangle for a certain number using some (borderline unreadable 😄) ES2015 patterns.

// Utils
const last = arr => arr[arr.length - 1]
const withoutLast = arr => arr.slice(0, -1)
const sumWithNext = arr => (val, index) => val + arr[index + 1]

// Sum the values from a row
const createRowValues = arr => withoutLast(arr).map(sumWithNext(arr))

// Create row padded by the start values
const createRow = (previous, start) => [
  start,
  ...createRowValues(previous),
  start
]

// Appends a new row based on the last row
const appendRow = start => rows => [
  ...rows,
  createRow(last(rows), start)
]

// Takes a starting value and the number of rows and returns a nested array
const pascal = (rows, start = 1) => [...Array(rows)].reduce(
  appendRow(start),
  [[start]]
)

pascal(10)

// [ [ 1 ],
//   [ 1, 1 ],
//   [ 1, 2, 1 ],
//   [ 1, 3, 3, 1 ],
//   [ 1, 4, 6, 4, 1 ],
//   [ 1, 5, 10, 10, 5, 1 ],
//   [ 1, 6, 15, 20, 15, 6, 1 ],
//   [ 1, 7, 21, 35, 35, 21, 7, 1 ],
//   [ 1, 8, 28, 56, 70, 56, 28, 8, 1 ],
//   [ 1, 9, 36, 84, 126, 126, 84, 36, 9, 1 ],
//   [ 1, 10, 45, 120, 210, 252, 210, 120, 45, 10, 1 ] ]

Bulk Edit Strava Activities Plugin

TL;DR

Check out the GitHub repo or demo gif.

At some point earlier this year, I wanted to change all my https://strava.com activities from private to public (gotta get on those segment leaderboards!). This looked like a hassle to do by hand, and I'm always looking for a good excuse to prove the XKCD Theory of Automation. So I started coding.

Read more