Skip to content

Instantly share code, notes, and snippets.

View Sasszem's full-sized avatar
💥
Burning the dynamite at both ends

László Baráth Sasszem

💥
Burning the dynamite at both ends
  • Szolnok, Hungary
View GitHub Profile
@Sasszem
Sasszem / test_vecs_mult.py
Created February 13, 2017 11:00
Thes if v1 vector is the multiple of v2
def test_multiple(v1,v2):
"""Test if the 1st vec is the multiple of the 2nd"""
try:
v=[a/b for a,b in zip(v1,v2) if (not (a==0 and b==0))] #Divide one-by-one, but when dividing 0 by 0, don't do anything(and don1T raise ZDE)
#print(v)
return(len(set(v))<=1) #If there are 0 or 1 types of values(empty list or all the same) then it's true, else it's not
except ZeroDivisionError: #If divide nonzero by zero
return False #Then it's not a multiple of it
@Sasszem
Sasszem / shared.d
Created February 20, 2017 10:57
Shared variable vs. global. The difference is that shared vars are shared between threads, bud globals don't.
import std.stdio;
import core.thread;
shared int a=5;
int b=5;
void foo()
{writeln(" a=",a);writeln(" b=",b);}
@Sasszem
Sasszem / Terminal.java
Created April 16, 2018 10:08
A curses-like terminal class in java. Done in a boring IT class. Was not tested
package rpg;
import java.util.ArrayList;
class Terminal
{
public static final Integer BLACK = 0;
public static final Integer RED = 1;
public static final Integer GREEN = 2;
public static final Integer YELLOW = 3;
@Sasszem
Sasszem / term.py
Created July 17, 2018 23:05
A terminal control python module, like ComputerCraft's. Based on colorama
"""
Low-level terminal API based on colorama
Uses ASCII escape sequences
"""
import colorama
from colorama.ansi import clear_screen, set_title
from shutil import get_terminal_size
@Sasszem
Sasszem / prim.py
Created July 17, 2018 23:10
A PyOpenGL based 3d opbject renderer class with transformations
# -*- coding: utf-8 -*-
from OpenGL.GL import *
from array import array
glEnableClientState(GL_VERTEX_ARRAY)
class Primitive():
def __init__(self,vert,colors,colors2,drawMode,ind,x=0,y=0,z=0,s=0,rX=0,rY=0,rZ=0,sX=1,sY=1,sZ=1):
#Csúcstömbadatok tárolása/Storing vertex-data
self.vert=array('f',list(vert))
self.vert=glGenBuffers(1)
@Sasszem
Sasszem / pynp.py
Created July 17, 2018 23:51
A socket wrapper to help write custom protocols
import json
import struct
import array
def _toBytes(list):
return array.array('B', list).tostring()
def _toId(int):
return _toBytes((int %256, int//256))
@Sasszem
Sasszem / faszelso.py
Created October 1, 2018 00:57
OKTV 2017/18 turn 2 ex. 3
from sys import stdin, stdout
def readTree(numNodes):
"""Does what it says on the box.
The tree is stored like tree[n] = [...], the list of the child nodes of node n"""
nodes = {}
for i in range(1,numNodes+1):
# Why would I write readable code?
nodes[i] = list(map(int,stdin.readline().strip().split()[:-1]))
@Sasszem
Sasszem / fibo.lua
Created October 13, 2018 20:59
Demonstration of the power of simple dynamic programming using the fibonacci sequance
local NUM_TO_CALC = 10
print("Fib1 - uses 'brute-force recursive method':")
print("-------------------------------------------")
local called = {}
-- hashmap to store call statistics
local function fib(n, depth)
depth = depth or 1
@Sasszem
Sasszem / adventure_1.py
Last active February 13, 2020 23:41
A simple text adventure game in python
# a *very simple* text adventure game in python
# to practice control flow statements
# only contains IF-ELSE, WHILE statements, STRING, INTEGER and BOOL variables
# INPUT and PRINT
#######
# Map #
#######
@Sasszem
Sasszem / game_lists.py
Created February 23, 2020 22:11
Text adventore game rewritten with lists
#######
# Map #
#######
#########
#Key A #
# 2#
############# ###