Skip to content

Instantly share code, notes, and snippets.

def singleton(class_):
instances = {}
def getinstance(*args, **kwargs):
if class_ not in instances:
instances[class_] = class_(*args, **kwargs)
return instances[class_]
return getinstance
@singleton
class MyClass(BaseClass):
if __name__=="__main__":
print("Selam")
@mcihad
mcihad / .htaccess
Created September 15, 2014 19:23
test.php konfigurasyon dosyası
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
@mcihad
mcihad / test.php
Last active October 22, 2019 18:10
PHP MVC Basit Url Yönlendirmesi ve Action Çalıştırma, Simple MVC implementation , Url Routing and action execution
<?php
class Controller {
protected $data=array();
public function set($name,$value) {
$this->data[$name]=$value;
}
public function get($name) {
@mcihad
mcihad / py-deco.py
Last active August 29, 2015 14:04
Decorator Python
"""
django view içerisinde kullanmak için
f fonksiyonu ilk parametresi request
kullanıcının applikasyon yetkisi kontrol edilebilir
"""
from functools import wraps
def apps_required(appname):
@mcihad
mcihad / prime.rb
Last active August 29, 2015 14:04
Ruby asal sayı
#require "prime" diyerek standart prime modulünüde kullanabilirsiniz
class Fixnum
def prime?
2.upto((self-(self % 2))/2) do |i|
if self % i==0
return false
end
end
return true
end
@mcihad
mcihad / go-ilk.go
Last active August 29, 2015 14:03
Go dili ilk deneme sum,avg, min,max
package main
import "fmt"
func sum(vals []int) (r int) {
for _, val := range vals {
r += val
}
return
}