Skip to content

Instantly share code, notes, and snippets.

View ackintosh's full-sized avatar
🎯
Focusing

Akihito Nakano ackintosh

🎯
Focusing
View GitHub Profile
@ackintosh
ackintosh / gist:3731335
Created September 16, 2012 06:53
Sample of observer pattern using PHP5.4 trait.
trait Subject
{
public function initListeners()
{
$this->listeners = array();
}
public function addListener($listener)
{
$this->listeners[] = $listener;
@ackintosh
ackintosh / gist:3938364
Created October 23, 2012 11:51
Abstract class/method in Ruby
# These code may not be a ruby.
class AbstractKlass
def initialize
raise 'Abstract Class !!'
end
def method_a
raise 'Called abstract method !!'
end
@ackintosh
ackintosh / gist:3945597
Created October 24, 2012 11:36
Template Method Pattern in Ruby
class Report
def initialize
@title = 'report title'
@text = ['text1', 'text2', 'text3']
end
def output_report
output_start
output_body
output_end
@ackintosh
ackintosh / gist:4010809
Created November 4, 2012 09:00
Strategy Pattern in Ruby
class Formatter
def output_report(title, text)
raise 'Called abstract method !!'
end
end
class HTMLFormatter < Formatter
def output_report(report)
puts "<html><head><title>#{report.title}</title></head>"
puts '<body>'
@ackintosh
ackintosh / gist:4010931
Created November 4, 2012 09:40
Strategy Pattern and Proc Object in Ruby
class Report
attr_reader :title, :text
attr_accessor :formatter
def initialize(&formatter)
@title = 'report title'
@text = ['text1', 'text2', 'text3']
@formatter = formatter
end
@ackintosh
ackintosh / masonry.html
Created November 10, 2012 05:59
Using the jQuery Masonry
<div class="masonry">
<article class="masonry-brick">
...
</article>
<article class="masonry-brick">
...
</article>
<article class="masonry-brick">
...
</article>
@ackintosh
ackintosh / gist:4059901
Created November 12, 2012 15:14
fizzbuzz in php
<?php
for ($i = 1; $i <= 100; $i++) echo (($i % 15 === 0) ? 'fizzbuzz' : (($i % 5 === 0) ? 'buzz' : ($i % 3 === 0 ? 'fizz' : $i))) . PHP_EOL;
@ackintosh
ackintosh / gist:4142451
Created November 25, 2012 04:58
Using the __call()
class Wrapper
{
private $_obj;
public function __construct($obj)
{
$this->_obj = $obj;
}
public function __call($name, $args)
<?php
// front.php
$options = array(
'name' => 'ack_queue',
'driverOptions' => array(
'host' => 'localhost',
'port' => '22133',
),
);
@ackintosh
ackintosh / gist:4696317
Created February 2, 2013 06:35
Functional Programming in PHP
<?php
class MyList implements ArrayAccess
{
private $_values;
public function __construct($array = array())
{
$this->_values = $array;
}