Skip to content

Instantly share code, notes, and snippets.

View terror's full-sized avatar

liam terror

View GitHub Profile
using System;
using static System.Console;
class Program {
static void Main(string[] args) {
Write("Number of rows: ");
int r = int.Parse(ReadLine()); // 5
Write("\nNumebr of cols: ");
int c = int.Parse(ReadLine()); // 3
using System;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
List<List<int>> arr = new List<List<int>>();
// -> []
for(int i = 0; i < 10; ++i) {
# python functions are objects
# can be passed stored in variables, passed as args, returned, etc
def wrap(func):
print("wow!")
func()
print("oo")
def hello():
print("hello!")
def diff_a(a, b):
return list(set(a) - set(b)) + list(set(b) - set(a))
def diff_b(lists):
x = [list(set(i) - set(j)) for i in lists for j in lists]
return list(set([item for sublist in x for item in sublist]))
def main():
a = [1, 2, 3]; b = [1, 2, 5, 4]; c = [1, 3, 5, 6]
print(diff_a(a, b)) # [3, 5, 4]
import time
import functools
class Foo:
def __init__(self, n = 1):
self.n = n
@functools.cached_property
def expensive(self):
return fib(self.n)
_='_=%r;print (_%%_)';print (_%_)
@terror
terror / meta.py
Last active June 8, 2021 17:25
Python metaprogramming example
class Meta(type):
def __new__(cls, what, bases=None, dict=None):
if 'area' not in dict:
raise Exception("Area not found!")
return type.__new__(cls, what, bases, dict)
class Shape(metaclass=Meta):
def __init__(self, l, w):
self.l = l
self.w = w
@terror
terror / hof.py
Last active June 8, 2021 17:25
Code for my `Higher order functions` blog post
def filter(func, iterable):
return [el for el in iterable if func(el)]
def map(func, iterable):
return [func(x) for x in iterable]
def reduce(func, iterable, init=None):
it = iter(iterable)
val = next(it) if init is None else init
@terror
terror / ff.py
Created June 9, 2021 15:59
Simple python function frequency counter
import ast, collections, argparse, os
class File:
def __init__(self, path):
self.path = path
@property
def last(self):
return os.path.normpath(os.path.basename(self.path))
@terror
terror / test.py
Last active June 20, 2021 22:26
?
import random
class T:
store = []
@staticmethod
def run():
status = lambda name, result: f"[{name}] ... {result}"
for test in T.store:
try: