Skip to content

Instantly share code, notes, and snippets.

View JavadocMD's full-sized avatar

Tyler JavadocMD

View GitHub Profile
@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) {
package com.javadocmd.drawing;
import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.InputAdapter;
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Pixmap;
@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) {
@JavadocMD
JavadocMD / store.ts
Created July 25, 2019 00:11
TypeScript React/Redux Example
// user/store.ts
import * as Redux from 'redux'
import { anonymous, authenticated, User, UserData } from './User'
/* State */
export interface State {
readonly user: User
}
@JavadocMD
JavadocMD / OptionWithNever.ts
Created July 22, 2019 17:36
A simple example demonstrating the use of never in TypeScript.
// 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) {
super()
}
@JavadocMD
JavadocMD / ObservablesExamples.cs
Last active October 20, 2017 05:19
UniRx Before and After Example: loading a catalog from a web API while falling back to two on-disk sources.
// 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
JavadocMD / ProjectName.sln.DotSettings
Last active October 4, 2017 10:48
A nice DotSettings file for JetBrains Rider projects.
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/CodeEditing/Intellisense/CodeCompletion/IntelliSenseCompletingCharacters/CSharpCompletingCharacters/UpgradedFromVSSettings/@EntryValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/Highlighting/IdentifierHighlightingEnabled/@EntryValue">True</s:Boolean>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=SuggestVarOrType_005FSimpleTypes/@EntryIndexedValue">DO_NOT_SHOW</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=UnassignedField_002ECompiler/@EntryIndexedValue">DO_NOT_SHOW</s:String>
<s:String x:Key="/Default/CodeStyle/CodeCleanup/RecentlyUsedProfile/@EntryValue">Default: Reformat Code</s:String>
<s:String x:Key="/Defaul