Skip to content

Instantly share code, notes, and snippets.

@joethephish
joethephish / PlatformFloat.cs
Created July 1, 2020 16:40
Class to wrap single tweakable float value for UI that depends on platform. Could be hacked/adapted for something other than input type/platform.
using System;
using UnityEngine;
/// <summary>
/// PlatformFloat is an easy way of providing platform-specific tweak values.
/// By default, it behaves exactly like a normal float, and is converted back and forth
/// from a normal float implicitly.
/// However, in the inspector its possible to use a dropdown to provide platform
/// specific values for desktop, gamepad and touch.
/// </summary>
@joethephish
joethephish / map.ink
Created May 24, 2020 14:53
Sorcery-style ink with MAP convention
-> locationA
// Maybe in locationA.ink?
== locationA ==
Hello, welcome to location A!
-
+ Look in the drawer! -> lookInDrawer
+ Don't bother -> locationAPart2
= lookInDrawer
@joethephish
joethephish / ts-check-bug-simpler.js
Last active December 19, 2019 15:18
Default param causes ts-check to fail
const Obj = {
x: 1,
f: (y = Obj.x) => {}
};
Obj.x; // No definition found for 'x'
@joethephish
joethephish / ExampleTextView.cs
Created November 22, 2018 13:17
Example of centre alignment using SLayout
public class ExampleTextView {
public bool alignCentre;
// ... various fields, grab the SLayout as "layout" ...
// populate this list
List<SLayout> _wordLayouts;
// Lays out the words and returns the size used.
@joethephish
joethephish / simple-ink-story.ink
Created July 14, 2018 13:55
Simple ink story example
LONDON, 1872
Residence of Monsieur Phileas Fogg.
-> london
=== london ===
Monsieur Phileas Fogg returned home early from the Reform Club, and in a new-fangled steam-carriage, besides!
"Passepartout," said he. "We are going around the world!"
+ "Around the world, Monsieur?"
@joethephish
joethephish / Exp_for_zooming.md
Last active March 12, 2018 01:36
Using Mathf.Exp for zooming

Using Exp for zooming

One of the things I’m happiest to have learned in the past few months is a great use for Log + Exp in games when zooming in and out.

You may have already know that linear speeds work horribly for zooming, e.g.:

void Update() {
    scale = scale + speed * Time.deltaTime;
}
@joethephish
joethephish / XKCD_Calendar_Facts.ink
Last active December 18, 2017 17:04
An implementation in ink of https://xkcd.com/1930/
Did you know that {something()} {happens()} {becauseOf()}? {apparently()}.
== function something ==
{~
- the {~fall|spring} equinox
- the {~winter|summer} {~solstice|olympics}
- the {~earliest|latest} {~sunrise|sunset}
- daylight {~saving|savings} time
- leap {~days|years}
@joethephish
joethephish / MiniList.cs
Last active January 11, 2018 10:29
MiniList<T> - a struct based IList to be used when you have a very small number of elements
using System;
using System.Collections;
using System.Collections.Generic;
/// <summary>
/// Similar to normal List<T> except that it's a struct, meaning a local instance doesn't allocate any memory
/// on the heap by default. It has enough capacity for 8 items, beyond which point it'll automatically allocate
/// a full list internally. Useful if you want to have a list with a small number of items, and you don't want
/// any churn in the heap as a result. It'll be a bit slower than a normal list or array though since it needs
/// to do at least one switch statement any time you access it. Although it'll upgrade itself to a full list
@joethephish
joethephish / gist:09d12d80bd0a98c16670
Created December 9, 2014 12:44
Thumbnail Jekyll plugin
# Generates a thumbnail image and returns its path, given a path to the full image.
# Hacked from various existing plugins, particularly:
# https://github.com/mrdanadams/jekyll-thumbnailer/blob/master/thumbnail.rb
# https://github.com/10io/jekyll-thumbnailify/blob/master/jekyll-thumbnailify.rb
#
# Doesn't require ImageMagick, and instead uses the Apple Developer tool sips, so
# only works when generated on a Mac. Could easily replace sips with ImageMagick again.
#
# Usage:
#
@joethephish
joethephish / Dangerous NSArray count
Created June 29, 2013 18:02
The dangers of using [NSArray count] in if statements! (because count is an NSUInteger)
NSArray *array = @[@"a", @"b"];
if( array.count - 3 >= 5 ) {
NSLog(@"Big!");
} else {
NSLog(@"Small!");
}
// --> Big!