Skip to content

Instantly share code, notes, and snippets.

@SonOfLilit
SonOfLilit / demux.py
Created October 30, 2024 16:49
Split text file by filename/path comments (e.g. for writing LLM outputs to disk)
import sys
import os
from typing import Dict
import re
def parse_files(content: str) -> Dict[str, str]:
"""Parse the input content into a dictionary of filepath -> content."""
files = {}
maybe_files = set()
current_file = None
@SonOfLilit
SonOfLilit / hiromi_mentorboy.py
Created January 23, 2023 19:27
Draft of Hiromi API: mentorbot
"""
- /room command handler
- /schedule command handler
- task - schedule
- weekly task - summary (w/ button handler)
- dashboard
- admin
"""
from django import models
@SonOfLilit
SonOfLilit / gpt_decoding_puzzle.md
Last active December 3, 2022 02:52
GPT-3 davinci-003 solving a problem with python and debugging its own code with guidance from a teacher, see comment for explanation
>>> # demonstration of how to solve an encoding puzzle:
>>> puzzle = "VGhlIHBhc3N3b3JkIGlzIGNvbXBvc2VkIG9mIHRoZSBmaXJzdCBsZXR0ZXIgb2YgZWFjaCB3b3JkIGluIHRoaXMgc2VudGVuY2UsIGluIG9yZGVyLCBhbGwgaW4gbG93ZXJjYXNl"
>>>
>>> # Step 1: Decode the puzzle
>>> puzzle_decoded = puzzle.decode('base64')
Traceback (most recent call last):
  File "passw.py", line 8, in <module>
    print(puzzle.decode('base64'))
LookupError: 'base64' is not a text encoding; use codecs.decode() to handle arbitrary codecs
@SonOfLilit
SonOfLilit / sequencer.py
Last active May 30, 2022 21:56
Official solution to refactoring challenge from Clean Code on Toilet #1: Naming Things.
# Sequencer is the music production term of art for what this does
class Sequencer:
def toggle_record(self, value):
self.is_recording = value
if not value:
for note in self.held_notes.values():
self.record_midi(midi.NoteOff(note.pitch, note.velocity))
self.held_notes = {}
def handle_note(self, note):
@SonOfLilit
SonOfLilit / player_recorder.py
Last active May 30, 2022 22:31
Refactoring challenge from Clean Code on Toilet #1: Naming Things.
# Fork and refactor before you look at the official solution[1] or other players' forks
# [1]: https://bit.ly/ccot1solution
class PlayerRecorder:
def user_clicked_piano_note(self, value):
self.engine.send_note(value)
if self.play and self.r:
if value[0] == ON:
self.temp[value[1]] = value
elif value[0] == OFF:
"""
Implementation of https://arxiv.org/pdf/1802.07068.pdf by Aur Saraf
"""
import random
def histogram(items):
counts = {}
for item in items:
if item not in counts:
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
### Keybase proof
I hereby claim:
* I am sonoflilit on github.
* I am sonoflilit (https://keybase.io/sonoflilit) on keybase.
* I have a public key ASD1Caun2jjDgw-sJMliMwtosIDQchNMBCzL9G8vUMI48go
To claim this, I am signing this object:
@SonOfLilit
SonOfLilit / bf.py
Created June 26, 2017 22:56
Live coded during my "Virtual Machines and Brainfuck" talk at PyConIL 2017
import sys
def parse_parens(code):
result = {}
stack = []
for i, c in enumerate(code):
if c == '[':
stack.append(i)
elif c == ']':
match = stack.pop()
@SonOfLilit
SonOfLilit / gcgid2unicode.csv
Created July 15, 2016 20:17
Extract a gcgid2unicode conversion table from IBM's cdctables.zip
AA010000 0625
AA010002 FE88
AA010006 F8FB
AA010009 0627
AA020000 0649
AA020002 FEF0
AA020009 0649
AA050000 064E
AA050004 FE77
AA050009 064E