Skip to content

Instantly share code, notes, and snippets.

@Richienb
Richienb / index.js
Created June 25, 2020 04:37
Express with SSL
const express = require("express");
const devcert = require("devcert");
const app = express();
(async () => {
const ssl = await devcert.certificateFor("localhost");
https.createServer(ssl, app).listen(3000);
})()
const pSpread = require("p-spread")
pSpread(Promise.resolve([1, 2]), console.log)
@Richienb
Richienb / index.js
Last active June 7, 2020 02:55
GCD
const gcd = (a, b) => {
if (typeof a !== "number") {
throw new TypeError(`Expected number, got ${typeof a}`)
}
if (typeof b !== "number") {
throw new TypeError(`Expected number, got ${typeof b}`)
}
if (b === 0) {
@Richienb
Richienb / README.md
Last active August 7, 2020 06:00
Convert between HEX and Scratch CSB

Convert between HEX and Scratch CSB

Example

const hexCsb = require("hex-csb")
const csbHex = require("csb-hex")

hexCsb("#90dffe")
//=> [82, 41, 33]
@Richienb
Richienb / index.js
Last active January 26, 2021 06:04
Javascript logic gates
exports.not = a => !a
exports.or = (a, b) => a || b
exports.nor = (a, b) => !a && !b
exports.and = (a, b) => a && b
exports.nand = (a, b) => !a && !b
@Richienb
Richienb / index.js
Last active June 30, 2020 06:58
internalIp.v4() for browsers
const internalIp = async () => {
if (!RTCPeerConnection) {
throw new Error("Not supported.")
}
const peerConnection = new RTCPeerConnection({ iceServers: [] })
peerConnection.createDataChannel('')
peerConnection.createOffer(peerConnection.setLocalDescription.bind(peerConnection), () => { })
@Richienb
Richienb / settings.json
Last active May 11, 2020 02:26
My Windows Terminal config
// To view the default settings, hold "alt" while clicking on the "Settings" button.
// For documentation on these settings, see: https://aka.ms/terminal-documentation
{
"$schema": "https://aka.ms/terminal-profiles-schema",
"defaultProfile": "{0eca68b7-6ef1-402f-b212-a6a02220ae13}",
"theme": "dark",
"profiles": [
{
"guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
"name": "Windows PowerShell",
@Richienb
Richienb / LICENSE
Created May 4, 2020 15:35
Flashlight control
MIT License
Copyright (c) 2020 Richie Bendall
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

Keybase proof

I hereby claim:

  • I am Richienb on github.
  • I am richienb (https://keybase.io/richienb) on keybase.
  • I have a public key whose fingerprint is 8D82 25A7 B9A4 B05A 1412 5906 3D6E BC25 5449 456A

To claim this, I am signing this object:

@Richienb
Richienb / index.js
Created March 29, 2020 10:22
Send an email in node.js
const { promisify } = require("util")
const sendmail = promisify(require("sendmail")({ silent: true }))
module.exports = async (options) => {
await sendmail(options)
}