Skip to content

Instantly share code, notes, and snippets.

View aalhour's full-sized avatar
🪂

Ahmad Alhour aalhour

🪂
View GitHub Profile
@aalhour
aalhour / microkanren.py
Created December 22, 2015 11:13 — forked from cheery/microkanren.py
Microkanren tryout.
import itertools
# Microkanren programs are 'goal' functions that take in a
# state and return a stream of states that satisfy the given goal.
# I am interested about microkanren because it presents a logic
# programming kernel which fits into a dynamically typed language.
# Anything could go as a variable, but I wanted names for variables.
class Variable(object):
@aalhour
aalhour / fib_micro_service.py
Created December 2, 2015 12:26
Fibonacci microservice using Python & Tornado.
import tornado.web
import tornado.ioloop
from tornado.options import define, options
define('port', default=45000, help='try running on a given port', type=int)
def fib():
a, b = 1, 1
while True:
yield a
@aalhour
aalhour / frontendDevlopmentBookmarks.md
Last active September 9, 2015 11:42 — forked from dypsilon/frontendDevlopmentBookmarks.md
A badass list of frontend development resources I collected over time.
public class TreeNode<T> where T : IComparable<T>
{
public T Value { get; set; }
public TreeNode<T> Left { get; set; }
public TreeNode<T> Right { get; set; }
public TreeNode<T> Parent { get; set; }
}
public static class TreeTraversalIterative
{
@aalhour
aalhour / TreeTraversalRecursive.cs
Last active September 4, 2015 07:09
Recursive traversals of a binary tree.
public class TreeNode<T> where T : IComparable<T>
{
public T Value { get; set; }
public TreeNode<T> Left { get; set; }
public TreeNode<T> Right { get; set; }
public TreeNode<T> Parent { get; set; }
}
public static class TreeTraversalRecursive
{
public enum ToyType { Car = 0, House = 1 };
public static class ToysFactory
{
private static IToy _newToy { get; set; }
public static IToy CreateToy(ToyType type)
{
if (type == ToyType.Car)
{
@aalhour
aalhour / SingletonPatternExample.cs
Last active August 17, 2017 21:35
A singleton class example in C#.
public sealed class SingletonExample
{
// internal singleton instance
private static SingletonExample _instance;
// lock for thread-safety laziness
private static readonly object _mutex = new object();
// private empty constuctor
private SingletonExample()
@aalhour
aalhour / AckermannMemoized
Last active August 29, 2015 14:23
Recursively-memoized implementation of the Ackermann formula as discussed on ComputerPhile (https://www.youtube.com/watch?v=i7sm9dzFtEI).
public class AckermannFormulaMemoized
{
public static long AckermannMemoized(long m, long n)
{
long ans = 0;
string key = String.Format("{0},{1}", m, n);
if (memory.ContainsKey(key)) {
return memory[key];
} else {
@aalhour
aalhour / Ackermann
Last active August 29, 2015 14:23
Implementation of the Ackermann formula as discussed on ComputerPhile (https://www.youtube.com/watch?v=i7sm9dzFtEI).
public class AckermannFormula
{
public static long Ackermann(long m, long n)
{
if (m == 0) return (n+1);
else if (n == 0) Ackermann(m-1, 1);
else return Ackermann(m-1, Ackermann(m, n-1));
}
}