Skip to content

Instantly share code, notes, and snippets.

View charles-l's full-sized avatar
👾
making games

Charles charles-l

👾
making games
View GitHub Profile
@charles-l
charles-l / jumpapp.py
Last active May 4, 2024 16:51
python port of jumpapp
#!/usr/bin/env python3
# depends on having `wmctrl`, `xdotool`, and `zenity` installed.
import argparse
import re
import subprocess
import os
import traceback
@charles-l
charles-l / collision.py
Last active April 1, 2024 21:35
Simple collisions for action games (raylib python). Blog post: https://c.har.li/e/2024/03/28/implementing-robust-2D-collision-resolution.html
# `pip install raylib` to get pyray
import pyray as rl
from dataclasses import dataclass
import random
from typing import Optional
SIZE = 32
def copy_rect(rect):
  1. Install gdb
  2. Install GDB PEDA
  3. Install nasm
  4. Create a makefile:
    %: %.asm
      nasm -f elf64 $< && ld -s -o $@ $@.o
    
    all: $(patsubst %.asm,%,$(wildcard *.asm))
@charles-l
charles-l / tailscale.tf
Last active April 30, 2023 20:44
terraform notes: provision a server with tailscale automatically
terraform {
required_providers {
tailscale = {
source = "tailscale/tailscale"
version = "0.13.7"
}
}
}
provider "tailscale" {
@charles-l
charles-l / sra.py
Last active March 31, 2023 15:10
writeup for the picoctf 2023 crypto challenge: SRA
'''
Script to solve SRA in picoCTF 2023
The challenge provides a broken version of RSA that gives the user the cipher text
and d (e^-1) for the private key. n is not given. Below is the original script
with some annotations I added.
from Crypto.Util.number import getPrime, inverse, bytes_to_long
from string import ascii_letters, digits
from random import choice
# Python implementation of the wordwrap algorithm from
# http://blogs.perl.org/users/damian_conway/2019/08/greed-is-good-balance-is-better-beauty-is-best.html
import math
import re
def cost(lines, width):
# NOTE: not skipping the last line in the uniformity cost since
# if there's no way of splitting in greedy_wrap, the last line ends up
# with everything on it.
@charles-l
charles-l / reactive.py
Created July 7, 2021 19:52
Reactive programming in python
from functools import wraps
from collections import defaultdict
from dataclasses import dataclass, field
from typing import Dict, List
import ast
import inspect
class StateFinder(ast.NodeVisitor):
def __init__(self, state_name):
self.state_name = state_name
@charles-l
charles-l / tailscaled
Last active October 3, 2023 11:19
tailscaled sysvinit script for devuan
#!/bin/sh
### BEGIN INIT INFO
# Provides: tailscale
# Required-Start: $local_fs $all $network
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop:
# Short-Description: Tailscale daemon
# Description: Runs the tailscale daemon.
### END INIT INFO
@charles-l
charles-l / stack_frame.py
Last active February 22, 2021 17:52
GDB command to visualize the raw memory for the current stack frame
class RawFrame(gdb.Command):
"""Dump the raw memory for the stack while visualizing a stack frame"""
def __init__ (self):
super().__init__('raw-frame', gdb.COMMAND_USER)
def invoke(self, arg, from_tty):
sp = gdb.selected_frame().read_register('rsp').cast(gdb.lookup_type('unsigned char').pointer())
bp = gdb.selected_frame().read_register('rbp').cast(gdb.lookup_type('unsigned char').pointer())
def hex_word(addr, length=8):
@charles-l
charles-l / save_page.py
Last active March 2, 2024 19:57
A python script to save the Firefox Reader view of a page with images. Kind of a personal archive.org tool but using zip and HTML files rather than WARC.
#!/usr/bin/env python3
from bs4 import BeautifulSoup
from readability import Document
import click
from click import echo
import requests
import slugify
import os