Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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 / 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 / ring-integers.ts
Last active December 16, 2025 15:50
Class for residue rings
class MathUtils {
static mod(x: number, n: number): number {
return ((x % n) + n) % n
}
static gcd(a: number, b: number) {
while (b !== 0) {
;[a, b] = [b, a % b]
}
return Math.abs(a)
@ScriptRaccoon
ScriptRaccoon / triggers.sql
Created March 5, 2026 21:06
examples of sql triggers (SQLite)
-- users
CREATE TABLE IF NOT EXISTS users (
id INTEGER PRIMARY KEY,
username TEXT NOT NULL UNIQUE,
password_hash TEXT NOT NULL,
role TEXT NOT NULL DEFAULT 'user'
CHECK (role IN ('user', 'moderator', 'admin')),
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP,
last_login_at TIMESTAMP,