Skip to content

Instantly share code, notes, and snippets.

Matthew Miner mminer

Block or report user

Report or block mminer

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
@mminer
mminer / VerticalCollapse.tsx
Created Jan 2, 2020
React component for expanding and collapsing container with dynamic height.
View VerticalCollapse.tsx
import React, {forwardRef, useImperativeHandle, useRef} from 'react';
interface Props {
children: React.ReactNode;
className?: string;
collapsedHeight: number;
isCollapsed: boolean;
transitionDuration?: string;
}
@mminer
mminer / testequality.sh
Created Dec 10, 2019
Basic Bash script to test equality of two inputs with coloured output.
View testequality.sh
#!/usr/bin/env bash
actual=$1
expected=$2
# https://stackoverflow.com/a/5947802
GREEN='\033[0;32m'
RED='\033[0;31m'
RESET='\033[0m' # No Color
@mminer
mminer / MultiReadHttpServletRequest.java
Created Aug 21, 2019
Servlet request wrapper that allows reading request body multiple times.
View MultiReadHttpServletRequest.java
package com.matthewminer;
import org.apache.commons.io.IOUtils;
import javax.servlet.ReadListener;
import javax.servlet.ServletInputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;
import java.io.ByteArrayInputStream;
import java.io.IOException;
@mminer
mminer / lruCache.ts
Created Jul 4, 2019
Simple least-recently inserted cache.
View lruCache.ts
export default class LeastRecentlyInsertedCache<T> implements Iterable<T> {
private maxSize: number;
// Set objects maintain insertion order, making them appropriate for keeping track of when values
// are added relative to each other.
private set = new Set<T>();
constructor(maxSize: number) {
this.maxSize = maxSize;
}
@mminer
mminer / basicAuthMiddleware.js
Created Dec 12, 2018
Express middleware for HTTP Basic Authentication.
View basicAuthMiddleware.js
function basicAuthMiddleware(request, response, next) {
const { authorization = '' } = request.headers;
const [, credentials] = authorization.split(' ');
const decoded = new Buffer(credentials || '', 'base64').toString();
const splitIndex = decoded.indexOf(':');
const username = decoded.substring(0, splitIndex);
const password = decoded.substring(splitIndex + 1);
// TODO: supply valid values for username and password
if (username !== USERNAME || password !== PASSWORD) {
@mminer
mminer / InactivityReset.js
Created Dec 11, 2018
React component that runs an action after no user activity is detected.
View InactivityReset.js
import PropTypes from 'prop-types';
import { Component } from 'react';
const eventListenerOptions = { capture: true, passive: true };
// Events that signify that the user is still active.
const eventNames = ['keydown', 'mousedown', 'touchstart'];
class InactivityReset extends Component {
constructor(props) {
@mminer
mminer / RelativeTime.js
Created Dec 11, 2018
React component that displays an auto-updating relative time.
View RelativeTime.js
import moment from 'moment';
import PropTypes from 'prop-types';
import { Component, createElement as h } from 'react';
class RelativeTime extends Component {
constructor(props) {
super(props);
this.intervalId = null;
this.state = { output: moment(props.time).fromNow() };
this.updateOutput = this.updateOutput.bind(this);
@mminer
mminer / SharedTexture.cpp
Created Dec 8, 2018
Gets a shared texture handle from an Unreal texture.
View SharedTexture.cpp
#include "SharedTexture.h"
FSharedTexture FSharedTexture::FromRenderTarget(const UTextureRenderTarget2D& RenderTarget)
{
const FTextureRHIRef TextureRHI = RenderTarget.Resource->TextureRHI;
if (TextureRHI == nullptr)
{
return {};
}
@mminer
mminer / restore-docker-volumes.sh
Created Nov 26, 2018
Restores Docker volumes from tar archives.
View restore-docker-volumes.sh
#!/usr/bin/env bash
usage() {
cat <<EOF
Usage: $0 VOLUME [VOLUME ...]
Restore Docker volumes from tar archives.
EOF
}
@mminer
mminer / backup-docker-volumes.sh
Last active Nov 26, 2018
Back up Docker volumes to tar archives.
View backup-docker-volumes.sh
#!/usr/bin/env bash
usage() {
cat <<EOF
Usage: $0 VOLUME [VOLUME ...]
Back up Docker volumes to tar archives.
EOF
}
You can’t perform that action at this time.