Skip to content

Instantly share code, notes, and snippets.

View WaldoJeffers's full-sized avatar
🤓
Building a new standard JS library: conductor

WaldoJeffers

🤓
Building a new standard JS library: conductor
View GitHub Profile

Strings

String.prototype.*

None of the string methods modify this – they always return fresh strings.

  • charAt(pos: number): string ES1

    Returns the character at index pos, as a string (JavaScript does not have a datatype for characters). str[i] is equivalent to str.charAt(i) and more concise (caveat: may not work on old engines).

@VictorTaelin
VictorTaelin / promise_monad.md
Last active April 28, 2024 13:28
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

@MatthieuLemoine
MatthieuLemoine / crypto.js
Created January 23, 2017 14:36
Node crypto sign & verify
const id = '__JUNK__';
// Public key need to be in PKCS8 format
// ssh-keygen -e -m PKCS8 -f id_rsa.pub > id_rsa.pkcs8
const publicKey = fs.readFileSync(path.join(__dirname, 'id_rsa.pkcs8'), { encoding : 'utf8' });
const privateKey = fs.readFileSync(path.join(__dirname, 'id_rsa'), { encoding : 'utf8' });
// Sign
const signer = crypto.createSign('RSA-SHA512');
signer.update(id);
const signature = signer.sign(privateKey, 'hex');

Transduce


What is transduce? What is it for? This document is intended to help people (such as myself) who would be looking through the ramda docs, find transduce and have no idea if it would be a good fit for my current problem.

@MatthieuLemoine
MatthieuLemoine / 1_install_lets_encrypt
Last active May 24, 2016 13:13
nginx + Let's encrypt = <3
#!/bin/bash
sudo apt-get install git bc
sudo git clone https://github.com/letsencrypt/letsencrypt /opt/letsencrypt
sudo mkdir /var/www/letsencrypt
sudo chown www-data /var/www/letsencrypt
@Avaq
Avaq / combinators.js
Last active May 1, 2024 09:38
Common combinators in JavaScript
const I = x => x
const K = x => y => x
const A = f => x => f (x)
const T = x => f => f (x)
const W = f => x => f (x) (x)
const C = f => y => x => f (x) (y)
const B = f => g => x => f (g (x))
const S = f => g => x => f (x) (g (x))
const S_ = f => g => x => f (g (x)) (x)
const S2 = f => g => h => x => f (g (x)) (h (x))