Skip to content

Instantly share code, notes, and snippets.

@irwiss
irwiss / checkerboard.gdshader
Last active January 30, 2023 21:25
Godot shader for checkerboard pattern with rotation
shader_type canvas_item;
uniform float cells = 8.0; // how many cells in checkerboard pattern
uniform float angle: hint_range(0, 1.57079632679) = 0.0; // repeats every PI / 2
void vertex() { // rotate UVs by angle
UV *= mat2(vec2(cos(angle), -sin(angle)), vec2(sin(angle), cos(angle)));
}
void fragment() { // assign color by even/odd checkerboard pattern
@irwiss
irwiss / heap_permutations.gd
Last active January 13, 2023 16:09
Heap's permutations algorithm implemented in GDScript 2
extends Node # for ease of testing attach to a node
func swap_elements(x: Array, a: int, b: int):
var temp = x[a]
x[a] = x[b]
x[b] = temp
# https://en.wikipedia.org/wiki/Heap%27s_algorithm
func heap_permutations(x: Array) -> Array:
x = x.duplicate() # copy we original array isn't affected by swaps
@irwiss
irwiss / conditional_break.cs
Last active May 6, 2021 10:49
Faster conditional break, acts something like assert with automatic debugger homing
[System.Diagnostics.DebuggerHidden]
[System.Diagnostics.Conditional("DEBUG")]
public static void DebuggerBreakIf(bool condition)
{
if (condition)
{
System.Diagnostics.Debugger.Break();
}
}
@irwiss
irwiss / pipe_to_discord_webhook.sh
Last active May 22, 2022 08:20
Shell script to pipe stdin to discord webhook
#!/bin/bash
# pipe_stdin_to_discord_webhook.sh
# This script triggers discord webhook with input from stdin line-by-line
set -eu
# discord webhook url, pay attention to add ?wait=true at the end
WEBHOOK_URL='https://discordapp.com/api/webhooks/[WEBHOOKID]/[WEBHOOKID]?wait=true'
# grep filter per line, lines not matching won't be sent
@irwiss
irwiss / phpbb_mysql_to_postgres.load
Created October 24, 2018 10:40
Pgloader script to convert a phpbb mysql database to postgres
/*
* Pgloader script to convert a phpbb mysql database to postgres.
* Get a fresh postgres database and make a basic phpbb install to create schema.
* Phpbb wants to keep mysql-ism of boolean columns being int types.
* Probably worth tidying up stuff like FTS indices, **_track tables before.
* Assuming this script is called phpbb_mysql_to_postgres.load, database and
* schema names are "phpbb", run:
*
* docker run --network=with_access_to_both_containers \
* --rm \
@irwiss
irwiss / cf.ini
Last active June 7, 2018 16:40
Shell script for docker to receive wildcard certificates
# Cloudflare API credentials used by Certbot
# Should be sitting at /srv/certbot/cf.ini
dns_cloudflare_email = your cloudflare email goes here
dns_cloudflare_api_key = your cloudflare key goes here
@irwiss
irwiss / phpbb_mass_prune.php
Last active April 2, 2019 22:59
phpbb_mass_prune.php
phpbb user pruning tool fails to actually work at > 100 users to prune
even though it happily displays a form with about 30000 checkboxes and
usernames to choose.
Slightly modified - this script wants user_ids_to_delete.txt near it,
with numerical user ids, one id per line.
Bulk delete all users with 0 posts in prevoius revision
This needs a *lot* of memory (or swapfile) if you have a lot of users
@irwiss
irwiss / HelpBoxDrawer.cs
Last active August 22, 2017 17:50
HelpBox field decorator for Unity3d
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
[CustomPropertyDrawer(typeof(HelpBoxAttribute))]
public class HelpBoxDrawer : DecoratorDrawer
{
public override float GetHeight()
@irwiss
irwiss / EnableTls12.cs
Created June 7, 2016 09:40
A helper method to detect and enable Tls1.2 on applications running on .NET4.0 with .NET 4.5 installed
/// <summary>Enable TLS1.2 for .NET 4.0 app if .NET 4.5 is installed.</summary>
/// <seealso cref="http://stackoverflow.com/questions/28286086/default-securityprotocol-in-net-4-5"/>
/// <returns>True if .NET 4.0 is installed and we enabled the protocol on SevicePointManager.</returns>
public static bool TryEnableTls12()
{
// detect .NET 4.5 or greater https://msdn.microsoft.com/en-us/library/hh925568
using (var rk = Microsoft.Win32.RegistryKey
.OpenBaseKey(Microsoft.Win32.RegistryHive.LocalMachine, Microsoft.Win32.RegistryView.Registry32)
.OpenSubKey("SOFTWARE\\Microsoft\\NET Framework Setup\\NDP\\v4\\Full\\"))
{