Skip to content

Instantly share code, notes, and snippets.

@justecorruptio
justecorruptio / main2.py
Last active December 15, 2022 20:36
Advent of Code 2022 Day 15 Part2
from itertools import product
import re
fh = open('input', 'r')
lines = {}
for line in fh:
sx, sy, bx, by = map(int, re.findall('-?\d+', line))
d = abs(bx - sx) + abs(by - sy) + 1
for endpoints, mb, norm in [
@justecorruptio
justecorruptio / anki_def.js
Last active May 22, 2019 19:24
Definitions for anki cards
<div class="row">
{{Front}}
<span id="playa" class="hooks hooks-l">{{Playability}}</span>
<span id="number" class="hooks hooks-r hooks-u">{{Number}}</span>
</div>
<script>
function $$(id) { return document.getElementById(id); }
$$('playa').innerText |= 0;
@justecorruptio
justecorruptio / debugger.py
Created January 25, 2018 22:01
inline debugger
import cProfile, logging, cStringIO, pstats
prof = cProfile.Profile()
score_list = prof.runcall(model.score, scoring_data)
prof.create_stats()
stream = cStringIO.StringIO()
stats = pstats.Stats(prof, stream=stream)
stats.strip_dirs().sort_stats('time').print_stats(20)
#print stream.getvalue()
logging.getLogger().info(stream.getvalue())
@justecorruptio
justecorruptio / import_mem.py
Created September 29, 2017 18:24
Stupid Python import memory tester
import gc
import os
import sys
import time
import imp
import ihooks
__PID = os.getpid()
def rss():
#gc.collect()
@justecorruptio
justecorruptio / gif.py
Created June 8, 2017 09:44
gif encoder inspired by /DavidBuchanan314/gif-enc
from struct import pack
from random import sample
dist = lambda a, b: (a[0] - b[0]) ** 2 + (a[1] - b[1]) ** 2 + (a[2] - b[2]) ** 2
nn = lambda rgb, centers: min((dist(rgb, c), i) for i, c in enumerate(centers))[1]
class GIF(object):
def __init__(self, data, size):
self.size = size
self.data = data
@justecorruptio
justecorruptio / density.py
Last active October 21, 2016 07:56
Script to find the "densest" Pro Game
from multiprocessing.dummy import Pool
import os
import re
from subprocess import Popen, PIPE
from threading import RLock
DIR = 'go4go'
def parse(fn):
fh = open(fn, 'r')
@justecorruptio
justecorruptio / mysql_unicode_regex.py
Last active February 21, 2020 09:51
Generate a regex to detect unicode blocks in mysql.
#!/usr/bin/python
# -*- coding: utf-8 -*-
start, end = u'가힝' # Korean
#start, end = u'あゟ' # Japanese
def esc(c):
if c in '[]\\\'\"':
return '\\' + c
return c
@justecorruptio
justecorruptio / eb.py
Created October 24, 2015 11:42
EB Logo in python!
exec'i=0;A=.9987;R=range;C=[ord(x)-1\
12for x in"qppp~dp|zpy~pg~pczpadpdap\
|ap~dpzdpztpvupvjprkprppnqpnlpjmpjwp\
fxpfhpzdp~d"];D=lambda x,y:" E"[sum(\
(F4]-y)*(F7]-y)<0and F5]-x>(F5]-F8])\
*(F4]-y)/(F4]-F7])for j in R(22))&1]\
\nwhile 1:\n r=2-i/140%2\n for j in \
R(24):F0],Fr]=F0]*A-Fr]/20,F0]/20+Fr\
]*A\n Z="\\n".join("".join(D(x*.4-20\
,y*.91-20)for x in R(99))for y in R(\
@justecorruptio
justecorruptio / eb.c
Last active October 23, 2015 11:15
EB Logo
float*F,S=20,C[72]={1},A=.9987,b,d,
x,y;r,i,j;main(s){for(j=23;j--;F[5]
="DZ^^ZDAADDTUJKPQLMWXHDD"[j]-80)4[
F=C+j*3]="^[YGCAD[^ZZVVRRNNJJFFZ^"[
j]-80;for(;puts("\e[2J");usleep(99*
99)){for(j=24;j--;F[r]=y)y=2[F=C+j*
3]/S+A*F[r=++i/4800%2],F[2]=A*F[2]-
F[r]/S;for(y=-S;y<S;y+=.9)for(x=-S,
printf("\e[38;5;%d66m\n",C[2]<0);x<
S;x+=.4,putchar("E "[s%2]))for(s=j=
@justecorruptio
justecorruptio / synth.pl
Created September 29, 2014 05:32
Perl Synthsizer
$SPS = 16000;
$PI = 3.14159265359;
$PITCH_ROLL = 1;
$BPM = 170;
%FREQS = (
A => 440.000,
B => 493.883,
C => 261.626,