Skip to content

Instantly share code, notes, and snippets.

@matthew-gerstman
matthew-gerstman / HarryPotter.pas
Last active March 10, 2018 01:43
I wrote this program in the 8th grade to help me pick which chapter of which Harry Potter audiobook to fall asleep to.
Program HarryPotter (input,output);
Uses CRT;
Var
Book,Chapter,Last,test,index,PW,hold,High,Low,Multiple,v,Check:Integer;
Part:Char;
Unwanted:Array [1..4] of integer;
Procedure Matt;
Var
//redux-utils/types.ts
import { Reducer } from "redux";
import { MuggleNamespaceShape } from "../data/muggles/types";
import { WizardNamespaceShape } from "../data/wizards/types";
export const MUGGLE_NAMESPACE_KEY = "MUGGLE_NAMESPACE";
export const WIZARD_NAMESPACE_KEY = "WIZARD_NAMESPACE";
export type FullStoreShape = {
// redux-utils/store.ts
import { combineReducers, createStore, Store } from "redux";
import { ReducerMap, StoreShape } from "./types";
let reducerMap: ReducerMap = {};
const store = createStore(combineReducers(reducerMap));
export function getStore() {
return store;
// redux-utils/selectors.ts
import { FullStoreShape, NamespaceKey, StoreShape } from "./types";
export function getStateAtNamespaceKey<T extends NamespaceKey>(
state: StoreShape,
namespace: T
): FullStoreShape[T] {
const namespaceState = state[namespace];
if (!namespaceState) {
throw new Error(
// wizards.tsx
import * as React from "react";
import { connect, Provider } from "react-redux";
import { getStoreForWizardApp } from "./data/wizards/store";
import { Wizard } from "./data/wizards/types";
import { getWizards } from "./data/wizards/selectors";
export function WizardApp() {
return (
<Provider store={getStoreForWizardApp()}>
// data/wizards/store.ts
import { getStore, registerReducer } from "../../redux-utils/store";
import { WIZARD_NAMESPACE_KEY } from "../../redux-utils/types";
import { once } from "lodash";
import wizardReducer from "./reducer";
export const getStoreForWizardApp = once(() => {
registerReducer({ [WIZARD_NAMESPACE_KEY]: wizardReducer });
return getStore();
});
// data/wizards/selectors.ts
import { getStateAtNamespaceKey } from "../../redux-utils/selectors";
import { StoreShape, WIZARD_NAMESPACE_KEY } from "../../redux-utils/types";
import { mapValues } from "lodash";
import { Wizard } from "./types";
const getWizards = (state: StoreShape) => (
getStateAtNamespaceKey(state, WIZARD_NAMESPACE_KEY)
);
// data/wizards/actions.ts
import { AnyAction } from "redux";
export type Wizard = {
name: string;
parentsAlive: boolean;
spells: string[];
};
export const enum WizardActionTypes {
LearnSpell = "WIZARD/LEARN_SPELL",
// data/wizards/reducer.ts
import { WizardAction, WizardActionTypes, WizardNamespaceShape } from "./types";
const defaultState: WizardNamespaceShape = {
harryPotter: {
name: "Harry Potter",
parentsAlive: false,
spells: []
}
};