Skip to content

Instantly share code, notes, and snippets.

View attilammagyar's full-sized avatar

Attila Magyar attilammagyar

View GitHub Profile
@attilammagyar
attilammagyar / GameOfLife.py
Last active December 15, 2015 08:39
A simple Conway's Game of Life implementation in Python.
class GameOfLife(object):
def evolve(self, cells):
next_generation = set()
for cell in cells:
if self.__should_survive(cell, cells):
next_generation.add(cell)
for neighbor in self.__get_neighbors(cell):
if self.__should_become_alive(neighbor, cells):
next_generation.add(neighbor)
return next_generation
@attilammagyar
attilammagyar / basic
Last active September 3, 2021 12:33
Oldest existing source code of mine (good old C64!) :-)
10 REMGOSUB2000
20 V=53248:AD=8192:A1=PEEK(V+17):A2=PEEK(V+24)
30 POKEV+17,59:POKEV+24,24
60 FORI=1024TO2023
70 POKEI,16
80 NEXTI
90 FORI=8192TO16383:POKEI,0:NEXTI
120 REMFORX=0TO319
121 REMY=100
122 REMGOSUB1000
@attilammagyar
attilammagyar / debug.h
Created November 4, 2012 13:15
(C/C++) small helpers to generate debug logs in hairy situations
#ifndef __DEBUG_H_INCLUDED
#define __DEBUG_H_INCLUDED
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/file.h>
#include <sys/time.h>
#include <libgen.h>
#include <time.h>
@attilammagyar
attilammagyar / PDO.php
Created April 18, 2012 22:12
My favorite PHP gotchas
<?php
// https://bugs.php.net/bug.php?id=53567
function create_pdo()
{
return new PDO("mysql:host=localhost;dbname=test",
"test", "my_password",
array(PDO::ATTR_PERSISTENT => true));
}
@attilammagyar
attilammagyar / index.html
Created March 4, 2012 16:40
JavaScript variable declaration hoisting examples
<!DOCTYPE html>
<html>
<head>
<title>JavaScript variable declaration hoisting</title>
<meta charset="utf-8" />
<script type="text/javascript" src="test.js"></script>
</head>
<body>
<h1>See FireBug console :-)</h1>
</body>
@attilammagyar
attilammagyar / MyObject.php
Created August 30, 2011 20:31
PHP: user defined readonly, type-checked, callback or calculated properties
<?php
class MyObject
{
public function __construct()
{
$this->properties = array();
}
public function __get($property_name)