Skip to content

Instantly share code, notes, and snippets.

Brandon Blaylock baetheus

Block or report user

Report or block baetheus

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@baetheus
baetheus / useTaskDatumEither.ts
Last active Nov 15, 2019
Preact hook for @nll/dux AsyncData in an fp-ts Task
View useTaskDatumEither.ts
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 / indexeddb.ts
Last active Jun 19, 2019
Quick and dirty wrapper for indexeddb using idb and io-ts
View indexeddb.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 / examples.ts
Created Jun 12, 2019
Building typescript syntax programatically
View examples.ts
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 / io-openapi-3.0.2.ts
Created Jun 5, 2019
io-ts codecs for openapi 3.0.2
View io-openapi-3.0.2.ts
import { Option } from 'fp-ts/lib/Option';
import * as t from 'io-ts';
import { createOptionFromNullable } from 'io-ts-types';
/**
* Semver RegExp from https://github.com/sindresorhus/semver-regex/blob/master/index.js
*/
const SEMVER_REGEX = /(?<=^v?|\sv?)(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)(?:-(?:[1-9]\d*|[\da-z-]*[a-z-][\da-z-]*)(?:\.(?:[1-9]\d*|[\da-z-]*[a-z-][\da-z-]*))*)?(?:\+[\da-z-]+(?:\.[\da-z-]+)*)?(?=$|\s)/gi;
interface SemverBrand {
@baetheus
baetheus / monocle-playground.ts
Created May 21, 2019
Playing with monocle-ts
View monocle-playground.ts
import { array } from 'fp-ts/lib/Array';
import { fromNullable, none, Option, some } from 'fp-ts/lib/Option';
import { fromTraversable, Lens, Optional, Prism } from 'monocle-ts';
/* Interfaces */
interface Bug {
bugId: number;
description: Option<string>;
}
@baetheus
baetheus / useRxjs.ts
Last active Jul 10, 2019
useRxjs POC
View useRxjs.ts
import { some, none, fromNullable } from 'fp-ts/lib/Option';
import { Observable } from 'rxjs'
import { useEffect, useState } from 'react'
const useRxjs = <T>(obs: Observable<T>, init?: T) => {
const [state, setState] = useState(fromNullable(init));
const [errorState, setErrorState] = useState(none);
const [completeState, setCompleteState] = useState(false);
useEffect(() => obs
View imgp.component.ts
import { ChangeDetectionStrategy, Component, ElementRef, EventEmitter, Input, Output, Renderer2 } from '@angular/core';
import { fromEvent, merge, Observable, Subscription } from 'rxjs';
import { catchError, map } from 'rxjs/operators';
const requestImage = (src: string) => {
const img = new Image();
img.src = src;
return merge(fromEvent(img, 'error'), fromEvent(img, 'load')).pipe(
map(evt => {
if (evt.type === 'error') {
@baetheus
baetheus / maxCountDuringPeriod.ts
Last active May 26, 2019
rxjs: maxCountDuringPeriod
View maxCountDuringPeriod.ts
/**
* maxCountDuringPeriod
*/
export const maxCountDuringPeriod = (count: number, period: number) => (obs: Observable<any>) => {
if (count < 2) {
throw new Error('maxCountDuringPeriod count must be greater than or equal to 2');
}
if (period < 0) {
throw new Error('maxCountDuringPeriod period must be positive');
View keybase.md

Keybase proof

I hereby claim:

  • I am baetheus on github.
  • I am baetheus (https://keybase.io/baetheus) on keybase.
  • I have a public key ASCazPD8JqHVme4Inlk1UFORaPUcRKxU-XNuMjjhClrJfwo

To claim this, I am signing this object:

@baetheus
baetheus / input-interfaces.ts
Created Jan 24, 2019
Potential Input State Interfaces
View input-interfaces.ts
export interface InputState<ValueType, MaskType> {
value: ValueType;
mask: MaskType; // TODO Decide on masking implementation
touched: boolean;
invalid: boolean;
focused: boolean;
disabled: boolean;
}
export enum InputEvents {
You can’t perform that action at this time.