Skip to content

Instantly share code, notes, and snippets.

@tspng
tspng / .iterm-colours.zsh
Created January 31, 2024 08:44 — forked from aclarknexient/.iterm-colours.zsh
Set iTerm2 tab colours based on the command you are running
# A dotfile to turn iTerm2 tabs a different colour based on the command glob.
# Useful for marking different environments in different colours.
# Cargo-culted from multiple sources, apologies for not fully acknowledging them :(
# Edit the line that reads "if [[ "$1" =~ "^(login-helper) " ]]; then" and replace
# "login-helper" with whatever command you use to authenticate. Then modify the case
# statement to match your auth command's arguments. For example: you may use a script
# called "authsaml" to authenticate, and its arguments are dev, test, preprd, and prd.
# Change the colour function you call if you want to change tab colours.
@tspng
tspng / bookmarklet.js
Created January 14, 2024 14:10
Map Genie | Baldur's Gate 3 Map | My Categories - https://mapgenie.io/baldurs-gate-3/maps/baldurs-gate
javascript:(function() { const MY_CATEGORIES = ['AREA', 'WAYPOINT', 'UNIQUE ARMOR', 'UNIQUE WEAPON', 'SIDE QUEST']; document.querySelectorAll('#categories .category-item').forEach(e => { e.classList.contains('category-visible') && e.click(); MY_CATEGORIES.includes(e.querySelector('span[class=\"title\"]').innerText) && e.click(); }); })();
@tspng
tspng / End G-Code
Created December 21, 2023 22:08
Creality Ender-3 S1 Pro - Cura Slicer Settings
G91 ;Relative positioning
G1 E-2 F2700 ;Retract a bit
G1 E-2 Z0.2 F2400 ;Retract and raise Z
G1 X5 Y5 F3000 ;Wipe out
G1 Z10 ;Raise Z more
G90 ;Absolute positioning
G1 X0 Y{machine_depth} ;Present print
M106 S0 ;Turn-off fan
M104 S0 ;Turn-off hotend
@tspng
tspng / iTermColorsToTerminalColors.swift
Created November 26, 2023 09:17
Convert iTerm2 color scheme to Terminal.app color scheme (Swift 5 Compatible)
#!/usr/bin/xcrun swift
//
// Copyright © 2016 Leon Breedt
// Ported to Swift 5 by Pablo Morelli 2019
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
@tspng
tspng / .gitconfig
Created March 3, 2022 16:03
My .gitconfig
# This is Git's per-user configuration file.
[push]
default = simple
[user]
name = tspng
email = tspng@socket.ch
[core]
excludesfile = /Users/tspng/.gitignore_global
[http]
# allow large deltas to be pushed
@tspng
tspng / testcase.py
Created July 27, 2021 10:40
SQLAlchemy Many-to-One delete with backref testcase
import unittest
from sqlalchemy import Column, Integer, ForeignKey, create_engine, event
from sqlalchemy.orm import backref, relationship, sessionmaker
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.exc import IntegrityError
from sqlalchemy.engine import Engine
Base = declarative_base()
engine = create_engine('sqlite://')
@tspng
tspng / models.py
Last active July 26, 2021 14:10
SQLAlchemy Many-to-One relationship and cascade example
class Image(db.Model):
id = db.Column(db.Integer, primary_key=True)
url = db.Column(db.String(255))
class ThingWithImage(db.Model):
id = db.Column(db.Integer, primary_key=True)
image_id = db.Column(db.Integer, db.ForeignKey("image.id"))
image = db.relationship("Image", foreign_keys=[image_id])
@tspng
tspng / models.py
Last active July 21, 2021 10:53
SQLAlchemy custom query property problem
class _ForUserQuery(BaseQuery):
def _get_client_user_query(self):
raise NotImplementedError
def _get_pk_field(self):
raise NotImplementedError
def for_user(self, user):
query = self._get_client_user_query()
if not user.is_admin:
@tspng
tspng / pre-commit
Last active September 13, 2020 15:59
git hooks & examples
#!/bin/sh
OC_CONFIG="EFI/OC/config.plist"
HIDDEN_VALUE="__GENERATE_YOUR_OWN__"
MODIFIED=0
hide_value() {
key=$1
found=`grep -A1 "<key>${key}</key>" ${OC_CONFIG} | grep ${HIDDEN_VALUE} | wc -l`
if [ $found -eq 0 ]; then
@tspng
tspng / conftest.py
Created December 17, 2019 14:21
Flask, Flask-Login, pytest example
import pytest
from backend import create_app
from backend.auth.models import User, Role
@pytest.fixture(scope="session")
def monkeypatch_session(request):
"""
Experimental session scoped monkeypatch fixture, see