Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / histogram
Last active December 23, 2015 22:49
A simple script to display a pretty histogram based on values read from STDIN.
#!/usr/bin/perl
=pod
A simple script to display a pretty histogram based on values read from STDIN.
=cut
use strict;
use Getopt::Long qw(:config bundling);
use List::Util qw(first max maxstr min minstr reduce shuffle sum);
binmode(STDOUT, ':utf8');
@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 / 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 / 2048.py
Last active September 22, 2017 05:17
Tiny 2048
import os,tty;tty.setcbreak(0);M=['']*16
def G(v):
p=['']*4;u=list(filter(str,v));i=3
while u:z=u.pop();p[i]=u and z==u[-1]and 2*u.pop()or z;i-=1
return p
def Y(M,k):i=1;M=zip(*[iter(M)]*4);exec'M=map([list,G][i*k==k*k],zip(*M))[::-1];i+=1;'*4;return sum(M,[])
while 1:
r=id(M)%71+17
while M[r%16]*r:r-=1
if r:M[r%16]=r%7%2*2+2
@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 / 2048.annotated.c
Created April 9, 2014 09:52
Annotated version of 2048.c
/* Annotated version of 2048.c */
M[16], // The board
X=16, // Shorthand for 16
W, // Game over bit mask: 1=won, 2=not lost
k;
main(){
T( // Call main game logic
system("stty cbreak") // Set tty mode to not wait for enter key
@justecorruptio
justecorruptio / conway_life.c
Last active October 24, 2017 08:04
Tiny implementation of Conway's game of life.
#define _+o[~$&1][O
o[2][992],$;main(O){
for(;gets(o);$++)for
(puts("\e[H"),O=32;O
++<960;)putchar(O%32
?" O"[o[$&1][O]=3==(
_-33]_-32]_-1]_-31]_
+1]_+31]_+32]_+33]|_
])|O%9&!$]:10);}
@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())