Skip to content

Instantly share code, notes, and snippets.

View michalwa's full-sized avatar

Michał Wawrzynowicz michalwa

View GitHub Profile
@peter-leonov
peter-leonov / promise_monad.md
Created January 14, 2018 19:52 — forked from VictorTaelin/promise_monad.md
async/await is just the do-notation of the Promise monad

async/await is just the do-notation of the Promise monad

CertSimple just wrote a blog post arguing ES2017's async/await was the best thing to happen with JavaScript. I wholeheartedly agree.

In short, one of the (few?) good things about JavaScript used to be how well it handled asynchronous requests. This was mostly thanks to its Scheme-inherited implementation of functions and closures. That, though, was also one of its worst faults, because it led to the "callback hell", an seemingly unavoidable pattern that made highly asynchronous JS code almost unreadable. Many solutions attempted to solve that, but most failed. Promises almost did it, but failed too. Finally, async/await is here and, combined with Promises, it solves the problem for good. On this post, I'll explain why that is the case and trace a link between promises, async/await, the do-notation and monads.

First, let's illustrate the 3 styles by implementing

@ork
ork / Makefile
Last active January 8, 2022 17:29
Generic C Makefile
EXEC = $(shell basename $$(pwd))
CC = gcc
CFLAGS = -std=gnu11 -O3 -Wall -Wextra -Wpedantic -Wstrict-aliasing
CFLAGS += $(shell pkg-config --cflags glib-2.0 gio-2.0)
LDFLAGS = $(shell pkg-config --libs glib-2.0 gio-2.0)
SRC = $(wildcard *.c)
OBJ = $(SRC:.c=.o)
@shaunlebron
shaunlebron / angleLerp.js
Created February 5, 2014 20:41
The best way to interpolate 2D angles
/*
2D Angle Interpolation (shortest distance)
Parameters:
a0 = start angle
a1 = end angle
t = interpolation factor (0.0=start, 1.0=end)
Benefits:
1. Angles do NOT need to be normalized.