Skip to content

Instantly share code, notes, and snippets.

View OhMeadhbh's full-sized avatar

Meadhbh Hamrick OhMeadhbh

View GitHub Profile
@OhMeadhbh
OhMeadhbh / 00_readme.txt
Last active July 28, 2023 12:22
Efficiently Calculating the Parity of a 32 Bit Integer
Read this file first.
Then read the comments at the top of parity_test.c
Then read the comments above each algorithm implementation in parity.c
So there I was talking about efficient implemetation of fundamental functions
with Palmer over at SiFive. Back in the day, I used to participate in informal
contests on rec.games.programmer to see who could craft the most efficient
implementations for population count or bit reversal or bit-blitting. For
programmer types, it's great fun.
@OhMeadhbh
OhMeadhbh / dsdm.dsdm
Created October 6, 2017 19:21
A few files relating to DSD/Message - it's like regexes, but for message flows.
// dsdm.dsdm
//
// DSD/Message : Like Partial Regexes, but for Message Flows
//
// This file introduces some of the concepts of DSD/Message, a language for describing the content and intent of message flows
// between cooperating distributed systems. DSD/Message (aka DSD/M) is used by protocol designers to succinctly define the content
// of protocol messages in loosely coupled systems. It defines two messaging patterns: EVENT and REQUEST / RESPONSE which behave
// like you might imagine. DSD/M also includes a macro capability to allow developers to easily reuse message constructions. The
// VARIANT construction allows developers to unambiguously denote changes in message structure based on specific values of specific
// message omponents. (Don't worry, this is a simple concept, it just sounds complicated when described formally.)
@OhMeadhbh
OhMeadhbh / example.dsd
Last active May 6, 2017 09:29
Example Dynamic Structured Data file
# example.dsd
#
# This file contains a "DSD Message." DSD stands for "Dynamic Structured Data."
# It is a specification for messages that look a little like JSON, but have
# comments and a few features that makes it slightly easier to parse on small
# (8-bit) CPUs. But don't worry about that right now. This document is meant
# to give you the "flavour" of DSD without weighing you down with specifics.
# The first thing you'll notice about DSD is that (like JSON) virtually every
# DSD message you'll likely see is a dictionary (pretty much the same thing
@OhMeadhbh
OhMeadhbh / states.js
Created June 29, 2015 23:30
What US state names are contained within other state names?
var states = [
{ name: "Alabama" },
{ name: "Alaska" },
{ name: "Arizona" },
{ name: "Arkansas" },
{ name: "California" },
{ name: "Colorado" },
{ name: "Connecticut" },
{ name: "Delaware" },
{ name: "Florida" },
@OhMeadhbh
OhMeadhbh / HashRouter.js
Created June 22, 2015 04:21
Simple Hash-Router
// HashRouter.js - an object that routes through a table to an object + method
// based on a the "hash" portion of a http(s) URL. Designed to be much, much
// simpler than the Backbone router.
// Copyright (c) 2015 Meadhbh S. Hamrick
//
// 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
@OhMeadhbh
OhMeadhbh / proxyroutes.json
Last active August 29, 2015 14:16
sn-proxy v1 config file
{
"production": {
"port": 80,
"httpsify": true
},
"staging": {
"port": 8080,
"default": "http://127.0.0.1:19000",
"hosts": [
{ "host": "#lo", "target": "http://127.0.0.1:19002" },
@OhMeadhbh
OhMeadhbh / lifecycle.js
Created February 12, 2015 19:32
node.js http.server object lifecycle
// lifecycle.js
//
// This example demonstrates how to start, use and eventually shut down a node.js server. Many
// node tutorials will tell you to completely restart a node process when changing a http
// server's behavior. This is good advice, since it can limit the effect of memory leaks and
// you don't have to worry about cross-version side effects on your business logic. But
// every now and again you'll run across a situation where it's impractical to restart a
// node process to upgrade server behaviour. For instance, we once made an "intelligent"
// proxy that would change it's logging and routing behaviour based on whether it (or we)
// thought an attack was happening.
@OhMeadhbh
OhMeadhbh / raspiuser
Last active August 29, 2015 14:12
Unhorking Raspbian
# raspiuser
#
# Having a fixed username / password combination is generally considered
# insecure. This script renames the default 'pi' user to one of your own
# choosing (please choose a name other than 'pi'.) Run it as root, passing
# the new username as the first parameter:
#
# sudo ./raspihork testuser
#
@OhMeadhbh
OhMeadhbh / cropify.sh
Created December 24, 2014 00:20
chop the top & bottom from a noisy screenshot
# Figure out how big the input image is
GEO_INPUT=`identify $1 | cut -f 3 -d ' '`
X_INPUT=`echo $GEO_INPUT | cut -f 1 -d x`
Y_INPUT=`echo $GEO_INPUT | cut -f 2 -d x`
# Slice off a 2 pixel wide strip from the left side of the image
# Store as temp.jpg
convert $1 -crop 2x${Y_INPUT}+0+0 temp.jpg
# Now trim off the top of the temp.jpg. But we have to create a new image
@OhMeadhbh
OhMeadhbh / ddn.ddn
Created December 22, 2014 11:34
DDN: Son of Son of Dysfunction
; ddn.ddn
;
; This document describes the Dynamic Data Notation (DDN). DDN is a superset
; of JavaScript Object Notation and fills a similar role. It differs from JSON
; in a few important ways:
;
; * DDN supports comments. Semi-colons (;), hash markes (#) and C++ style
; "slash slash" di-graphs (//) all begin a "to the end of the line" style
; comment. C-style "slash splat" (/*) and "splat slash" (*/) digraphs
; enclose bounded comments.