Skip to content

Instantly share code, notes, and snippets.

@obskyr
obskyr / loop_and_fade.py
Last active September 28, 2024 12:18
Loop a video game music file and fade it out, so that it may be listened to properly in music apps.
#!/usr/bin/env python3
"""Loop an audio file to a length that's pleasant to listen to and, fade it out
smoothly, and add trailing silence. Particularly useful to turn looping video
game music into versions that might be more friendly to music-listening apps.
"""
import math
import os
import re
@obskyr
obskyr / postfiles-date-image-fix.rb
Last active February 11, 2024 22:30
A workaround for the jekyll-postfiles bug that makes dates at the start of image filenames impossible.
# jekyll-postfiles is lovely, *but* it has a bug that prevents images named
# like posts from being copied. (Or rather, perhaps this is a problem with Jekyll.)
# https://github.com/nhoizey/jekyll-postfiles/issues/1
# This plugin excludes such files from Jekyll's processing, and manually copies
# them over to the _site/ directory. (You are also no longer required to
# manually exclude images from _posts/ or _drafts/ in the config.)
require 'cgi'
EXTENSIONS_NOT_TO_PROCESS = Set[
@obskyr
obskyr / audacity_chapters_to_ffmpeg_metadata.py
Created September 8, 2023 12:23
Convert chapters exported with “Export Labels…” in Audacity to an FFmpeg-compatible metadata text file.
#!/usr/bin/env python3
"""Turn an Audacity "Label Track.txt" into an FFmpeg metadata file."""
import os
import re
import sys
LABEL_LINE_RE = re.compile(r"^(?P<start>[0-9]+(?:.[0-9]+)?)\s+(?P<end>[0-9]+(?:.[0-9]+)?)\s+(?P<title>.*)$")
def to_ffmetadata(labels_s):
@obskyr
obskyr / X-MAS CTF 2020 – Ken Kutaragi's Secret Code.md
Created December 20, 2020 02:53
How to Reverse-Engineer a PS1 Game – X-MAS CTF 2020 Writeup

X-MAS CTF 2020 Writeup: Ken Kutaragi's Secret Code

Or, How to Reverse-Engineer a PS1 Game

X-MAS CTF 2020 was my first CTF – I do ROM hacking, fan translation, and hardware modding, but I haven't done much hacking related to modern systems, so I was a wee bit worried there wouldn't be many challenges suited to my skillset. Imagine my surprise and delight, then, when I saw the challenge Ken Kutaragi's Secret Code, which consists of a PlayStation executable! And wouldn't you know it? I've hacked away at quite a few PS1 games in my day! Not many people solved it, likely because it requires quite niche skills – so let me share those with you!


Identifying our goal

The challenge description is as follows.

@obskyr
obskyr / _Tales of Ar'Okés.md
Last active January 5, 2022 11:25
Use your arrow keys instead of a numpad in Tales of Maj'Eyal and other games where it's required!

Tales of Ar'Okés

Do you have a tenkeyless keyboard? Are you not stuck in the 1970s? Then finally, your prayers are answered. This handy script lets you use arrow keys in Tales of Maj'Eyal (and other grid-based numpad-controlled games) and still reliably walk diagonally!

How to use

  1. Install AutoHotKey, the scripting language (for Windows only)
  2. Click “Download ZIP” at the top right of this page, and extract arrow-keys-to-numpad.ahk to wherever you want it.
  3. Whenever you want to use it, simply double-click the script, and it will run in the background!
@obskyr
obskyr / ohmybaud.ino
Last active February 25, 2019 03:14
Test baud rates on Arduino compatibles – does your desired combination of clock frequency and baud rate work?
#include <math.h>
// Implements the "client" side of the testing protocol of ohmybaud.py.
#define SAFE_BAUD_RATE 9600
#define TEST_DURATION_TARGET 2.5
const uint32_t BAUD_RATES[] = {
2400,
4800,
@obskyr
obskyr / twittify.py
Last active June 29, 2018 02:26
Prepare lossless images (screenshots, for example) for being posted to Twitter, scaling them reasonably and making sure Twitter will keep them lossless.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import print_function
from __future__ import unicode_literals
"""Turn a lossless image into something in a resolution suitable for Twitter,
and turn down the opacity on a single pixel so Twitter won't convert it.
"""
@obskyr
obskyr / asmdependencies.cr
Last active March 16, 2018 02:12
Near-instant RGBDS assembly dependency generation / include scanning, for use with makefiles.
# Get all the dependencies of RGBDS assembly files recursively,
# and output them using Make dependency syntax.
def dependencies_in(asm_file_paths)
asm_file_paths = asm_file_paths.clone
dependencies = {} of String => Set(String)
asm_file_paths.each do |asm_file_path|
if !dependencies.has_key? asm_file_path
asm_dependencies, bin_dependencies = shallow_dependencies_of asm_file_path
@obskyr
obskyr / banksy.py
Last active March 9, 2018 13:51
A Python script to convert Game Boy memory addresses between absolute and banked forms.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Convert Game Boy addresses between absolute and banked forms.
from __future__ import print_function
from __future__ import unicode_literals
import sys
@obskyr
obskyr / stream_response.py
Last active October 18, 2024 13:18
How to stream a requests response as a file-like object.
# -*- coding: utf-8 -*-
import requests
from io import BytesIO, SEEK_SET, SEEK_END
class ResponseStream(object):
def __init__(self, request_iterator):
self._bytes = BytesIO()
self._iterator = request_iterator