Skip to content

Instantly share code, notes, and snippets.


Donovan Mueller donut

  • RightThisMinute
  • Phoenix, Arizona, USA
View GitHub Profile
donut /
Last active Aug 7, 2019
An alternative to `React.useReducer` that supports middleware with side effects.
type ('action, 'state) middleware
= dispatch:('action -> unit)
-> 'state
-> 'action
-> [ `Rerun of 'action | `Next of 'action | `Stop of 'action ]
let apply_middleware middleware dispatch state action =
let rec apply action = function
donut /
Last active Jun 10, 2019
A wrapper for React's useReducer() hook that applies middleware. Written in OCaml.
let use_reducer ?(middleware=[]) reducer initial =
(* [middlewared_dispatch] is setup as a reference so we can change it to the
dispatch function returned by [useReducer]. This way we can insert
middleware before the real reducer function runs. *)
let middlewared_dispatch = React.useRef (fun a ->
Js.Console.error2 "Dispatch called before reducer hook initialized." a)
let apply_middleware middleware state action =
let dispatch = React.Ref.current middlewared_dispatch in
View Greg Boyd on


Well, “back in the day” we had three television Networks, and it was in the interest of all of them to report the News with as little bias as possible to attract the widest possible audience. With the advent of Cable News, however, people are able to watch the filtered version of the News that they agree with and that therefore activates the pleasure centers of their brain. And when liberal and conservative minded people no longer have to try to see the world through each other’s eyes, they get hardened in their perspectives. In time, they lose the willingness, and then the ability, to understand the perspectives of those who fundamentally disagree with their deeply held beliefs. Those who oppose them, therefore, can’t possibly be doing so on rational or moral grounds, which means they must either be stupid or immoral. They therefore cannot be reasoned with. They must simply be defeated.

If someone has a practical solution as to

donut /
Last active Nov 10, 2017
Times different methods for calculating the number of digits of an integer.
#load "unix.cma";;
open Printf;;
let by_string x =
x |> string_of_int |> String.length
let rec by_recursion = function
| 0 -> 1
| x -> 1 + by_recursion (x / 10)
donut / jbuild
Created Oct 30, 2017
Demonstrates "Commands out of sync" error with ocaml-mariadb and let
View jbuild
(jbuild_version 1)
((name main)
(libraries (core cohttp.lwt mariadb))))

Keybase proof

I hereby claim:

  • I am donut on github.
  • I am donut2d ( on keybase.
  • I have a public key ASC7Ca_uC20tY6gxRMv5jLjQq4AirMKa-6bHWB6W-kXPXgo

To claim this, I am signing this object:

donut / Dictionary.swift
Created Mar 9, 2016
Adds Dictionary.mapValues method
View Dictionary.swift
import Foundation
extension Dictionary {
func mapValues<T>(transform: Value->T) -> Dictionary<Key,T> {
// Adapted from
var dict = [Key:T]()
for (key, value) in zip(self.keys, {
dict[key] = value
* @file
* Provides support for classes to have event systems.
* @url
class EventsMixin
constructor: ->
@_event_handlers = {}
* @file
* Provides mixin support for classes.
* @url
* @see
module.exports = (base, mixins...) ->
constructors = []
donut /
Last active Aug 29, 2015
A simple hook system in JavaScript.
* @file
* A hook system.
* @see
'use strict'
hook =
_callbacks: []
You can’t perform that action at this time.