Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am saeidw on github.
  • I am saeidw (https://keybase.io/saeidw) on keybase.
  • I have a public key ASDnLvideBWBHvTG_rQjiZhSuhpejH-jwAAPU6__8-oZYgo

To claim this, I am signing this object:

@saeidw
saeidw / gist:f3bf911b411205a4f834
Created May 20, 2015 14:10
Multiple client objects reading from same socket
<?php
$socket1 = new \Hoa\Socket\Client('tcp://172.16.3.76:5900');
$socket1->connect();
echo $socket1->read(6), PHP_EOL;
$socket2 = new \Hoa\Socket\Client('tcp://172.16.3.76:5900');
$socket2->connect();
@saeidw
saeidw / hints.php
Created February 18, 2015 12:05
Type hint stupidity
<?php
// PROBLEM: I want to use type-hints to make sure the parameters of
// a function are all the right type.
function printColor(Color $theColor) {
echo "The color is " . $theColor->getValue() . PHP_EOL;
}
interface ValueType {
@saeidw
saeidw / sum-fns.hs
Created January 10, 2015 11:00
Sum types with functions
-- We can have a sum type where each constructor is a function:
data F = A (String -> Int)
| B (Int -> Int)
-- Now let's create a value of this type:
-- The `length` function has type `[a] -> Int` and since
-- `String` is a synonym for `[Char]` we can use `length` on strings
f :: F
f = A (length)
@saeidw
saeidw / ziptree.py
Created September 3, 2013 14:35
A simple translation of the Zipper example from http://learnyouahaskell.com/zippers
# -----------------------------------------------------------------------------
# A tree is either an empty node, or a node with a left and right sub-tree
class Empty(object):
pass
class Node(object):
def __init__(self, value, left, right):
self.value = value
self.left = left
@saeidw
saeidw / gist:4644671
Last active December 11, 2015 18:49
For reference: $ php -v PHP 5.4.9 (cli) (built: Nov 21 2012 19:54:46) Copyright (c) 1997-2012 The PHP Group Zend Engine v2.4.0, Copyright (c) 1998-2012 Zend Technologies with Xdebug v2.2.1, Copyright (c) 2002-2012, by Derick Rethans
<?php
namespace Z;
class TestClass {
public function __construct() {}
public function test() { return "test()"; }
}
namespace Q;
use Z\TestClass;