Skip to content

Instantly share code, notes, and snippets.

View Gatada's full-sized avatar
💭
Working offline on a physical tabletop game

Johan H. W. Basberg Gatada

💭
Working offline on a physical tabletop game
View GitHub Profile
@Gatada
Gatada / state.gd
Last active October 4, 2022 12:19
A simple Label @tool with a highlight state
@tool
extends Control
## Highlight Label Tool
##
## A simple node with a highlight state. Highlighting the node will change the background color.
## The highlight state will reset after `state_duration` seconds (to ensure the highlight is seen).
##
## The scene consists of:
##
@Gatada
Gatada / WeakenedArray.swift
Last active February 26, 2020 13:32
Trying to implement a reapable array with weak references.
import Foundation
class Weak<T: AnyObject> {
weak var value: T?
init (value: T) {
self.value = value
}
}
@Gatada
Gatada / keybase.md
Created September 21, 2018 12:59
This is the identify verification required by Keybase. Look me up!

Keybase proof

I hereby claim:

  • I am gatada on github.
  • I am johanhwb (https://keybase.io/johanhwb) on keybase.
  • I have a public key ASCacjLLyHyxKcFR8KEAMqLOq_Z7KNFKf7RUf_o9lSRcFwo

To claim this, I am signing this object:

@Gatada
Gatada / UIColor.swift
Last active August 24, 2018 15:00
A extension for UIColor that creates a UIColor from a hex code.
import UIKit
public extension UIColor {
/// Initialize a color from a hex value. Optionally include an alpha value (default is 1).
///
/// - Parameters:
/// - hex: The integer that will be resolved to the red, green and blue component.
/// - alpha: The alpha value of the color.
public convenience init?(hex: UInt, alpha: CGFloat = 1) {
class AppDelegate: UIResponder, UIApplicationDelegate {
public enum Shared {
static public var Heartbeat = HeartbeatManager()
}
}
public class HeartbeatManager {
@Gatada
Gatada / Log.swift
Last active April 26, 2018 08:55
A useful printing implementation that requires no flags, yet gets removed during compiler optimization for a release build.
import UIKit
import PlaygroundSupport
/// Prints the `items` with an optional separator and terminator.
/// The benefit of this approach is that all calls will be entirely removed during compiler optimization for release builds.
/// Additionally you can provide an optional closure to perform text processing. The processed string gets printed either before or immediately after `message` depending on the returned boolean.
///
/// - Parameters:
/// - items: Zero or more items to print.
/// - separator: An optional string to print between each item; default is a single whitespace.
@Gatada
Gatada / SingleInstance.swift
Last active April 24, 2018 14:31
How to make a singleton fully testable (resettable)?
import UIKit
import PlaygroundSupport
class SingleInstance {
#if TESTING
open static var shared = SingleInstance()
static func reset() {
SingleInstance.shared = SingleInstance()
}