Skip to content

Instantly share code, notes, and snippets.

View beltiras's full-sized avatar

Árni St. Steinunnarson beltiras

  • Leiguskjól
  • Reykjavík, Iceland
View GitHub Profile
@beltiras
beltiras / cto.py
Last active August 27, 2023 02:45
import time
import datetime
def timing_protect(constant_time):
"""
The jitter will depend not on runtime but activity on the system writ large
import random
def d20():
return random.randint(1,20)
d = {}
for i in range(1000000):
r = max(d20(),d20())
d[r] = d.get(r,0) + 1
for i,n in d.items():
print(str(i)+","+str(n))
@beltiras
beltiras / sll.py
Last active April 15, 2019 20:51 — forked from gunnarig/sll.py
class SLL_Node:
def __init__(self, data, next):
self.data = data
self.next = next
# IMPLEMENT THIS
def average_of_list(head):
if type(head) == float:
return head
@beltiras
beltiras / clock.py
Last active October 23, 2018 18:45 — forked from gunnarig/clock.py
class Clock:
def __init__(self,hours = 0,minutes = 0,seconds = 0):
self.hours = hours
self.minutes = minutes
self.seconds = seconds
def add_clocks(self,var1,var2,var3):
self.seconds = self.seconds + var3
if self.seconds > 59:
self.seconds -= 60
@beltiras
beltiras / oifeho.py
Created October 18, 2018 15:30 — forked from gunnarig/oifeho.py
RANK = 0
NAME = 1
COUNTRY = 2
POINTS = 3
BIRTH_YEAR = 4
def get_input(user_prompt):##
user_input = input(user_prompt)
def check_win(game_state, token):
all_rows = [[line[x] for line in game_state] for x in range(len(game_state))] + [game_state[len(game_state)-x-1][x] for x in range(len(game_state))] + [game_state[x][x] for x in range(len(game_state))]
for line in all_rows:
if sum([1 for t in line if t == token]) == len(game_state):
return token
return " "
@beltiras
beltiras / ipfehoe.py
Last active October 14, 2018 22:43 — forked from gunnarig/ipfehoe.py
list_of_list = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]]
def make_diagonal(list_of_lists):
diag = []
diag.append([list_of_lists[len(list_of_lists)-x-1][x] for x in range(len(list_of_lists))])
diag.append([list_of_lists[x][x] for x in range(len(list_of_lists))])
print(diag)
@beltiras
beltiras / old.py
Last active October 14, 2018 21:23 — forked from gunnarig/old.py
def make_col(a_list_of_lists):
col_list = []
n = len(a_list_of_lists)
for n in range(len(a_list_of_lists)):
col = [l[n] for l in a_list_of_lists]
col_list.append(col)
print(col_list)
return col_list
@beltiras
beltiras / pifhwe0i.py
Last active October 14, 2018 21:16 — forked from gunnarig/pifhwe0i.py
def user_input_dimentions():
not_correct_input = True
while not_correct_input == True:
try:
boardDimentions = int(input("enter width of board: "))
not_correct_input = False
except ValueError:
print("please stop being an idiot")
return boardDimentions
def transpose(matrix):
result_matrix = []
for i in range(len(matrix[0])):
result_matrix.append([m[i] for m in matrix])
return result_matrix