Skip to content

Instantly share code, notes, and snippets.

Avatar

Daniel Buckmaster crabmusket

View GitHub Profile
@crabmusket
crabmusket / README.md
Last active Jul 3, 2021
Headless rendering with THREE.js
View README.md

Headless THREE

Created with

Make sure you install headless-gl's dependencies, then run with XVFB like so:

View json-rpc-pipelines.md

JSON-RPC pipeline batches

Typical RPC implementation

Say we want to implement an RPC service for basic maths operations. For example, let's calculate the value of ln(e^2). This calculation has several steps in our maths API:

  1. Get the value of e
  2. Square e
@crabmusket
crabmusket / server.py
Created May 6, 2020
Python simple HTTP server
View server.py
# https://blog.notryan.com/server.py
# https://www.reddit.com/r/programming/comments/gdxh3w/http_blog_server_100_lines_of_c_in_a_closet/fpkqvqw/
import socket
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.bind(("0.0.0.0", 8080))
sock.listen(1)
while True:
View Alphabet.hs
module Alphabet (
Alphabet,
encodeWithAlphabet,
decodeFromAlphabet
) where
import Prelude
import Data.List(elemIndex, mapAccumR)
import Data.Maybe(fromMaybe)
@crabmusket
crabmusket / MJML.php
Last active Mar 5, 2020
MJML emails in Laravel
View MJML.php
<?php
namespace App\Mail;
use Symfony\Component\Process\Process;
use Symfony\Component\Process\Exception\ProcessFailedException;
use Symfony\Component\Process\Exception\RuntimeException;
use Illuminate\Contracts\View\Factory as ViewFactory;
use Illuminate\Support\HtmlString;
View README.md

deno_env_file.ts

Use this snippet to parse, modify and render environment files.

import { EnvFile } from "https://gist.githubusercontent.com/crabmusket/e10effe4800691bb15543ff264518e76/raw/deno_env_file.ts";

let content = `
KEY=value
SOMETHING_ELSE=cool
@crabmusket
crabmusket / json.ts
Last active Oct 1, 2019
JSON utilities for Deno
View json.ts
/** For the spec of the JSON type, see http://json.org */
export type JsonValue = JsonObject | JsonArray | number | string | boolean | null;
/** JSON objects can have any string key. */
export interface JsonObject {[key: string]: JsonValue};
/** For the explanation of this type, see https://github.com/Microsoft/TypeScript/issues/3496#issuecomment-128553540 */
export interface JsonArray extends Array<JsonValue> {};
/** Narrow the type of a JsonValue to check if it's an object. */
@crabmusket
crabmusket / readme.md
Last active Aug 12, 2019
Async semaphore utility class for Deno
View readme.md

semaphore.ts

An asynchronous semaphore utility class meant to work with Deno. You can use it to implement rate-limiting and other concurrency patterns.

Usage example:

import { Semaphore } from "https://gist.githubusercontent.com/crabmusket/681b4f81ed05716f8dd10ac88d1d960b/raw/5e7c18013e896425d1048324f8668932f23437df/semaphore.ts";
@crabmusket
crabmusket / deno_micro_modules.md
Last active Aug 12, 2019
Deno micro modules index page
View deno_micro_modules.md

Deno micro modules

Each of these modules is a single file consisting of no more than a page or two of code, which provide some useful 'generic' feature. These modules could be copied as-is into any TypeScript project, but they're designed to work with Deno. Deno's URL loading makes it very easy to import them.

@crabmusket
crabmusket / Dockerfile
Last active Aug 9, 2019
Build Deno in a Docker container
View Dockerfile
FROM ubuntu:16.04
RUN apt-get update && apt-get install \
build-essential \
clang-3.8 \
curl \
git \
libxml2 \
python-dev \
-y