Skip to content

Instantly share code, notes, and snippets.

View mattmazzola's full-sized avatar

Matt Mazzola mattmazzola

View GitHub Profile
@mattmazzola
mattmazzola / index.ts
Created November 9, 2020 06:45
Library entry point
export function createRatingSystem(kFactor: KFactorOption = 32, exponentDenominator: number = 400, exponentBase: number = 10): RatingSystem
@mattmazzola
mattmazzola / gameScenarioes.csv
Created October 18, 2020 18:19
Game scenarios
We can make this file beautiful and searchable if this error is corrected: It looks like row 2 should actually have 4 columns, instead of 5 in line 1.
A skill, B skill, outcome, effect
lower, higher, A wins, Player A should be rewarded a lot because they were expected to lose, but won
lower, higher, A loses, Player A should not be penalized much because they were expected to lose
@mattmazzola
mattmazzola / machine.js
Created April 24, 2020 04:29
Generated by XState Viz: https://xstate.js.org/viz
const testStateMachine = Machine({
id: 'testState',
initial: 'preload',
states: {
preload: {
on: {
LOAD: {
target: 'ready',
},
},
import express from 'express'
import * as ui from 'cra-package'
const app = express()
app.use(express.static(ui.directoryPath))
app.get('/', function (req, res) {
res.sendFile(ui.defaultFilePath)
})
"builduipackage": "tsc -p ./packageScripts/tsconfig.json --outDir ./package && tsc -p ./scripts/tsconfig.json && node ./scripts/createPackage.js",
@mattmazzola
mattmazzola / express-react.ts
Created January 4, 2020 21:39
How to host React build from Express
const express = require('express');
const path = require('path');
const app = express();
app.use(express.static(path.join(__dirname, 'build')));
app.get('/', function(req, res) {
res.sendFile(path.join(__dirname, 'build', 'index.html'));
});
app.listen(9000);
@mattmazzola
mattmazzola / index.ts
Created December 22, 2019 07:25
Main script of package
import * as path from 'path'
const directoryPath = __dirname
const defaultFilePath = path.join(directoryPath, 'index.html')
export {
directoryPath,
defaultFilePath,
}
@mattmazzola
mattmazzola / createPackage.ts
Created December 22, 2019 07:17
Create Package Script
import * as fs from 'fs-extra'
import * as path from 'path'
const packageJsonPath = path.join(__dirname, '..', 'package.json')
const buildPath = path.join(__dirname, '..', 'build')
const uiPackagePath = path.join(__dirname, '..', 'package')
const indexJsPath = path.join(uiPackagePath, 'index.js')
const indexDtsPath = path.join(uiPackagePath, 'index.d.ts')
async function main() {
@mattmazzola
mattmazzola / userIsAuthenticated.ts
Created October 9, 2017 04:52
authentication required
// tslint:disable-next-line:no-any
const userIsAuthenticated = connectedRouterRedirect<any, State>({
// The url to redirect user to if they fail
redirectPath: '/login',
// Determine if the user is authenticated or not
authenticatedSelector: state => state.user.isLoggedIn,
// A nice display name for this check
wrapperDisplayName: 'UserIsAuthenticated'
})
@mattmazzola
mattmazzola / iauthenticationservice.ts
Created October 9, 2017 04:48
Authentication Service
export interface IAuthenticationService {
acquireTokenAsync<T>(provider: IProvider<T>): Promise<T>
restoreSession<T>(provider: IProvider<T>): T | undefined
invalidateSession(): void
getAccessToken<T>(provider: IProvider<T>, resourceId: string): string
}