Skip to content

Instantly share code, notes, and snippets.

View harunyasar's full-sized avatar

Harun Yasar harunyasar

  • Hyperware LTD
  • Oxford
  • 20:56 (UTC)
View GitHub Profile
@harunyasar
harunyasar / php_design_patterns _command_pattern.php
Last active August 29, 2015 14:19
PHP Design Patterns: Command Pattern
<?php
// Command
interface Order {
public function execute();
}
// Receiver Class
class Stock {
@harunyasar
harunyasar / php_design_patterns_factory_pattern.php
Created April 24, 2015 10:35
PHP Design Patterns: Factory Pattern
<?php
interface Dog
{
public function speak ();
}
class Poodle implements Dog
{
public function speak()
@harunyasar
harunyasar / simple_fibonacci_generator.py
Last active August 29, 2015 14:20
Simple Fibonacci generator
def fibo():
a, b = 0, 1
while True:
yield a
a, b = b, a + b
# usage
f = fibo()
f.next()
...
@harunyasar
harunyasar / php_design_patterns_decorator_pattern.php
Last active April 2, 2016 15:17
PHP Design Patterns: Decorator Pattern
<?php
interface Shape {
public function draw();
}
class Rectangle implements Shape {
public function draw() {
echo "Shape: Rectangle\r\n";
}
@harunyasar
harunyasar / simple_grid_creator.js
Last active September 9, 2015 07:00
Simple grid creator...
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;
@harunyasar
harunyasar / simple_fibonacci_generator.php
Last active August 29, 2015 14:22
Simple Fibonacci generator
<?php
function fibonacci($item) {
$a = 0;
$b = 1;
for ($i = 0; $i < $item; $i++) {
yield $a;
$a = $b - $a;
$b = $a + $b;
}
@harunyasar
harunyasar / formatting_and_stripping.py
Created July 3, 2015 12:24
String formatting with % and stripping
a = " Lorem ipsum"
b = " "
("%s %s" % (a , b)).strip() # 'Lorem ipsum'
"%s %s" % (a , b) # ' Lorem ipsum '
@harunyasar
harunyasar / get_the_dict_key_by_value.py
Created September 16, 2015 08:49
Get the dict key by value
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)]
@harunyasar
harunyasar / pascal_triangle.py
Created October 7, 2015 08:21
Pascal Triangle
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
@harunyasar
harunyasar / low_cohesion.php
Created October 22, 2015 07:00
Personel sınıfı için Low Cohesion örneği
<?php
class Personel {
private $db;
public function __construct(DatabaseConnection $db)
{
$this->db = $db;
}