Skip to content

Instantly share code, notes, and snippets.

View matthewhartstonge's full-sized avatar
👨‍💻
Engineering

Matthew Hartstonge matthewhartstonge

👨‍💻
Engineering
View GitHub Profile
@matthewhartstonge
matthewhartstonge / mutation-observer.js
Last active November 11, 2024 10:01
glimmer/ember-modifier DOM observer
import Modifier from 'ember-modifier';
import { registerDestructor } from '@ember/destroyable';
import { assert } from '@ember/debug';
/**
* @modifier mutation-observer
*
* This Ember modifier uses the MutationObserver API to observe changes in the
* DOM of a given element. It initializes a MutationObserver, attaches it to
* the provided DOM element, and invokes a callback whenever a mutation is detected.
@matthewhartstonge
matthewhartstonge / http-client.dart
Created August 22, 2021 11:46
Shows the difference in boilerplate between Dart's stdlib HttpClient and package 'http/http.dart'
import 'dart:convert';
import 'dart:io';
// httpGet YOLO's a GET request to the given uri.
// Explosions may vary.
Future<dynamic> httpGet(String uri) {
return HttpClient(context: SecurityContext.defaultContext)
.getUrl(Uri.parse(uri))
.then((HttpClientRequest request) {
// You can also do this simply as a string 'context-type' without the imported constant.
@matthewhartstonge
matthewhartstonge / class-99-bottles-of-beer.dart
Last active August 22, 2021 07:59
Provides a functional and class based Dart solution for https://www.99-bottles-of-beer.net/
library ninetyninebottlesofbeer;
class Song {
// in Dart, underscore denotes private variables.
// Private variables are scoped to a library, so you can still access privates
// within a given file/library from other classes/functions.
// Note the above declared library name to limit the scope..
int _numBeers;
// The number of bottles of beers to sing from.
int bottlesOfBeer;
@matthewhartstonge
matthewhartstonge / configGitforGpg.bat
Created May 30, 2018 09:11
Config git for WinGPG
REM If you haven't globally set up git, ensure your git user.email is the same as the email used for your signing key.
REM git config --global user.name My Name
REM git config --global user.email [email protected]
git config --global user.signingkey Y0UR51GN1NGK3Y
git config --global commit.gpgsign true
git config --global gpg.program "C:\Program Files (x86)\GnuPG\bin\gpg.exe"
@matthewhartstonge
matthewhartstonge / release.ps1
Last active October 13, 2017 06:35
Cross-compile and package Go applications via Windows
# Enables simple cross-compilation and packaging of Go applications via Windows.
#
# Author: Matthew Hartstonge
# Written: 2017-10-12
# Creates binaries packaged and ready to go in a distibution folder
function main() {
$operatingSystems = ("windows", "darwin", "linux", "openbsd", "freebsd", "solaris")
$architechtures = ("386", "amd64")
@matthewhartstonge
matthewhartstonge / httpstatus.proto
Last active May 28, 2021 08:58
HTTP Status Codes as protobuf/gRPC enums
// HTTPStatusCode provides all the known HTTP status codes. Since these codes
// are well known, it makes sense to use them as an easy way to detect, over
// the wire, if a message has been malformed, errors have happened or processed
// correctly.
enum StatusCode {
StatusCode_UNSPECIFIED = 0;
StatusCode_CONTINUE = 100;
StatusCode_SWITCHING_PROTOCOLS = 101;
StatusCode_PROCESSING = 102;
@matthewhartstonge
matthewhartstonge / timezones.proto
Created July 14, 2017 12:43
timezones as protobuf/gRPC enums
syntax = "proto3";
package tz;
enum TimeZone {
Utc0000 = 0; // (UTC+-0:00) Coordinated Universal Time.
UtcMinus1200InternationalDateLineWest = 1; // (UTC-12:00) International Date Line West
UtcMinus1100MidwayIsland_Samoa = 2; // (UTC-11:00) Midway Island, Samoa
UtcMinus1000Hawaii = 3; // (UTC-10:00) Hawaii
UtcMinus0900Alaska = 4; // (UTC-09:00) Alaska
UtcMinus0800PacificTime = 5; // (UTC-08:00) Pacific Time (US & Canada)
@matthewhartstonge
matthewhartstonge / forceMongoMaster.js
Last active April 9, 2017 22:59
Start Mongo Replicaset up again after hard power off or restarting all hosts or containers
/**
* This script forces the first node in the config list to be master
*/
cfg = rs.conf()
cfg.members[0].priority = 1
cfg.members[1].priority = 0.5
cfg.members[2].priority = 0.5
rs.reconfig(cfg, {force: true})
@matthewhartstonge
matthewhartstonge / install-docker.sh
Last active March 20, 2020 08:35
Ubuntu 14.04LTS Docker Installation Script
#!/usr/bin/env bash
#===============================================================================
# Ubuntu 14.04LTS Docker Installation Script
#===============================================================================
# Maintainer: Matt Hartstonge <[email protected]>
# Description:
# Checks that your kernel version is up to scratch, otherwise prints errors.
# If Kernel is all good, will go ahead and do an automated install.
#
#-------------------------------------------------------------------------------
@matthewhartstonge
matthewhartstonge / bootstrap-nav-profile-pic.css
Last active January 31, 2021 22:16
Bootstrap 3 Navbar Profile CSS with HTML Example
/* Bootstrap 3 Navbar Profile Picture CSS
*
* The CSS for profile pictures in the navbar has always annoyed me,
* so here's my fix that appears to have the least hoops.
*
* Production use:
* >Add a div with the specified class.
* >Using JS, change the profile picture CSS URL as needed.
*
* HTML example: