Skip to content

Instantly share code, notes, and snippets.

@xphere
xphere / partial-tboi-repentance-map.mermaid.dont-show
Last active April 22, 2023 08:13
Mermaid flowchart showing dependencies between all 637 The Binding of Isaac Repentance achievements. Unfortunatelly, doesn't load due to Mermaid size limitations
flowchart LR
GAME_TBOI("🕹️The Binding of Isaac") --> GAME_AFTERBIRTH("🕹️Afterbirth") --> GAME_AFTERBIRTH_PLUS("🕹️Afterbirth+") --> GAME_REPENTANCE("🕹️Repentance")
GAME_AFTERBIRTH --> MODE_GREED("💰Greed Mode")
GAME_AFTERBIRTH_PLUS --> |500 to Greed Donation Machine| MODE_GREEDIER("💰Greedier Mode")
GAME_TBOI --> CHAR_ISAAC("😭Isaac")
GAME_TBOI --> |7 Red Hearts| ACHIEVEMENT_1("✅ Magdalene (#1)") --> CHAR_MAGGIE("😭Maggie")
GAME_TBOI --> |55 Coins| ACHIEVEMENT_2("✅ Cain (#2)") --> CHAR_CAIN("😭Cain")
GAME_TBOI & BOSS_SATAN --> |Defeat Satan| ACHIEVEMENT_3("✅ Judas (#3)") --> CHAR_JUDAS("😭Judas")
@xphere
xphere / task.gd
Created March 15, 2023 19:58
Task.WhenAll and Task.WhenAny Godot 4.0 GDScript 2.0 implementation
class_name Task
# Call all tasks and wait for them to complete, even async ones
static func WhenAll(tasks: Array[Callable]) -> void:
var awaiter := _Awaiter.new()
await awaiter.wait(tasks, tasks.size())
# Call all tasks and wait for at least one to complete, even async ones
@xphere
xphere / git-default.sh
Last active November 16, 2021 08:39
How to call git with default configuration?
#!/bin/bash
# git gets configuration from three main places: current repository, current user, system-wide
# Those can be skipped by changing the following environment variables
# PREFIX= HOME= GIT_CONFIG_NOSYSTEM=
# NOTE: Current repository can't be overriden
# But git requires at least the author and committer name/email
# Those must be setup with the following environment variables
# GIT_AUTHOR_NAME= GIT_AUTHOR_EMAIL= GIT_COMMITTER_NAME= GIT_COMMITTER_EMAIL=
# Thus the call will be something like this
@xphere
xphere / Makefile
Last active February 18, 2021 09:07
Show all console color combinations
all:
$(call colors)
define colors
$(foreach in,$(shell seq 0 9),$(foreach bg,$(shell seq 30 39),@echo -e $(foreach fg,$(shell seq 40 49),"\033[$(in);$(bg);$(fg)m $(in);$(bg);$(fg) \033[0m")
))
endef
@xphere
xphere / PosterizedViewport.gd
Created July 30, 2020 13:37
Generates a gradient mapping to keep your game within a given palette colors.
extends ViewportContainer
func _ready() -> void:
# Define your palette colors
var colors: = [
Color("#171219"),
Color("#251d35"),
Color("#2e2842"),
Color("#3e365d"),
@xphere
xphere / SpeedTrapListener.php
Created May 21, 2020 13:20
Simplest PhpUnit extension reporting slow tests
<?php
declare(strict_types=1);
namespace Test\SpeedTrapListener;
use PHPUnit\Runner\AfterLastTestHook;
use PHPUnit\Runner\AfterTestHook;
use PHPUnit\Runner\BeforeTestHook;
@xphere
xphere / .gitconfig
Last active March 24, 2022 07:45
Allows to store/recover state of current git branch. Like stash but keeping index and branch tracking.
[alias]
index-is-clean = !git diff-index --cached --quiet HEAD
recover = !f() { local REV=$(git rev); [ "$(git commit-message)" = ::modified ] && git reset -q HEAD~; [ "$(git commit-message)" = ::indexed ] && git reset -q --soft HEAD~; [ $(git rev) = $REV ] || echo 'Current state recovered'; }; f
rev = rev-parse HEAD
store = !f() { local REV="$(git rev)"; git index-is-clean || git unsafe-commit '::indexed'; git working-is-clean || $(git add -A && git unsafe-commit '::modified'); [ "$(git rev)" = "$REV" ] || echo 'Current state stored'; }; f
@xphere
xphere / DontWriteToPublicPropertiesRule.php
Created June 16, 2019 19:40
A PhpStan rule to ban changes on public members outside a class.
<?php declare(strict_types=1);
use PhpParser\Node;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\Assign;
use PhpParser\Node\Expr\AssignOp;
use PhpParser\Node\Expr\PropertyFetch;
use PhpParser\Node\Expr\StaticPropertyFetch;
use PhpParser\Node\Identifier;
use PHPStan\Analyser\Scope;
@xphere
xphere / plugin.gd
Last active July 17, 2023 20:44
Empty template for a Godot 4.1 plugin in GDScript
@tool
extends EditorPlugin
func _enter_tree() -> void:
pass
func _exit_tree() -> void:
pass
func _apply_changes() -> void:
@xphere
xphere / Random.gd
Created October 20, 2018 14:44
Random object, encapsulating seed and algorithm, for GDScript Godot 3.1
extends Reference
class_name Random
"""
Object constructor, requires a seed value to feed the PRNG.
You can use a const seed or an already randomized one. See randi()
"""
func _init(_seed: int) -> void:
set_seed(_seed)