Skip to content

Instantly share code, notes, and snippets.

View brianium's full-sized avatar
🕊️
Human

Brian Scaturro brianium

🕊️
Human
View GitHub Profile
@brianium
brianium / Autoloader.php
Created March 12, 2012 18:54
PHP 5 Autoloader with Namespace support
<?php
class Autoloader
{
protected $directory;
protected $methodQueue;
/**
* @param string $dir the directory to look from
*/
@brianium
brianium / gist:2026243
Created March 13, 2012 02:39
ecmascript 3 bind
function bind(f,o) {
if(f.bind) return f.bind(o);
else return function() {
return f.apply(o, arguments);
};
}
@brianium
brianium / gist:2029233
Created March 13, 2012 14:49
bindless closure
var obj = {
method: function(name){
this.name = name;
console.log(this.name);
var self = this;
var inner = function(msg) {
console.log(msg + " " + self.name);
};
inner('hello');
}
@brianium
brianium / gist:2029237
Created March 13, 2012 14:49
closure with bind
var obj = {
method: function(name){
this.name = name;
console.log(this.name);
var inner = function(msg) {
console.log(msg + " " + this.name);
}.bind(this,'hello');
inner();
}
};
@brianium
brianium / IInputConfigRepositoryTest.php
Created March 14, 2012 17:40
mocking interfaces in php
<?php
namespace Test\Unit\Domain\Repositories;
use Domain\Repositories;
use Domain\Entities\InputConfig;
use Infrastructure\Reflection\Reflection;
class IInputConfigRepositoryTest extends \PHPUnit_Framework_TestCase
{
public function setUp() {
$this->mock = $this->getMockBuilder('Domain\Repositories\IInputConfigRepository')
->disableOriginalConstructor()
@brianium
brianium / gist:2052652
Created March 16, 2012 20:59
simple ddd console app
using System;
using System.Collections.Generic;
using DMSSubscriberUpdate.Domain;
using DMSSubscriberUpdate.Infrastructure;
using DMSSubscriberUpdate.Domain.Services;
namespace DMSSubscriberUpdate
{
class Program
{
@brianium
brianium / gist:2052663
Created March 16, 2012 21:01
domain service
using System;
using System.Collections.Generic;
using System.Linq;
namespace DMSSubscriberUpdate.Domain.Services
{
class SubscriberProcessor
{
protected Subscriber Subscriber { get; set; }
@brianium
brianium / gist:2052706
Created March 16, 2012 21:07
related model
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DMSSubscriberUpdate.Domain
{
public class Attempt
{
public int ChannelID { get; set; }
@brianium
brianium / gist:2128767
Created March 20, 2012 00:08
simple binary socket writer/reader
<?php
namespace Infrastructure\BinarySocket;
class BinarySocket
{
protected $socket;
public function __construct($ip,$port)
{
$this->socket = @socket_create(AF_INET,SOCK_STREAM,SOL_TCP);
$connected = @socket_connect($this->socket,$ip,$port);
@brianium
brianium / gist:2150452
Created March 21, 2012 18:05
JavaScript AOP proof of concept
//AOP powers rely on invoke() being used instead of ()
Function.prototype.invoke = function(args) {
if (this.before) {
this.before(args);
}
val = this(args);
if (this.after) {
this.after(args);
}
return val;