Skip to content

Instantly share code, notes, and snippets.

View baetheus's full-sized avatar

Brandon Blaylock baetheus

View GitHub Profile
@baetheus
baetheus / examples.ts
Created June 12, 2019 20:58
Building typescript syntax programatically
import * as ts from 'typescript';
// import { Option as Option } from 'fp-ts/lib/Option';
const a = ts.createImportDeclaration(
undefined,
undefined,
ts.createImportClause(
undefined,
ts.createNamedImports([
ts.createImportSpecifier(
@baetheus
baetheus / indexeddb.ts
Last active June 19, 2019 15:49
Quick and dirty wrapper for indexeddb using idb and io-ts
import { Either } from 'fp-ts/lib/Either';
import { openDB } from 'idb';
import { array, Type } from 'io-ts';
import { from, Observable, of, throwError } from 'rxjs';
import { mergeMap } from 'rxjs/operators';
export const objectFactory = (
name: string,
keyPath: string,
option: 'readonly' | 'readwrite' | 'versionchange' = 'readonly',
@baetheus
baetheus / useTaskDatumEither.ts
Last active November 15, 2019 17:48
Preact hook for @nll/dux AsyncData in an fp-ts Task
import { DatumEither, failure, initial, toRefresh } from '@nll/datum/lib/DatumEither';
import { Task } from 'fp-ts/lib/Task';
import { Errors } from 'io-ts';
import { useEffect, useState } from 'preact/hooks';
export const useTaskDatumEither = <T>(task: Task<DatumEither<Errors, T>>) => {
const [state, setState] = useState<DatumEither<Errors, T>>(initial);
useEffect(() => {
// Setup "cancellation closure"
let linked = true;
@baetheus
baetheus / output.txt
Last active March 20, 2020 19:23
Rust Store
Print Listener: [1, 2]
SHOULD ONLY HAPPEN ONCE: [1, 2]
Print Listener: [1, 2, 1]
Print Listener: [1, 2, 1, 2]
Print Listener: [1, 2, 1, 2, 3]
Print Listener: [1, 2, 1, 2, 3, 4]
Final State: [1, 2, 1, 2, 3, 4]
@baetheus
baetheus / bin.rs
Last active March 28, 2020 17:57
Playing around with nom and parsing
use nom::{
branch::alt,
bytes::complete::{tag, take_until, take_while},
character::{complete::line_ending, is_alphabetic},
combinator::{map, opt, rest},
sequence::tuple,
IResult,
};
use std::str::from_utf8;
@baetheus
baetheus / Angular.ts
Created April 13, 2020 22:47
Angular helpers for @nll/dux test
import { Store as S, createStore, MetaReducer, RunOnce, RunEvery } from "./Store";
import { Reducer } from "./Reducers";
export interface StoreConfig<T> {
readonly reducers: Reducer<T>[];
readonly metaReducers: MetaReducer<T>[];
readonly runOnces: RunOnce<T>[];
readonly runEverys: RunEvery<T>[];
}
@baetheus
baetheus / createStateRestore.ts
Last active May 14, 2020 22:38
A localstorage manager for use with @nll/dux/Store
import * as C from "io-ts/es6/Codec";
import * as E from "fp-ts/es6/Either";
import { draw } from "io-ts/es6/Tree";
import { pipe } from "fp-ts/es6/pipeable";
import { actionCreatorFactory, AsyncActionCreators } from "@nll/dux/Actions";
import { asyncConcatMap } from "@nll/dux/Operators";
import { RunOnce, filterEvery, RunEvery, Store } from "@nll/dux/Store";
import { of, Observable, throwError, interval } from "rxjs";
import { mergeMap, map } from "rxjs/operators";
@baetheus
baetheus / fp_ts.ts
Last active May 17, 2020 21:21
Deno Oak adapter for hyper-ts
export * from "https://cdn.pika.dev/fp-ts@^2.6.1";
@baetheus
baetheus / models.ts
Last active June 18, 2020 05:42
Damped Harmonic Motion - See @nll/motion for further work
/**
* @since 0.0.0
*/
/**
* @since 0.0.0
*/
export interface SpringConfig {
mass: number;
tension: number;
@baetheus
baetheus / main.ts
Created September 29, 2020 03:09
Deno with sedate
import { serve } from "https://deno.land/std/http/server.ts";
import { connect } from "https://deno.land/x/redis@v0.13.0/mod.ts";
import { use } from "https://deno.land/x/sedate@v0.0.2/deno_handler.ts";
import * as S from "https://deno.land/x/sedate@v0.0.2/sedate.ts";
import { pipe } from "https://deno.land/x/hkts@v0.0.15/fns.ts";
const nil = <A>(a: A): a is NonNullable<A> => a === undefined && a === null;
const PORT = Deno.env.get("PORT");
const REDIS_URL = Deno.env.get("REDIS_URL");