Skip to content

Instantly share code, notes, and snippets.


Tyler JavadocMD

View GitHub Profile
JavadocMD / index.js
Created Aug 3, 2020
Follow a Blaseball game for the given team and print updates to the console.
View index.js
import { default as Socket } from ''
// dependencies:
// 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('')
JavadocMD / dedupe.ts
Created Aug 1, 2020
Removes repeated lines from the input.
View dedupe.ts
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 / api.ts
Created Aug 24, 2019
Express handler type constraints.
View api.ts
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 / window.d.ts
Created Aug 23, 2019
Extending Window in Typescript.
View window.d.ts
// This file would go in your source path, e.g.: src/window.d.ts
declare interface Window {
foo: string
JavadocMD / opt.ts
Last active Jul 25, 2019
Possible optional chaining gains?
View opt.ts
// Without optional chaining.
export const getInstance = async (instanceId: string): Promise<Instance> => {
const result = await ec2Client
.describeInstances({ InstanceIds: [instanceId] })
if (!result.Reservations) {
throw new Error(`Could not find instance ${instanceId}`)
if (result.Reservations.length > 1) {
JavadocMD / store.ts
Created Jul 25, 2019
TypeScript React/Redux Example
View store.ts
// user/store.ts
import * as Redux from 'redux'
import { anonymous, authenticated, User, UserData } from './User'
/* State */
export interface State {
readonly user: User
JavadocMD / OptionWithNever.ts
Created Jul 22, 2019
A simple example demonstrating the use of never in TypeScript.
View OptionWithNever.ts
// Let's assume we're writing our own Option type (in practice, you should probably use fp-ts or something).
export abstract class Option<T> {
public abstract map<U>(f: (t: T) => U): Option<U>
// Some needs a type parameter so we know what value it has.
export class Some<T> extends Option<T> {
constructor(public readonly value: T) {
JavadocMD / ObservablesExamples.cs
Last active Oct 20, 2017
UniRx Before and After Example: loading a catalog from a web API while falling back to two on-disk sources.
View ObservablesExamples.cs
// First the solution as provided, using UniRx.
public class ObservablesExample {
// The CatalogInfo, this is non-null immediately after calling LoadCatalog().
public IObservable<CatalogInfo> CatalogInfo;
// Helper methods, where the work of loading is done.
// UniRx makes it painless to execute these off the main thread.
// Errors are handled by Observable.OnError
private IObservable<CatalogInfo> LoadFromPlayFab() { /* ... */ }
JavadocMD / Login.cs
Created Jun 20, 2017
Use of a partial class to implement platform-specific logic in Unity.
View Login.cs
namespace Login {
public static partial class Login {
// Call this from the outside to log in
public static void LogIn() {
// Implementation delegate
JavadocMD /
Created Nov 12, 2016
A script to open Chrome bookmarks or entire folders of bookmarks by name. (Windows)
#!/usr/bin/env python
import os, subprocess, json
# Get all bookmarks matching the given name(s)
def get_bookmarks(profile_dir, names):
with open(os.path.join(profile_dir, 'Bookmarks')) as f:
j = json.load(f)
results = []
# There are two root-level bookmark folders: one for the bookmark bar and one for all others.