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 / 2048.c
Created April 4, 2014 03:49
Tiny 2048 in C!
M[16],X=16,W,k;main(){T(system("stty cbreak")
);puts(W&1?"WIN":"LOSE");}K[]={2,3,1};s(f,d,i
,j,l,P){for(i=4;i--;)for(j=k=l=0;k<4;)j<4?P=M
[w(d,i,j++)],W|=P>>11,l*P&&(f?M[w(d,i,k)]=l<<
(l==P):0,k++),l=l?P?l-P?P:0:l:P:(f?M[w(d,i,k)
]=l:0,++k,W|=2*!l,l=0);}w(d,i,j){return d?w(d
-1,j,3-i):4*i+j;}T(i){for(i=X+rand()%X;M[i%X]
*i;i--);i?M[i%X]=2<<rand()%2:0;for(W=i=0;i<4;
)s(0,i++);for(i=X,puts("\e[2J\e[H");i--;i%4||
puts(""))printf(M[i]?"%4d|":" |",M[i]);W-2
@justecorruptio
justecorruptio / .vimrc
Last active January 19, 2022 19:49
vimrc
set nocompatible
set timeout timeoutlen=500 ttimeoutlen=0
syntax enable
filetype on
augroup filetypedetect
au! BufRead,BufNewFile *.jsx setfiletype javascript
augroup END
set t_Co=256 background=light
@justecorruptio
justecorruptio / mandelbrot.py
Last active June 24, 2020 03:43
Python script to generate a Mandelbrot set.
J=1;exec'''z="";b=-1.6;exec'
x=y=0;exec"x,y=2*x*y+J,y*y-x
*x+b;"*20;z+=" O"[x*x+y*y<2]
;b+=.040;'*60;print z;J-=.10
;'''.replace('\n','')*20#Jay
@justecorruptio
justecorruptio / brainfuck.py
Last active June 24, 2020 03:41
Tiny brainfuck interpreter.
import sys,os;M=[0]*30000;A=[]
p=k=x=0;S=open(sys.argv[1]).read()
while x<len(S):exec"""M[p]+=1
M[p]-=1 M[p]=ord(os.read(0,1)or"\\0")
os.write(1,chr(M[p])) p-=p>0 p+=1
k=A.append(x)if+M[p]else+1 x=A.pop()-1
k+=1 0 k-=1 0""".split()['+-,.<>[][+]+'
.find(S[x]+'+'*(k>0))];M[p]&=255;x+=1
@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 / 2048.pl
Created April 9, 2014 08:39
Even smaller 2048 in Perl !!!
sub Y{$p=$_;for$i(1..4){$p=join'',map{substr+($k&&$k-$i?$p:join'',map{s/@//g;s
/(.)\1/++($a=$1)/eg;$_|'@'x4}$p=~/.{4}/g),3+$_%4*4-($_/4|0),1}0..15}$p}$_='@'x
16;for(`stty cbreak`;print"\e[2J\e[H";$_=Y map{$k=index+JDACB,getc}0..2){$k=0;
1until$r=0|rand 16,!/@/||s/(?<=^.{$r})@/rand>.1?A:B/e;printf'%4s|%s',/\w/&&1<<
(ord)-64,++$g%4?'':$/for/./g;last if$e=WIN x/K/||Y!~/@/&&LOSE}print$e # [2048]
@justecorruptio
justecorruptio / server.sh
Last active July 19, 2019 06:11
Bash www server. Golfed from github.com/jaburns/ngincat
#!/bin/bash
:|((read f g h
[[ -f .$g&&$g != *..* ]]&&echo "$h 200 O
"&&cat .$g)|nc -q0 -lp$1)>/dev/fd/0;$0 $1
@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 / 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,