Skip to content

Instantly share code, notes, and snippets.

View mdboop's full-sized avatar
🐐

Matthew Brooks mdboop

🐐
View GitHub Profile
function epic(action$) {
return Observable.ofType('FETCH_FOO')
.mergeMap(() =>
ajax('/api/foos')
.map((data) => ({
type: 'FETCH_FOO_SUCCESS',
data,
}))
.catch((err) => [{
type: 'FETCH_FOO_ERROR',
@mdboop
mdboop / either-react.jsx
Last active August 30, 2017 21:29
Functional null-check and code-branching with React
/**
* This is something I threw together as a quick test.
* It's a contrived example because you'd likely just have one component for message and include something like:
* <p>{message.body || 'No message.'}</p>
*
* However, when I'm writing components, I often have to handle different UI treatments depending on the data.
* It's the same overall component, same logical chunk of UI, but it might take on three different forms, and
* those differences may have drastically different markup. Those situations make it easy start writing a lot
* of imperative code, and I always feel dissatisfied when I have to include if statements in my render functions.
*
import configureMockStore from 'redux-mock-store';
import { createEpicMiddleware, combineEpics } from 'redux-observable';
import { Observable } from 'rxjs';
import userEpic from './userEpic.js';
import { fetchUser } from '../actionCreators/users.js';
describe('userEpic', () => {
// set up our mock data and mock request function
@mdboop
mdboop / redux-observable-fsa.js
Last active June 29, 2017 07:18
A little function, which could be paired with flux standard actions to help reduce redux boilerplate.
import { actionCreatorFactory } from 'typescript-fsa'
import { ajaxGetJSON, ajaxPost, ajaxPut, ajaxDelete } from 'rxjs'
import { combineEpics } from 'redux-observable'
const createEpic = (fsa, request, prepare) =>
(action$, store) =>
action$.ofType(fsa.started.type)
.map(
action => (typeof prepare === 'function' ? prepare(action, store.getState() : action.payload)
)
@mdboop
mdboop / shrimp-linguine.md
Last active January 12, 2018 23:32
Simple pasta recipe with shrimp

Shrimp Linguine

  • 1 lb spaghetti or linguine
  • 1 lb shrimp, cleaned and deveined
  • 1/4 cup olive oil
  • 1/2 cup butter (1 stick)
  • 1 cup white wine
  • finely chopped garlic, as desired (4-5 gloves is good)
  • 1 medium shallot, finely chopped
  • sliced mushrooms, as desired (~2-3 cups)
@mdboop
mdboop / autocomplete.jsx
Last active September 4, 2019 15:45
Simple Rxjs + Downshift autocomplete
import React from 'react';
import Downshift from 'downshift';
import Rx from 'rxjs';
import { ajax } from 'rxjs/observable/dom/ajax';
const makeUrl = search =>
`https://en.wikipedia.org/w/api.php?action=query&format=json&list=search&utf8=1&srsearch=${encodeURIComponent(str)}`;
const input$ = new Rx.Subject();
@mdboop
mdboop / matching.js
Created October 27, 2020 07:52
mock interview question
const assert = require("assert");
function matchingBrackets(str) {
// TODO: implement me!
}
// Test cases
assert.strictEqual(matchingBrackets("{}"), true);
assert.strictEqual(matchingBrackets("{"), false);
assert.strictEqual(matchingBrackets(""), true);
@mdboop
mdboop / docker-compose.yml
Created November 20, 2020 14:36
A docker compose configuration for developing locally with Postgres and Redis
version: "3.8"
services:
redis:
image: "redis:alpine"
ports:
- 6379:6379
postgres:
image: "postgres:13.1"
ports:
- 5432:5432
@mdboop
mdboop / newline.sh
Created January 6, 2021 06:15
newline check for file
if [[ -s redirects && -z "$(tail -c 1 redirects)" ]]; then exit 1; else echo "redirects file newline check OK."; fi;