Skip to content

Instantly share code, notes, and snippets.

View martinpi's full-sized avatar

Martin Pichlmair martinpi

View GitHub Profile
@martinpi
martinpi / readme.txt
Created August 30, 2023 08:36
EYE EYE EYE (PuzzleScript Script)
Play this game by pasting the script in http://www.puzzlescript.net/editor.html
@martinpi
martinpi / usePersistentState.ts
Created August 25, 2023 08:16
A persistent React hook that supports update functions. Couldn't find any on the interwebs so I had to roll my own.
import { useEffect, useRef, useState } from 'react';
// This hook receives three parameters:
// storageKey: This is the name of our storage that gets used when we retrieve/save our persistent data.
// ttl (seconds): How long it should be kept in browser storage
// initialState: This is our default value, but only if the store doesn't exist, otherwise it gets overwritten by the store.
// Example:
// Store a state that can be any or null and keep it cached for 15 minutes.
// [state, setState] = usePersistentState<any | null>("project.key", 15 * 60, null);
@martinpi
martinpi / readme.txt
Created September 1, 2022 10:43
constellation z (PuzzleScript Script)
Play this game by pasting the script in http://www.puzzlescript.net/editor.html
@martinpi
martinpi / clean.py
Created January 17, 2022 16:17
A cleaning script for Gutenberg texts. Cleans a whole folder full of text files. Pretty rough around the edges but seems to work.
from gutenberg_cleaner import *
import getopt
import sys
import os
from pathlib import Path
argumentList = sys.argv[1:]
options = "hi:o:s"
long_options = ["help", "input", "output", "strip"]
@martinpi
martinpi / readme.txt
Created September 7, 2021 11:00
Lilifee (PuzzleScript Script)
Play this game by pasting the script in http://www.puzzlescript.net/editor.html
@martinpi
martinpi / readme.txt
Created September 7, 2021 10:54
Simple Block Pushing Game (PuzzleScript Script)
Play this game by pasting the script in http://www.puzzlescript.net/editor.html
@martinpi
martinpi / IncrementBuildNumber.cs
Created September 25, 2020 13:45
Automatically increment the iOS build number in Unity conforming to Apple's guidelines before every build. Be sure to drop into a folder name "Editor". Worked in autumn 2020.
using UnityEngine;
using UnityEditor.Build;
using UnityEditor.Build.Reporting;
using UnityEditor;
public class IncrementBuildNumber : IPreprocessBuildWithReport {
public int callbackOrder { get { return 0; } } // Part of the IPreprocessBuildWithReport interface
public void OnPreprocessBuild(BuildReport report) {
if (report.summary.platform == BuildTarget.iOS) {
@martinpi
martinpi / CorrectAspectRatio.cs
Created March 4, 2019 15:39
Use screen width instead of height as reference for scaling orthographic size of a Unity camera. Especially useful for supporting a wide range of mobile phones.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/* Camera usually uses screen height as their reference for orthographic size.
This script makes it scale with width instead.
*/
public class CorrectAspectRatio : MonoBehaviour {
@martinpi
martinpi / AutocompleteView.swift
Created November 5, 2018 13:41
An autocomplete popup for text entry. Ported to Swift from this example: https://github.com/danjonweb/NCRAutocompleteTextView
//
// AutocompleteView.swift
//
// Originally created by Daniel Weber on 9/28/14.
// Copyright (c) 2014 Null Creature. All rights reserved.
// Ported to Swift by Martin Pichlmair 2018
//
import Cocoa
@martinpi
martinpi / SyntaxHighlighter.swift
Created October 13, 2018 14:27
A simple Swift 4.0 class for syntax highlighting in an NSTextView
//
// SyntaxHighlighter.swift
// CardsCardsCards
//
// Created by Martin Pichlmair on 12/10/2018.
//
// Based on https://raw.githubusercontent.com/kuyawa/Macaw/master/Macaw/Macaw.swift
import Cocoa