Skip to content

Instantly share code, notes, and snippets.

@mrcoles
mrcoles / index.html
Created October 5, 2018 16:26
redux-undo@1.0.0-beta-9.9.7 filter inconsistency
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>Redux Undo Filter Test</title>
</head>
<body>
<p>See info in JS console</p>
<script src="store.js"></script>
</body>
@mrcoles
mrcoles / unirest_promise.js
Created September 8, 2017 17:25
Node Unirest Promise Wrapper
function unirest_prom(unirest_req, always_resolve) {
// Returns a Promise by wrapping a unirest.Request object in
// a Promise that immediately calls `.end(...)`
//
// Params:
//
// * unirest_req - unirest.Request - any unirest Request object that has
// not yet had `.end(...)` called on it
// * always_resolve - bool (optional) - defaults to `false`, iff `true` then
// the Promise always resolves--even when the request fails
@mrcoles
mrcoles / extract-props.d.ts
Created March 6, 2019 16:13
A simple function to split up a props object into specified `customProps` that match `keys` and the remaining `spreadProps`
declare module "extract-props" {
export interface ExtractedProps {
spreadProps: object;
customProps: object;
}
export default function extractProps(props: object, keys: string[]): ExtractedProps;
}
@mrcoles
mrcoles / LoaderDots.jsx
Last active March 13, 2019 03:38
LoaderDots.jsx: a React loader component (to show when waiting on a network call)
import React from 'react';
export default ({
fill = '#666666',
width = 52,
height = 12,
scale = 1,
style = {}
}) => (
<svg
@mrcoles
mrcoles / crop-video.sh
Created April 5, 2019 01:34
Script for cropping iPhone X screen recordings with ffmpeg
#!/usr/bin/env bash
DIMS_SHORT="886:1576:0:104"
DIMS_TALL="886:1816:0:104"
INFILE=
OUTFILE=
DIMS="$DIMS_TALL"
print_usage() {
@mrcoles
mrcoles / csv-script.py
Last active May 15, 2019 21:37
Simple template for a python script that uses argparse and reads in and prints out a CSV or TSV
import csv
def run(infile, outfile, is_tsv=False, dry_run=False):
dialect = 'excel-tab' if is_tsv else 'excel'
reader = csv.DictReader(infile, dialect=dialect)
writer = None
is_first = True
for row in reader:
@mrcoles
mrcoles / clean-amplify-s3-builds.js
Created June 25, 2019 22:58
A script for deleting old amplify builds in s3 and keeping the 5 most recent ones.
const AWS = require('aws-sdk');
const PREFIX = 'amplify-builds/';
const DEFAULT_KEEP_N = 5;
const DEFAULT_DRY_RUN = false;
const s3 = new AWS.S3();
// ## Main
@mrcoles
mrcoles / Plural.tsx
Created July 26, 2019 18:51
A simple React component for handling pluralization of a word.
import React from 'react';
export const Plural = ({
num,
text,
pluralText,
pluralSuffix,
singularSuffix
}: {
num: number;
@mrcoles
mrcoles / parcel-local-proxy.js
Last active December 4, 2019 12:40
A simple proxy script for controlling URL rewriting when running Parcel with multiple entry points (including https support)
const chalk = require('chalk');
const fs = require('fs');
const http = require('http');
const https = require('https');
const yargs = require('yargs');
// Configuration
const DEFAULT_PARCEL_PORT = 4321;
@mrcoles
mrcoles / routeurl.ts
Last active March 5, 2020 17:32
Define your React Router URLs as objects that can be used both in your router and also to generate URL strings.
import { generatePath } from 'react-router';
// ## Route URL
export default class RouteUrl<P extends { [K in keyof P]?: string }> {
constructor(public routePath: string) {}
asPath(params: { [K in keyof P]: string | number | boolean }) {
return generatePath(this.routePath, params);
}