Skip to content

Instantly share code, notes, and snippets.

View JavadocMD's full-sized avatar

Tyler JavadocMD

View GitHub Profile
@JavadocMD
JavadocMD / Day21.scala
Created December 21, 2022 18:49
A solution to Advent of Code 2022 Day 21.
/*
Copyright 2022 Tyler Coles (javadocmd.com)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
@JavadocMD
JavadocMD / Day16.scala
Last active December 20, 2022 19:00
A solution to Advent of Code 2022 Day 16.
/*
Copyright 2022 Tyler Coles (javadocmd.com)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
@JavadocMD
JavadocMD / Day06Loops.scala
Last active December 14, 2022 19:52
A solution to Advent of Code 2022 Day 6 without sets, only loops (modeled as nested recursive functions).
/*
Copyright 2022 Tyler Coles (javadocmd.com)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
@JavadocMD
JavadocMD / Day01AkkaActors.scala
Last active December 14, 2022 19:52
A solution to Advent of Code 2022 Day 1 using Akka Actors.
/*
Copyright 2022 Tyler Coles (javadocmd.com)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
@JavadocMD
JavadocMD / Day01AkkaStreams.scala
Last active December 14, 2022 19:52
A solution to Advent of Code 2022 Day 1 using Akka Streams.
/*
Copyright 2022 Tyler Coles (javadocmd.com)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
@JavadocMD
JavadocMD / index.js
Created August 3, 2020 22:38
Follow a Blaseball game for the given team and print updates to the console.
import { default as Socket } from 'socket.io-client'
// dependencies: socket.io-client
// Usage example:
// $ node ./dist/index.js "Philly Pies" | espeak-ng -v en-us -s 120
function main() {
const team = process.argv[2] || 'Philly Pies'
const socket = Socket('https://blaseball.com')
@JavadocMD
JavadocMD / dedupe.ts
Created August 1, 2020 19:16
Removes repeated lines from the input.
import { Transform } from 'stream'
import { StringDecoder } from 'string_decoder'
const split = (r: RegExp = /\r?\n/) => {
const enc = 'utf8'
const dec = new StringDecoder(enc)
let prev: string = ''
return new Transform({
defaultEncoding: enc,
transform(chunk, e, callback) {
@JavadocMD
JavadocMD / api.ts
Created August 24, 2019 22:09
Express handler type constraints.
import { Request, NextFunction } from 'express'
interface JsonResponse<T> {
status(code: number): JsonResponse<T>
json(value: T): JsonResponse<T>
}
type JsonHandler<T> = (
req: Request,
res: JsonResponse<T>,
@JavadocMD
JavadocMD / window.d.ts
Created August 23, 2019 07:21
Extending Window in Typescript.
// This file would go in your source path, e.g.: src/window.d.ts
declare interface Window {
foo: string
}
@JavadocMD
JavadocMD / opt.ts
Last active July 25, 2019 19:21
Possible optional chaining gains?
// Without optional chaining.
export const getInstance = async (instanceId: string): Promise<Instance> => {
const result = await ec2Client
.describeInstances({ InstanceIds: [instanceId] })
.promise()
if (!result.Reservations) {
throw new Error(`Could not find instance ${instanceId}`)
}
if (result.Reservations.length > 1) {