This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace Login { | |
public static partial class Login { | |
// Call this from the outside to log in | |
public static void LogIn() { | |
DoLogIn(); | |
} | |
// Implementation delegate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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() { /* ... */ } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// user/store.ts | |
import * as Redux from 'redux' | |
import { anonymous, authenticated, User, UserData } from './User' | |
/* State */ | |
export interface State { | |
readonly user: User | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This file would go in your source path, e.g.: src/window.d.ts | |
declare interface Window { | |
foo: string | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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 |