Skip to content

Instantly share code, notes, and snippets.

Avatar

Matthew Miner mminer

View GitHub Profile
@mminer
mminer / Pathfinding.cs
Created Mar 19, 2021
A* pathfinding implementation.
View Pathfinding.cs
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 Feb 18, 2021
Unity function to vertically flip a render texture.
View VerticallyFlipRenderTexture.cs
/// <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 Jan 28, 2021
YouTube video player for Unity.
View YouTubePlayerResponse.cs
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 Oct 2, 2020
PowerShell script to keep Windows session alive by repeatedly toggling numlock.
View KeepWindowsSessionAlive.ps1
$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 Aug 10, 2020
Converts .mov files to image sequences using FFmpeg.
View convert_to_image_sequence.sh
#!/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 Aug 7, 2020
Gets the "minimal" paths that comprise a directory's contents while excluding a set of child paths.
View get_minimal_paths.py
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 Jul 21, 2020
Unreal Engine utility function to get the host's IP address.
View GetHost.cpp
// 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 Mar 9, 2020
Utility class to read and write arrays in localStorage / sessionStorage.
View storageArray.ts
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 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