Skip to content

Instantly share code, notes, and snippets.

View OliverJAsh's full-sized avatar

Oliver Joseph Ash OliverJAsh

View GitHub Profile
@OliverJAsh
OliverJAsh / foo.sh
Last active June 27, 2018 12:32
git pr-merge-and-clean
#!/bin/bash
# Dependencies:
# - hub (`brew install hub`)
# - climergebutton (`brew install vitorgalvao/tiny-scripts/climergebutton`)
set -eou pipefail
# TODO:
# - fail if no URL argument
@OliverJAsh
OliverJAsh / foo.ts
Last active June 27, 2018 02:23
Type safe routing with `fp-ts-routing` and `unionize`
import {
end,
int,
lit,
Match,
parse,
Route as RouteBase,
zero
} from "fp-ts-routing";
import { pipe } from "fp-ts/lib/function";
@OliverJAsh
OliverJAsh / foo.patch
Created March 7, 2018 14:28
React v15: log and time stamp end of batch update
diff --git a/node_modules/react-dom/lib/ReactDefaultBatchingStrategy.js b/node_modules/react-dom/lib/ReactDefaultBatchingStrategy.js
index 5e149f0..96e34a0 100644
--- a/node_modules/react-dom/lib/ReactDefaultBatchingStrategy.js
+++ b/node_modules/react-dom/lib/ReactDefaultBatchingStrategy.js
@@ -20,6 +20,8 @@ var emptyFunction = require('fbjs/lib/emptyFunction');
var RESET_BATCHED_UPDATES = {
initialize: emptyFunction,
close: function () {
+ console.timeStamp('end React batch update');
+ console.log('end React batch update');
@OliverJAsh
OliverJAsh / foo.js
Last active September 20, 2022 18:18
GitHub PR snippets
// Expand all collapsed commits
$$('.js-timeline-progressive-disclosure-button').forEach(el => el.click());
// Expand all collapsed conversations
$$('button')
.filter(el => el.innerText === 'Load more…')
.forEach(el => el.click());
@OliverJAsh
OliverJAsh / foo.ts
Created December 10, 2017 21:34
Luxon TypeScript typings
declare module 'luxon' {
namespace luxon {
type DateTimeFormat = any;
type ZoneOptions = {
keepCalendarTime?: boolean;
};
type ToFormatOptions = {
round: boolean;
};
@OliverJAsh
OliverJAsh / foo.md
Created December 8, 2017 11:29
Avoiding CSS overrides in responsive components

Avoiding CSS overrides in responsive components

I would like to demonstrate some of the benefits of scoped styles over mobile-first CSS with overrides for wider breakpoints. I'll start by explaining the two approaches, before listing the benefits.

Mobile-first with overrides for wider breakpoints

h2 {
  color: black;
 font-size: 2em;
@OliverJAsh
OliverJAsh / foo.md
Created November 29, 2017 17:35
Tagged unions with unionize

Tagged unions are a way of saying "this data is any one of these values", and the tag is a property that discriminates the values. It enables some really powerful type system features, like exhaustive checking and control flow analysis.

Tagged unions also go by the name of: tagged unions, discriminated unions, algebraic data types (ADTs), and sum types. Just to confuse matters.

In many functional languages this is a really common pattern, like Haskell, Elm, PureScript, and Scala. So much so, they have their own native syntax.

For example, in Elm we can define a tagged union representing an anonymous or named user with:

// elm
@OliverJAsh
OliverJAsh / foo.ts
Created November 28, 2017 20:03
TypeScript enums at the type and value level
{
// Enums represent types and values
// At the type level, this is a union of all enum members
// At the value level, this is an object containing enum members
enum TypeEnum {
foo,
bar,
baz,
}
@OliverJAsh
OliverJAsh / foo.ts
Last active January 27, 2025 18:24
Records and dictionaries in TypeScript
/*
In JavaScript, objects can be used to serve various purposes.
To maximise our usage of the type system, we should assign different types to our objects depending
on the desired purpose.
In this blog post I will clarify two common purposes for objects known as records and dictionaries
(aka maps), and how they can both be used with regards to the type system.