Skip to content

Instantly share code, notes, and snippets.

View crabmusket's full-sized avatar

Daniel Buckmaster crabmusket

View GitHub Profile
@crabmusket
crabmusket / readme.md
Last active August 7, 2019 06:20
String title case function for Deno

title_case.ts

Usage example:

import { titleCase } from "https://gist.githubusercontent.com/crabmusket/cd10f732e847afd023a00f6a45bd0d72/raw/558463e1c2a5aa910915a21396b105cefd1254d9/title_case.ts";

console.log(titleCase("deno is AWESOME"));
console.log(titleCase("words-can contain_punctuation"));
console.log(titleCase(" spacing is preserved"));
@crabmusket
crabmusket / Dockerfile
Last active August 9, 2019 04:40
Build Deno in a Docker container
FROM ubuntu:16.04
RUN apt-get update && apt-get install \
build-essential \
clang-3.8 \
curl \
git \
libxml2 \
python-dev \
-y
@crabmusket
crabmusket / php-throwables.md
Last active May 9, 2019 00:05
PHP throwables example

PHP exceptions and errors

In PHP, Exceptions can be caught:

try {
    throw new \DomainException('input out of bounds');
} catch (\Exception $e) {
    echo "got exception\n";
} finally {
@crabmusket
crabmusket / index.html
Created March 19, 2019 04:00 — forked from arrayjam/index.html
Australia Postcode Decoder
<!DOCTYPE html>
<meta charset="utf-8">
<style>
text, label {
font-family: sans-serif;
}
label {
position: absolute;
text-align: center;
@crabmusket
crabmusket / material_design_colors_2014.scss
Last active January 12, 2019 09:21
Google's 2014 material design colour palette as SCSS variables. Because sometimes you just need a bunch of variables. Colours taken from https://github.com/minusfive/sass-material-colors/blob/master/sass/_sass-material-colors-map.scss
$md-col-red-50: #ffebee;
$md-col-red-100: #ffcdd2;
$md-col-red-200: #ef9a9a;
$md-col-red-300: #e57373;
$md-col-red-400: #ef5350;
$md-col-red-500: #f44336;
$md-col-red-600: #e53935;
$md-col-red-700: #d32f2f;
$md-col-red-800: #c62828;
$md-col-red-900: #b71c1c;
@crabmusket
crabmusket / MJML.php
Last active April 12, 2024 11:39
MJML emails in Laravel
<?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;

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 / keybase.md
Created May 18, 2017 11:45
Keybase verification

Keybase proof

I hereby claim:

  • I am crabmusket on github.
  • I am crabmusket (https://keybase.io/crabmusket) on keybase.
  • I have a public key ASC8gXuUziw0CsDZ1i5l0XQoHZmIdciVmtULjMDwc5qeowo

To claim this, I am signing this object:

@crabmusket
crabmusket / mercuryTree.js
Last active August 29, 2015 14:20
Rendering a recursive tree of items with mercury
'use strict';
// Mercury is a 'truly modular frontend framework'. This helpful import gets
// us a lot of top-level symbols from submodules it re-exports.
var hg = require('mercury');
// Like this one - h is a short constructor for HTML elements.
var h = require('mercury').h;
// And since we'll be running this in a browser using beefy, we need a reference
// to the document.
var document = require('global/document');
@crabmusket
crabmusket / Cheryl.hs
Last active August 29, 2015 14:19
A translation of Norvig's solution to the Cheryl's Birthday problem from Python to Haskell. Original: http://nbviewer.ipython.org/url/norvig.com/ipython/Cheryl.ipynb
-- A list of possible dates Cheryl's birthday might be on.
possibilities = [(May, 15), (May, 16), (May, 19),
(June, 17), (June, 18),
(July, 14), (July, 16),
(August, 14), (August, 15), (August, 17)]
-- We say we know the actual date when the list of possibilities is singular.
know ps = length ps == 1
-- Telling someone the month or day will reduce the possibilities.