export M2_HOME=/Users/macbookpro/Developer/maven
export JAVA_HOME=$(/usr/libexec/java_home)
alias mvn=/Users/macbookpro/Developer/maven/bin/mvn
Kategori arşivi: Kod
Thymeleaf HTML5 Data Attributes
Thymeleaf‘de html5 data attributelari asagidaki sekilde verilebilir.
<div th:attr="data-xxx=$xxx,data-xx=$xx"></div> |
Javascript Get Object Length
javascript resize iframe height
function adjustFrameHeight(frameId){ try{ var frame = document.getElementById(frameId); var frameDoc; if (frame.contentDocument) frameDoc = frame.contentDocument; else frameDoc = frame.contentWindow.document; if (navigator.appName == "Microsoft Internet Explorer"){ frame.style.height = frameDoc.body.scrollHeight+'px'; }else{ frame.style.height = frameDoc.body.offsetHeight+'px'; } }catch(err){ //ignore } } |
PHP gercek IP adresini alma
PHP’de proxy uzerinden gelen isteklerin esasen hangi IP’den geldigini bulmaya yarayan bir metod.
private function getRealIpAddr(){ $ip = false; if(!empty($_SERVER['HTTP_CLIENT_IP'])){ $ip=$_SERVER['HTTP_CLIENT_IP']; }elseif(!empty($_SERVER['HTTP_X_FORWARDED_FOR'])){ $ip=$_SERVER['HTTP_X_FORWARDED_FOR']; }else { $ip=$_SERVER['REMOTE_ADDR']; } return $ip; } |
SSH Server Permission Denied (Publickey)
ssh-keygen |
ile olusturulan ve
/home/:username:/.ssh/authorized_keys |
klasorune konulan public key’e ragmen yine de
Permission Denied(publickey) |
hatasi aliyorsak eger bu klasor ve icindeki dosyalarin izinlerini gozden gecirmek gerekebilir.
/home/:username:/.ssh/ => Bu klasorun sahibi :username: olmali
chown -R :username: /home/:username:/.ssh/ |
/home/:username:/.ssh/ => Bu klasorun izni 0700 olmali
chmod 0700 /home/:username:/.ssh/ |
/home/:username:/.ssh/authorized_keys => Bu dosyanin izni 0600 olmali
chmod 0600 /home/:username:/.ssh/authorized_keys |
* :username: ssh ile baglanmak istenilen kullanici ismi
Umarim birine yardimci olur benim gibi 3 saat harcamazsiniz 🙂
jQuery Custom Countdown Plugin
Javascript Timestamp
PHP Query Cache
basit bir query cache sınıfı. php5 gerekiyor evet.
Kullanımı aşağıdaki gibi. elbette class ilk olarak include edilmeli evet. ikinci parametre true olarak verilirse o dosya için bir cache yoksa eğer ilk olarak cache oluşturulcak ve tekrar çağrıldığında cache’deki veri dönecek
kullanımı:
$dbCache = new dbcache(); //eğer query cache'i varsa $retVal = $dbCache->checkQueryCache($query); if($retVal !== FALSE) { return unserialize($retVal); } //bu satır da querycache'ini yazmak için //$return değişkeni query'den dönen sonuçların tutulduğu bir array $dbCache->writeQueryCache($query,serialize($return)); |
bu da sınıf. cache_dir ile tanımlanan klasöre yazma izni verilmeli:
< ?php /* * Class: Simple Query Cache v0.2 * @author: Doruk Özalp * * last update: * 23 / 01 / 2010 23:22 PM * * changelog: * v0.2: * added file modification time support * * v0.1: * initial release * * */ class dbcache { //PRIVATE VARIABLES private $cache_file; private $base_dir; private $this_dir; private $lifetime; private $query_data; private $query; private $cache_dir = "assets/output_cache/"; //CONSTRUCTOR function __construct() { $this->setBaseDir($_SERVER["REQUEST_URI"]); $this->setThisDir($this->cache_dir) . md5($this->getBaseDir())); $this->setLifeTime(3600); // 1-hour } //DECONSTRUCTOR function __destruct() { } //PUBLIC FUNCTIONS public function checkQueryCache($query) { $retVal = FALSE; $this->setQuery($query); $this->setCacheFile($this->getThisDir() . "/" . md5($this->getBaseDir() . $this->getQuery())); if($this->checkCacheFile()) { $retVal = $this->loadCacheFile(); } return $retVal; } public function writeQueryCache($query, $query_data) { $this->setQuery($query); $this->setQueryData($query_data); $this->setCacheFile($this->getThisDir() . "/" . md5($this->getBaseDir() . $this->getQuery())); if($this->checkCacheFile()) { clearstatcache(); if(time() - filemtime($this->getCacheFile()) > $this->getLifeTime()) { $this->writecachefile(); } } else { $this->writecachefile(); } } //PRIVATE FUNCTIONS private function checkCacheFile() { $retVal = FALSE; if(file_exists($this->getCacheFile())) { $retVal = TRUE; } return $retVal; } private function loadCacheFile() { return file_get_contents($this->getCacheFile()); } private function writecachefile() { if(!is_dir($this->getThisDir())) { mkdir($this->getThisDir(), 0777); } $handle = fopen($this->getCacheFile(), 'w+'); fwrite($handle, $this->getQueryData()); fclose($handle); } //SETTER AND GETTERS private function setBaseDir($input) { $this->base_dir = $input; } private function getBaseDir() { return $this->base_dir; } private function setThisDir($input) { $this->this_dir = $input; } private function getThisDir() { return $this->this_dir; } private function setLifeTime($input) { $this->lifetime = $input; } private function getLifeTime() { return $this->lifetime; } private function setCacheFile($input) { $this->cache_file = $input; } private function getCacheFile() { return $this->cache_file; } private function setQueryData($input) { $this->query_data = $input; } private function getQueryData() { return $this->query_data; } private function setQuery($input) { $this->query = $input; } private function getQuery() { return $this->query; } } ?> |
PHP Partial Cache
basit bir partial cache sınıfı. php5 gerekiyor evet.
Kullanımı aşağıdaki gibi. elbette class ilk olarak include edilmeli evet. ikinci parametre true olarak verilirse o dosya için bir cache yoksa eğer ilk olarak cache oluşturulcak ve tekrar çağrıldığında cache’deki veri dönecek.
$output = new outputcache(); $output->load("header.php", true); $output->load("main.php", true); $output->load("footer.php", true); |
bu da sınıf. cache_dir ile tanımlanan klasöre yazma izni verilmeli:
< ?php /* * Class: Simple Output Cache v0.2 * @author: Doruk Özalp * * last update: * 22 / 01 / 2010 22:20 PM * * changelog: * v0.2: * added file modification time support * * v0.1: * initial release * * */ class outputcache { //PRIVATE VARIABLES private $output = array(); private $cache_file; private $base_dir; private $this_dir; private $lifetime; private $include_file; private $cache_dir = "assets/output_cache/"; //CONSTRUCTOR function __construct() { $this->setBaseDir($_SERVER["REQUEST_URI"]); $this->setThisDir($this->cache_dir . md5($this->getBaseDir())); $this->setLifeTime(3600); // 1-hour } //DECONSTRUCTOR function __destruct() { } //PUBLIC FUNCTIONS public function load($file, $cache = FALSE) { $this->setIncludeFile($file); if($cache === FALSE) { include_once($this->getIncludeFile()); } elseif($cache === TRUE) { $this->setCacheFile($this->getThisDir() . "/" . md5($this->getBaseDir() . $this->getIncludeFile())); if($this->checkCacheFile()) { clearstatcache(); if(time() - filemtime($this->getCacheFile()) > $this->getLifeTime()) { $this->makeCacheFile(); } else { $this->loadCacheFile(); } } else { $this->makeCacheFile(); } } } //PRIVATE FUNCTIONS private function makeCacheFile() { $this->start(); include_once($this->getIncludeFile()); $this->setOutput($this->getCacheFile(), $this->getContent()); $this->end(); $this->writecachefile(); } private function checkCacheFile() { $retVal = FALSE; if(file_exists($this->getCacheFile())) { $retVal = TRUE; } return $retVal; } private function loadCacheFile() { echo file_get_contents($this->getCacheFile()); } private function writecachefile() { if(!is_dir($this->getThisDir())) { mkdir($this->getThisDir(), 0777); } $handle = fopen($this->getCacheFile(), 'w+'); fwrite($handle, $this->getCacheContent($this->getCacheFile())); fclose($handle); } private function getCacheContent($file_md5) { return $this->getOutput($file_md5); } private function start() { return ob_start(); } private function end() { return ob_end_flush(); } private function getContent() { return ob_get_contents(); } //SETTER AND GETTERS private function setBaseDir($input) { $this->base_dir = $input; } private function getBaseDir() { return $this->base_dir; } private function setThisDir($input) { $this->this_dir = $input; } private function getThisDir() { return $this->this_dir; } private function setLifeTime($input) { $this->lifetime = $input; } private function getLifeTime() { return $this->lifetime; } private function setCacheFile($input) { $this->cache_file = $input; } private function getCacheFile() { return $this->cache_file; } private function setOutput($index, $input) { $this->output[$index] = $input; } private function getOutput($index) { return $this->output[$index]; } private function setIncludeFile($input) { $this->include_file = $input; } private function getIncludeFile() { return $this->include_file; } } ?> |