Skip to content

Instantly share code, notes, and snippets.

View baetheus's full-sized avatar

Brandon Blaylock baetheus

View GitHub Profile
@baetheus
baetheus / tasks.json
Created January 17, 2019 01:25
vscode tasks for schematics-react
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
// Run npm start as default build script (cmd + shift + b)
{
"label": "start",
"type": "npm",
"script": "start",
@baetheus
baetheus / campaigns.ts
Created January 18, 2019 19:46
Example action + reducer + lens + epic
/**
* Get Campaigns
*/
export const getCampaigns = contactStrategyActionFactory.async<number, Campaign[], Error>('GET_CAMPAIGNS');
export const campaignsLens = Lens.fromProp<ContactStrategyStore, 'campaigns'>('campaigns');
const getCampaignsReducer = reducerFactory(getCampaigns, campaignsLens);
const getCampaignsEpic: Epic = a$ =>
a$.pipe(
filterSwitchAsync(getCampaigns, companyId => from(GetCampaigns({ companyId }).then(({ campaigns }) => campaigns)))
@baetheus
baetheus / router.tsx
Last active January 20, 2019 01:35
React Redux Router POC
import * as React from 'react';
import { SFC } from 'react';
import { useRedux } from '~/store';
import { currentRoute, Routes } from '~/stores/routing';
import { Campaign } from './pages/Campaign';
import { Dashboard } from './pages/Dashboard';
export interface RouterProps {}
@baetheus
baetheus / input-interfaces.ts
Created January 24, 2019 21:36
Potential Input State Interfaces
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 {

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 / maxCountDuringPeriod.ts
Last active May 26, 2019 20:30
rxjs: maxCountDuringPeriod
/**
* 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');
@baetheus
baetheus / imgp.component.ts
Created April 23, 2019 19:52
Image fallback
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 / useRxjs.ts
Last active January 13, 2020 09:08
useRxjs POC
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
@baetheus
baetheus / monocle-playground.ts
Created May 21, 2019 01:07
Playing with monocle-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 / io-openapi-3.0.2.ts
Created June 5, 2019 20:56
io-ts codecs for openapi 3.0.2
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 {