Skip to content

Instantly share code, notes, and snippets.

View crabmusket's full-sized avatar

Daniel Buckmaster crabmusket

View GitHub Profile
@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;
@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 / 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 / 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 / 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 / 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 / json.ts
Last active October 1, 2019 04:38
JSON utilities for Deno
/** 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 August 12, 2019 23:17
Async semaphore utility class for Deno

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 August 12, 2019 01:54
Deno micro modules index page

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.

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