Skip to content

Instantly share code, notes, and snippets.

View mminer's full-sized avatar

Matthew Miner mminer

View GitHub Profile
@mminer
mminer / Pathfinding.cs
Created March 19, 2021 04:51
A* pathfinding implementation.
using System;
using System.Linq;
using System.Collections.Generic;
public static class Pathfinding
{
/// <summary>
/// A* implementation. Finds a path from start to goal.
/// </summary>
/// <param name="start">Where to begin.</param>
@mminer
mminer / VerticallyFlipRenderTexture.cs
Created February 18, 2021 21:39
Unity function to vertically flip a render texture.
/// <summary>
/// Vertically flips a render texture in-place.
/// </summary>
/// <param name="target">Render texture to flip.</param>
public static void VerticallyFlipRenderTexture(RenderTexture target)
{
var temp = RenderTexture.GetTemporary(target.descriptor);
Graphics.Blit(target, temp, new Vector2(1, -1), new Vector2(0, 1));
Graphics.Blit(temp, target);
RenderTexture.ReleaseTemporary(temp);
@mminer
mminer / YouTubePlayerResponse.cs
Created January 28, 2021 00:58
YouTube video player for Unity.
using System;
using System.Text.RegularExpressions;
using UnityEngine;
/// <summary>
/// Holds the result of parsing the ytInitialPlayerResponse JSON from a YouTube page.
/// </summary>
/// <remarks>
/// This is an incomplete list of fields in ytInitialPlayerResponse.
/// The full object contains many more, but we only care about a few.
@mminer
mminer / KeepWindowsSessionAlive.ps1
Created October 2, 2020 00:08
PowerShell script to keep Windows session alive by repeatedly toggling numlock.
$wshell = New-Object -ComObject WScript.Shell
while ($true) {
Write-Output "$(Get-Date) Toggling numlock"
$whell.SendKeys('{NUMLOCK}')
Start-Sleep -Seconds 10
}
@mminer
mminer / convert_to_image_sequence.sh
Created August 10, 2020 03:39
Converts .mov files to image sequences using FFmpeg.
#!/usr/bin/env bash
for filename in "$@"; do
base=$(basename "$filename" .mov)
mkdir "$base"
ffmpeg -i "$filename" "$base/$base-%03d.png"
done
@mminer
mminer / get_minimal_paths.py
Created August 7, 2020 19:17
Gets the "minimal" paths that comprise a directory's contents while excluding a set of child paths.
def get_minimal_paths(root_directory, paths_to_exclude=None, paths_to_include=None):
"""
Gets the "minimal" paths that comprise a directory's contents while excluding a set of child paths.
For example, given this directory hierarchy:
C:/Engine
Binaries
Documentation
Plugins
@mminer
mminer / GetHost.cpp
Created July 21, 2020 23:02
Unreal Engine utility function to get the host's IP address.
// Include "Sockets" in the `PrivateDependencyModuleNames` list in the Build.cs file.
#include "SocketSubsystem.h"
FString GetHost()
{
bool bCanBindAll;
return ISocketSubsystem::Get(PLATFORM_SOCKETSUBSYSTEM)->GetLocalHostAddr(*GLog, bCanBindAll)->ToString(false);
}
@mminer
mminer / storageArray.ts
Created March 9, 2020 18:53
Utility class to read and write arrays in localStorage / sessionStorage.
class StorageArray {
private storage: Storage;
constructor(storage: Storage) {
this.storage = storage;
}
get(key: string): string[] | null {
const jsonString = this.storage.getItem(key);
@mminer
mminer / VerticalCollapse.tsx
Created January 2, 2020 19:05
React component for expanding and collapsing container with dynamic height.
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 December 10, 2019 18:04
Basic Bash script to test equality of two inputs with coloured output.
#!/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