Skip to content

Instantly share code, notes, and snippets.

Avatar

Donovan Mueller donut

  • RightThisMinute
  • Phoenix, Arizona, USA
View GitHub Profile
@donut
donut / donut_react.ml
Last active Aug 7, 2019
An alternative to `React.useReducer` that supports middleware with side effects.
View donut_react.ml
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
donut / client_react.ml
Last active Jun 10, 2019
A wrapper for React's useReducer() hook that applies middleware. Written in OCaml.
View client_react.ml
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)
in
let apply_middleware middleware state action =
let dispatch = React.Ref.current middlewared_dispatch in
View Greg Boyd on democracy.md

From:

https://reknew.org/2018/08/part-8-of-15-race-and-social-hierarchies/

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
donut / calc_digits.ml
Last active Nov 10, 2017
Times different methods for calculating the number of digits of an integer.
View calc_digits.ml
#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
donut / jbuild
Created Oct 30, 2017
Demonstrates "Commands out of sync" error with ocaml-mariadb and let
View jbuild
(jbuild_version 1)
(executable
((name main)
(libraries (core cohttp.lwt mariadb))))
View keybase.md

Keybase proof

I hereby claim:

  • I am donut on github.
  • I am donut2d (https://keybase.io/donut2d) on keybase.
  • I have a public key ASC7Ca_uC20tY6gxRMv5jLjQq4AirMKa-6bHWB6W-kXPXgo

To claim this, I am signing this object:

@donut
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 http://stackoverflow.com/a/29460871/134014
var dict = [Key:T]()
for (key, value) in zip(self.keys, self.values.map(transform)) {
dict[key] = value
}
View EventsMixin.coffee
###*
* @file
* Provides support for classes to have event systems.
* @url https://gist.github.com/donut/e4268b600bf72a8290e8
###
class EventsMixin
constructor: ->
@_event_handlers = {}
View mix_of.coffee
###*
* @file
* Provides mixin support for classes.
* @url https://gist.github.com/donut/00e407abb7cece0bcdfa
* @see http://coffeescriptcookbook.com/chapters/classes_and_objects/mixins
###
module.exports = (base, mixins...) ->
constructors = []
@donut
donut / CaptainHook.coffee
Last active Aug 29, 2015
A simple hook system in JavaScript.
View CaptainHook.coffee
###*
* @file
* A hook system.
* @see https://gist.github.com/donut/f16040209cdc6f5e62c2
###
'use strict'
hook =
_callbacks: []
You can’t perform that action at this time.