Skip to content

Instantly share code, notes, and snippets.

@mjstrasser
mjstrasser / README.md
Last active October 15, 2020 05:38
Run Seq with mkcert, NGINX SSL offloading in Docker Compose

What this does

Runs a single-user instance of Seq in Docker with NGINX offloading of a mkcert certificate, listening on port 45341. It also runs the Seq GELF listener in a third container.

Prerequisites

{
"name": "retry-axios",
"version": "1.0.0",
"description": "Retry function for axios promise-based HTTP client",
"scripts": {
"test": "jest --coverage"
},
"dependencies": {
"is-retry-allowed": "^1.1.0"
},
@mjstrasser
mjstrasser / StreamUtils.java
Last active June 5, 2018 04:13
Utilities for working with Java streams
package mjs.stream.utils;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
public class StreamUtils {
/**
* Converts a stream into an iterable for use by, e.g. Spring CrudRepository classes.
*/
@mjstrasser
mjstrasser / zipper.erl
Created March 19, 2017 01:21
Higher-order functions in practice from Functional Programming in Erlang MOOC
-module(zipper).
-compile(compile_all).
-include_lib("eunit/include/eunit.hrl").
%% Tail-recursive implementation of zip/2
%% that combines items into 2-tuples.
zip(Xs, Ys) -> lists:reverse(zip(Xs, Ys, [])).
% Stop when either list finishes.
zip([], _, Zs) -> Zs;
zip(_, [], Zs) -> Zs;
@mjstrasser
mjstrasser / index.erl
Created March 13, 2017 04:46
Index generator for week 2 assignment in Functional Programming in Erlang MOOC from University of Kent (futurelearn.com)
-module(index).
-export([get_file_contents/1,show_file_contents/1,
index_file/1, word_index/1]).
-include_lib("eunit/include/eunit.hrl").
%% Index the words in the specified file.
index_file(Filename) ->
word_index(get_file_contents(Filename)).
@mjstrasser
mjstrasser / keybase.md
Last active January 30, 2016 12:46
Keybase proof

Keybase proof

I hereby claim:

  • I am mjstrasser on github.
  • I am mjstrasser (https://keybase.io/mjstrasser) on keybase.
  • I have a public key whose fingerprint is F541 37DC 4A71 A203 BEE9 F12C A13D 44D8 2E90 4858

To claim this, I am signing this object:

@mjstrasser
mjstrasser / tunnels.rb
Last active August 29, 2015 14:05
Manage SSH tunnels to remote hosts.
require 'net/ssh/gateway'
module Net
module SSH
# A class that manages URLs, tunnelling them if necessary.
class Tunnels
HP = Struct.new(:host, :port) do
def to_s
@mjstrasser
mjstrasser / headers_proxy.rb
Last active August 29, 2015 14:05
Web proxy that injects HTTP headers for test purposes
# Logging class that logs nothing. The default is INFO logging to $stderr.
class NullLog < WEBrick::BasicLog
def log(level, data)
# Do nothing.
end
end
# Subclass of WEBrick::HTTPProxyServer that injects HTTP headers into the request.
#
# Specifying a RequestCallback proc does not work because the WEBrick::HTTPRequest object
@mjstrasser
mjstrasser / pimp_it_hard.rb
Created July 6, 2014 05:28
Pimp it hard: Ruby script to pummel http://pimpmylight.catchpole.net/ a number of times, using random colour choice and random delays between messages.
# Run Pimp My Light for a while
require 'httparty'
COLOURS = [:red, :orange, :green]
PML_URL = 'http://pimpmylight.catchpole.net/?update=%s'
TOTAL = ARGV.length > 0 ? ARGV[0].to_i : 5
COUNTS = { red: 0, orange: 0, green: 0, except: 0 }