Skip to content

Instantly share code, notes, and snippets.


Sam Thorogood samthor

Block or report user

Report or block samthor

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View post-eleventy-build.js
let configured = false;
let finished = false;
const methodsToCall = [];
function setup() {
const Eleventy = require("@11ty/eleventy");
const originalWrite = Eleventy.prototype.write;
Eleventy.prototype.write = async function(...args) {
const out = await originalWrite.apply(this, args);
samthor / logcat
Last active Jan 29, 2020
Better logcat
View logcat
#!/usr/bin/env python
import logging
import subprocess
import re
import sys
import datetime
RE_SPACES = re.compile('\s+')
samthor / css-modules-plugin.mjs
Last active Aug 14, 2019
CSS Modules plugin for Rollup
View css-modules-plugin.mjs
import fs from 'fs';
// as per
export default function cssModules() {
return {
name: 'css-modules',
async load(id) {
if (!id.endsWith('.css')) {
samthor / crush
Last active Jun 6, 2019
Helpers to compress PNG images
View crush
command_exists() {
type "$1" &> /dev/null
for X in "$@"; do
if [ ${X: -4} == '.png' ]; then
if command_exists zopflipng; then
zopflipng "$X" "$X"
View .bash_functions
# Useful bash functions. This is sourced by the environment file.
# These are available to scripts, but you shouldn't use them in scripts if you
# want them to be portable.
# Usage: pathremove /path/to/bin [PATH]
# Eg, to remove ~/bin from $PATH
# pathremove ~/bin PATH
function pathremove {
local IFS=':'
samthor / gstate
Last active Jun 17, 2019
Sam's git status replacement
View gstate
heading() {
# or "\e" on *nix
echo -e "${HEAD}${1}${DONE}"
# 0) find local git repo, or fail now
samthor / emscripten-metadata.js
Last active Apr 16, 2019
code to read emscripten_metadata section of Web Assembly files
View emscripten-metadata.js
function lebReader(array) {
const view = new Uint8Array(array);
let at = 0;
return () => {
if (at >= view.length) {
return -1;
let ret = 0;
samthor / IDObserver.js
Created Sep 9, 2018
helper JS to observe $ changes
View IDObserver.js
* Raw IDObserver class. Use via default method below.
export class IDObserver {
* @param {!Node|!ShadowRoot} root
constructor(root) {
samthor / code.js
Last active Sep 4, 2019
Async cancellable promises
View code.js
// nb. This code is available in an ES module of Promise helpers, here:
// symbol returned to indicate that a call was cancelled
export const takeoverSymbol = Symbol('takeover');
* Accepts a generator function, which yields Promises, and converts it to an async function
* that cancels any previous calls.
View png.c
#include <stdint.h>
#include <string.h>
#include <stdlib.h>
typedef struct {
int chunks, w, h;
} info_t;
const char expected_header[8] = {0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a};
You can’t perform that action at this time.