Skip to content

Instantly share code, notes, and snippets.

View mminer's full-sized avatar

Matthew Miner mminer

View GitHub Profile
@mminer
mminer / cachedecorator.py
Created January 12, 2015 23:57
An example of a Python decorator to simplify caching a function's result.
"""An example of a cache decorator."""
import json
from functools import wraps
from redis import StrictRedis
redis = StrictRedis()
def cached(func):
@mminer
mminer / MyService.swift
Last active April 23, 2024 23:00
Components of XPC service.
import Foundation
class MyService: NSObject, MyServiceProtocol {
func upperCaseString(_ string: String, withReply reply: @escaping (String) -> Void) {
let response = string.uppercased()
reply(response)
}
}
@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 / Console.cs
Last active March 28, 2024 22:23
Unity script to display in-game debug console. Actively maintained version: https://github.com/mminer/consolation
// NOTE: For an actively-maintained version of this script, see https://github.com/mminer/consolation.
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// A console to display Unity's debug logs in-game.
/// </summary>
public class Console : MonoBehaviour
{
@mminer
mminer / eventManager.lua
Created March 8, 2024 18:00
Simple event manager for Lua.
local eventManager <const> = {}
function addEventListener(eventName, listener)
local eventListeners = eventManager[eventName]
if not eventListeners then
eventListeners = {}
eventManager[eventName] = eventListeners
end
@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 / Marquee.cs
Last active January 27, 2024 10:32
Simple Unity script to create a scrolling marquee.
using UnityEngine;
public class Marquee : MonoBehaviour
{
public string message = "Where we're going, we don't need roads.";
public float scrollSpeed = 50;
Rect messageRect;
void OnGUI ()
@mminer
mminer / DownloadProgressIndicatorDemo.swift
Last active November 3, 2023 08:44
Displays a progress indicator on a file in the Finder.
import Foundation
let progress = Progress(parent: nil, userInfo: [
.fileOperationKindKey: Progress.FileOperationKind.downloading,
.fileURLKey: URL(fileURLWithPath: "/Users/mminer/Downloads/somefile.zip"),
])
progress.isCancellable = true
progress.isPausable = false
progress.kind = .file
@mminer
mminer / SharedTexture.cpp
Created December 8, 2018 00:14
Gets a shared texture handle from an Unreal texture.
#include "SharedTexture.h"
FSharedTexture FSharedTexture::FromRenderTarget(const UTextureRenderTarget2D& RenderTarget)
{
const FTextureRHIRef TextureRHI = RenderTarget.Resource->TextureRHI;
if (TextureRHI == nullptr)
{
return {};
}
@mminer
mminer / jsonhandler.py
Created April 26, 2013 02:36
A JSON request handler for Tornado.
import json
import tornado.web
class JsonHandler(BaseHandler):
"""Request handler where requests and responses speak JSON."""
def prepare(self):
# Incorporate request JSON into arguments dictionary.
if self.request.body:
try: