Skip to content

Instantly share code, notes, and snippets.

View djanatyn's full-sized avatar

Jonathan Strickland djanatyn

View GitHub Profile
@VictorTaelin
VictorTaelin / promise_monad.md
Last active May 10, 2024 04:22
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

@typeswitch-dev
typeswitch-dev / minimal.asm
Created September 2, 2022 17:07
Minimal win64 executable in NASM assembly.
org 0 ; We use "org 0" so Relative Virtual Addresses (RVAs) are easy.
; This means that when we want an absolute Virtual Address we have
; to add IMAGE_BASE to the RVA (or whatever the base of that section is)
IMAGE_BASE equ 0x400000
SECT_ALIGN equ 0x200
FILE_ALIGN equ 0x200
msdos_header:
.magic db 'MZ'
@saolsen
saolsen / .Rust_Vals.md
Last active December 26, 2023 00:29
Rust Val

Make a Val with rust.

Build a https://www.val.town/ val with rust. This is an example of how to compile a rust file to wasm and use it as a val.

Requires rust, wasm-pack and deno.

Usage

  • Put your code in val.rs.
  • Build it.
@jessejputnam
jessejputnam / array_methods_cheats.md
Created August 16, 2022 12:57
A cheatsheet for choosing JavaScript array methods

Choosing an array method

I want to...

Mutate the original array

  • Add to original:
arr.push
arr.unshift
@johnelliott
johnelliott / index.js
Last active October 11, 2022 18:04
Streaming HTML standard input demo
#! /usr/bin/env node
const http = require('http')
process.stdin.setRawMode(true)
process.stdin.resume()
process.stdin.setEncoding('utf8')
const server = http.createServer((req, res) => {
res.statusCode = 200
res.setHeader('Content-Type', 'text/html')
res.write('<html>')
@belkarx
belkarx / lemonbar.sh
Created July 22, 2022 20:42
lemonbar.sh
#!/usr/bin/bash
Clock(){
TIME=$(date "+%H:%M:%S")
echo -e -n " \uf017 ${TIME}"
}
Cal() {
DATE=$(date +"%Y/%m/%d [%a]")
@kpmcc
kpmcc / tree.c
Created May 23, 2022 19:21
Simple tree example
// preprocessor macro - basically copies tree.h and puts
// the contents where the include goes
#include <stdio.h>
#include <stdlib.h>
#include "tree.h"
int print_tree_hello() {
@vivshaw
vivshaw / README.md
Last active May 2, 2022 20:55
🙈🙉🙊 Three Wise Monkeys 🙈🙉🙊
module Demo where
-- notice many of these don't have type signatures.
-- Haskell is smart enough figure out 99% of the type signatures for you.
-- any type signatures here are just to add clarity.
-- number
somenumber = 1
-- string
// ==UserScript==
// @name Work Gmail multi-line email list
// @description Makes sure that the new (late 2018) Gmail interface always shows the three-line previews of email lists (mainly for split-pane mode).
// The new Gmail behaviour changes this to one-line when the list pane is wide enough (but not wide enough for my liking).
// @author Lucas Costi
// @namespace https://lucascosti.com
//// The scope below only matches the second Gmail account (which is always my work one).
// @match https://mail.google.com/mail/u/1/*
// @grant none
// ==/UserScript==