This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Command | |
interface Order { | |
public function execute(); | |
} | |
// Receiver Class | |
class Stock { | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
interface Dog | |
{ | |
public function speak (); | |
} | |
class Poodle implements Dog | |
{ | |
public function speak() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def fibo(): | |
a, b = 0, 1 | |
while True: | |
yield a | |
a, b = b, a + b | |
# usage | |
f = fibo() | |
f.next() | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
interface Shape { | |
public function draw(); | |
} | |
class Rectangle implements Shape { | |
public function draw() { | |
echo "Shape: Rectangle\r\n"; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var createGrid = function (rows, cols) { | |
var str = "", | |
odd = "o", | |
even = "#"; | |
for (var row = 0; row < rows; row++) { | |
for (var col = 0; col < cols; col++) { | |
if ((row + col) % 2 === 0) { | |
str += even; | |
} else { | |
str += odd; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function fibonacci($item) { | |
$a = 0; | |
$b = 1; | |
for ($i = 0; $i < $item; $i++) { | |
yield $a; | |
$a = $b - $a; | |
$b = $a + $b; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a = " Lorem ipsum" | |
b = " " | |
("%s %s" % (a , b)).strip() # 'Lorem ipsum' | |
"%s %s" % (a , b) # ' Lorem ipsum ' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
words = { | |
'lorem': 1, | |
'ipsum': 2, | |
'dolor': 3, | |
'sit': 4, | |
'amet': 5 | |
} | |
def get_the_key(my_dict, value): | |
return my_dict.keys()[my_dict.values().index(value)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def pascal(n): | |
if n == 1: | |
return [1] | |
else: | |
p_line = pascal(n - 1) | |
line = [p_line[i] + p_line[i + 1] for i in range(len(p_line) - 1)] | |
line.insert(0, 1) | |
line += [1] | |
return line |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Personel { | |
private $db; | |
public function __construct(DatabaseConnection $db) | |
{ | |
$this->db = $db; | |
} |
OlderNewer