Skip to content

Instantly share code, notes, and snippets.

@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;
@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
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 / 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()
@nthe
nthe / api-cache.js
Last active January 20, 2023 15:11
Simple API cache for redux-observable
/**
* Check if cached record is valid.
* @param {object} cachedValue - cache record
* @param {number} cacheTime - time to cache
* @returns {bool}
*/
const isCached = (cachedValue, cacheTime) =>
(new Date() - cachedValue.at) / 1000 < cacheTime;
/**
@nthe
nthe / perf.js
Last active August 19, 2018 11:29
Simple performance monitor implemented as higher order component.
import React, { unstable_Profiler as Profiler } from "react";
/**
* Profiles storage.
*/
const profiles = {};
/**
* Calculate weighted average.
* @param {number} time - time passed
@nthe
nthe / shallow_water.pde
Created August 23, 2019 10:19
Shallow Water | Processing
import ch.bildspur.postfx.builder.*;
import ch.bildspur.postfx.pass.*;
import ch.bildspur.postfx.*;
/**
* varaibles
*/
float
cx,
cy,
@nthe
nthe / noisy_attractor.pde
Last active September 2, 2019 19:53
Noisy Attractor | Processing
float A = -2.337,
B = -2.337,
C = 0.2553,
D = 1.378,
dx = 0.1,
dy = 0.1;
float X() {
return A * sin(dx * A) - sin(dy * D);
}
@nthe
nthe / background.js
Created January 29, 2020 19:23
URL tracking cross-browser web-extension.
(function (window) {
/* reference exposed api based on browser */
const API = window.chrome || window.browser;
/* IP address used for calls */
let IPAddress = "0.0.0.0";
/* polling period in miliseconds */
@nthe
nthe / ConcurrentQueue.cs
Created February 3, 2020 21:11
ConcurrentQueue with MTA threads example
using System;
using System.Linq;
using System.Threading.Tasks;
using System.Collections.Generic;
using System.Collections.Concurrent;
namespace dotnetpad
{
class Program
{