Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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 / 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 / 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 / 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 / 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 / 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