Skip to content

Instantly share code, notes, and snippets.

View dionyziz's full-sized avatar
🐼

Dionysis Zindros dionyziz

🐼
View GitHub Profile
@dionyziz
dionyziz / timemachine.cpp
Created June 12, 2011 15:21
A simple time machine in C++
#include <cstdio>
#include <cstdlib>
#include <unistd.h>
using namespace std;
int main( int argc, char *argv[] ) {
int year;
int now;
char c;
@dionyziz
dionyziz / primes.php
Created August 23, 2011 21:57
An interesting way to implement the Sieve of Eratosthenes in PHP
<?php
class PrimeIterator implements Iterator {
private $i;
private $primes;
private function generateNextPrime() {
$candidate = $this->primes[ count( $this->primes ) - 1 ];
do {
$candidate += 2;
$isPrime = true;
@dionyziz
dionyziz / peano.js
Created August 28, 2011 16:05
Javascript Peano Arithmetic from thin air
// peano.js - Javascript Peano Arithmetic from thin air
// Developer: Dionysis "dionyziz" Zindros <dionyziz@gmail.com>
//
// This is an illustration of how it is possible to construct the system of arithmetic
// on non-negative integers in Javascript without requiring any underlying arithmetic code by the host language.
// The system is based purely on the underlying logic of the language; that is, "if", "and", "or",
// "not" and the equals operator "==", as well as the logical constants true and false;
// those logical constants, incidentally, can be obtained by issuing "null == null" and "!( null == null)"
// respectively, so they are not required to be defined. Indeed, observe the following alternative:
//
@dionyziz
dionyziz / example.js
Created September 7, 2011 13:51
A library for potentially infinite streams in Javascript
function sieve( s ) {
if ( s.empty() ) {
return s;
}
var h = s.head();
return new Stream( h, function () {
return sieve( s.tail().filter( function ( x ) {
return x % h != 0;
} ) );
@dionyziz
dionyziz / sieve.php
Created November 29, 2011 14:04
A sieve of Eratosthenes in PHP
<?php
define( 'N', 10000 );
// upper bound for our prime number
$estimate = floor( N * log( N ) + N * log( log( N ) ) );
$primes = array( 2, 3, 5, 7, 11, 13 );
$primeCount = 6;
$lastPrime = 13;
for ( $i = 17; $primeCount <= N; $i += 2 ) {
$prime = true;
@dionyziz
dionyziz / unknown.js
Created November 29, 2011 19:07
What does this piece of code do?
( ( function( f ) {
return ( function( x ) {
return f( function( n ) {
return ( x( x ) )( n );
} );
} )( function( x ) {
return f( function( n ) {
return ( x( x ) )( n );
} );
} );
@dionyziz
dionyziz / fibo.coffee
Created March 30, 2012 06:47 — forked from Geekfish/fibo.cj
Coffee nth Fibonacci
( f = ( x, y, i ) -> if i then f( y, x + y, i - 1 ) else y )( 1, 1, 1475 )
#include <stdio.h>
#include <unistd.h>
int main() {
int fd[2];
int a = 0;
pipe(fd);
if (vfork()) {
@dionyziz
dionyziz / private-access.cpp
Created October 25, 2013 19:45
Try to access the private property of another object of the same class.
#include <cstdio>
class Test {
private:
int foo;
public:
Test(int foo_value) {
foo = foo_value;
}
@dionyziz
dionyziz / private-cross-class-access.cpp
Created October 25, 2013 20:04
Private access between two different classes.
#include <cstdio>
class Test {
private:
int foo;
public:
Test(int foo_value) {
foo = foo_value;
}