Skip to content

Instantly share code, notes, and snippets.

@nthe
nthe / events.py
Last active February 27, 2018 12:53
simple implementation of observer pattern in python
class Event:
def __init__(self):
self._subscribers = set()
@property
def subscribers(self):
return self._subscribers.copy()
class Allergen(models.Model):
name = models.CharField(max_length=256, null=False, blank=False)
class Ingredient(models.Model):
name = models.CharField(max_length=255, null=False, blank=False)
description = models.TextField(null=True, blank=False)
allergens = models.ManyToManyField(Allergen) # -> this fields creates table
may_contain = models.ManyToManyField(Extra) # between Ingredient and Allergen
@nthe
nthe / singleton.py
Last active December 9, 2020 07:37
class Singleton(object):
_instance = None
def __new__(cls, *args, **kwargs):
if not cls._instance:
cls._instance = super(Singleton, cls).__new__(cls, *args, **kwargs)
return cls._instance
@nthe
nthe / game_of_life.c
Created September 17, 2016 11:11
Just another Game of Life implementation.
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#define fx for(i = 0; i < x; i++)
#define fy for(j = 0; j < y; j++)
#define nl printf("\n");
#define apc ap[j * x + i]
#define dc int i, j;