Skip to content

Instantly share code, notes, and snippets.

View egulhan's full-sized avatar
Here we go again...

Erman Gülhan egulhan

Here we go again...
View GitHub Profile
@egulhan
egulhan / dl_speed_limit.php
Created January 27, 2013 08:58
File download with speed limit
// Source: http://jonasjohn.de/snippets/php/dl-speed-limit.htm
// local file that should be send to the client
$local_file = 'test-file.zip';
// filename that the user gets as default
$download_file = 'your-download-name.zip';
// set the download rate limit (=> 20,5 kb/s)
$download_rate = 20.5;
@egulhan
egulhan / go-up
Created January 27, 2013 21:08
go up by number means that do cd.. by number
# up 4 -> go up 4 directories
up()
{
dir=""
if [[ $1 =~ ^[0-9]+$ ]]; then
x=0
while [ $x -lt ${1:-1} ]; do
dir=${dir}../
x=$(($x+1))
done
@egulhan
egulhan / isIpValid.js
Created August 1, 2013 08:34
Check a IP is valid or not.
var
ip=attr.val(),
ipPatt=/^([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])$/;
// If invalid ip
if(!ipPatt.test(ip))
alert('invalid ip');
else
alert('valid ip');
@egulhan
egulhan / vimrc.simple
Last active December 20, 2015 22:39
vimrc.simple
"""""""""""""""""""""""""""""""""""""""""""""""""""""
" @date 2013-08-12
"""""""""""""""""""""""""""""""""""""""""""""""""""""
set number
set nowrap
set backupdir=/var/tmp/vimtmp
set nobackup
set noswapfile
set autoindent
@egulhan
egulhan / 2digitYearTo4digitYear.php
Last active December 26, 2015 02:59
Convert 2 digit year to 4 digit year
$dt = DateTime::createFromFormat('y', '12');
echo $dt->format('Y'); // output: 2012
@egulhan
egulhan / dateArgsToVars.php
Created October 21, 2013 11:40
Convert a date arguments into variables by preg_split.
date_default_timezone_set('Europe/Istanbul');
$date=date('Y-m-d h:i:s');
list($year,$month,$day,$hour,$minute,$second)=preg_split('/[- :]/',$date);
@egulhan
egulhan / ipv4BlockIpRegex.php
Created November 4, 2013 12:07
IPv4 block IP PHP regex pattern
$patt='/^([1-9]?[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]){1}(\.|\.[1-9]?[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]){0,3}$/';
/**
* Valid IP address examples:
*
* 192.168.1.1
* 192.168.
* 192.168
*/
@egulhan
egulhan / urlEncodedCharList
Created November 6, 2013 08:21
Url encoded char. list
URL Encoded Characters
backspace %08
tab %09
linefeed %0A
creturn %0D
space %20
! %21
" %22
# %23
@egulhan
egulhan / Cipher.php
Last active December 29, 2015 00:09
Hash (encode/decode) test by a key
<?php
/**
* Cipher Class
*
* Ciphers text by user defined key.
* @date 2013-11-21
* @require php5-mcrypt
* @http://www.php.net/manual/en/function.mcrypt-encrypt.php#78531
* @http://stackoverflow.com/questions/1289061/best-way-to-use-php-to-encrypt-and-decrypt-passwords
@egulhan
egulhan / instanceByStaticFunction.php
Created November 21, 2013 19:50
Getting instance of an class via static function.
<?php
class SampleClass
{
static private $instance;
/**
* This implements the 'singleton' design pattern
*/
static function getInstance()