Skip to content

Instantly share code, notes, and snippets.

@ScriptRaccoon
ScriptRaccoon / script.ts
Last active December 1, 2025 18:29
Determines which Player wins in Treblecross (TypeScript)
// return true iff player 1 has a winning strategy for n-size treblecross
// https://en.wikipedia.org/wiki/Treblecross
function treblecross_win_optimized(n: number): boolean {
if (n === 0 || n === 2) return false
if (n === 1) return true
if (n >= 32) throw new Error("We use bitmasks, only n <= 32 allowed.") // FIXME
const cache: Map<number, boolean> = new Map()
let board = 0
@ScriptRaccoon
ScriptRaccoon / secure.ts
Created November 11, 2025 16:47
Proxy of an object that prevents the access to selected properties
/**
* Creates a proxy of an object that prevents the access to selected properties
*/
function secure<T extends Record<PropertyKey, unknown>, K extends readonly (keyof T)[]>(
obj: T,
fields: K,
): Omit<T, K[number]> {
return new Proxy(obj, {
get(target: T, property: PropertyKey, receiver: any) {
if (fields.includes(property)) {
@ScriptRaccoon
ScriptRaccoon / lastfm-script.js
Created November 7, 2025 13:46
Script to remove all liked songs on last.fm
/**
* Use this script on https://www.last.fm/user/{your_user_name}/loved
* to remove all your loved songs on last.fm.
*/
function click_unlike_button() {
const button = document.querySelector('.chartlist-love-button')
if (!button) {
const next_page_link = document.querySelector('.pagination-next a')
if (!next_page_link) {
@ScriptRaccoon
ScriptRaccoon / pwgen
Created March 27, 2025 09:44
Password generator CLI (with Python)
#!/usr/bin/env python3
# This Python script can quickly generate passwords.
# Simply type 'pwgen' into the terminal.
# Options:
# -l or --length to set the length. Default is 20.
# -a or --alphanumeric to generate an alphanumeric password: no special characters.
import argparse
import random
@ScriptRaccoon
ScriptRaccoon / index.ts
Last active March 13, 2025 13:42
zod example
import { z } from "zod"
// USER
const userNameSchema = z
.string({
invalid_type_error: "Username must be a string",
required_error: "Username is required",
})
.min(2, { message: "Username must be at least 2 characters long" })
@ScriptRaccoon
ScriptRaccoon / dailybot.gs
Last active January 25, 2025 18:20
Script for a slack app sending a daily bot message thatannounces the Daily animator
const scriptProperties = PropertiesService.getScriptProperties()
const WEBHOOK_URL = scriptProperties.getProperty('WEBHOOK_URL')
const COLLEAGUES = [
{
name: 'Hanna',
slackID: '...',
},
{
name: 'Martin',
@ScriptRaccoon
ScriptRaccoon / rubik.py
Last active September 29, 2024 20:18
Verifies that 1260 is the highest possible order of an element in the 3x3 Rubik's cube group
"""
This module verifies that 1260 is the highest possible order of an element in the 3x3 Rubik's cube group.
This is only an upper bound but it turns out that it can also be achieved, so this estimate is precise.
The approach is loosely based on the answer by 'jmerry' at https://math.stackexchange.com/questions/2392906/
"""
from functools import lru_cache
import math
@ScriptRaccoon
ScriptRaccoon / subtitle-generator.py
Created April 27, 2024 21:12
script generating numbered timestamps based on clicks
import time
# This script generates numbered timestamps based on clicks
# This has been used for example in https://youtu.be/4t61xW8QIEg
def main():
print("Click whenever you want to mark a timestamp")
print("Press 'q' to quit and generate timestamps\n")
@ScriptRaccoon
ScriptRaccoon / script.gs
Created February 12, 2024 22:15
Google Apps Script to sync from Spreadsheet to Calendar
/*
This script needs to be bound with a Google Spreadsheet.
It needs to have a header row of the form: title | start | end | description
The script then generates calendar entries for every row below.
For example, the sheet could have the following entries (displayed in csv format):
Title,Start,End,Description
Test 1,27.02.2024 11:00:00,27.02.2024 15:00:00,Hallo 1
Test 2,28.02.2024 15:00:00,28.02.2024 17:30:00,Hallo 2
@ScriptRaccoon
ScriptRaccoon / script.js
Last active January 27, 2024 12:00
Add MIT licenses to all your repos
const TOKEN = "...." // your github access token
const owner = "..." // your github name
const blackList = [] // the names of the repos you don't want to process
const { Octokit } = require("@octokit/rest") // install this first
const octokit = new Octokit({ auth: TOKEN })
const fs = require("fs")