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 / footerInGridView.php
Created April 10, 2014 07:39
Footer column usage in GridView, Yii
<?php
/**
* Can be used as sum of a column
*/
...
array(
'name'=>'first_col',
'footer'=>'<b>TOTAL:</b>'
),
@egulhan
egulhan / convertBytes.php
Created April 17, 2014 11:47
Convert bytes to up-sizes
/**
* @source: http://codeaid.net/php/convert-size-in-bytes-to-a-human-readable-format-(php)
*/
function bytesToSize1024($bytes, $precision = 2)
{
$unit = array('B','KB','MB','GB','TB','PB','EB');
return @round($bytes / pow(1024, ($i = floor(log($bytes, 1024)))), $precision).' '.$unit[$i];
}
@egulhan
egulhan / multipleInheritance.php
Created May 16, 2014 13:15
PHP does not support multiple inheritance. This shows how to make it possible.
// Source: http://stackoverflow.com/a/356431
class B {
public function method_from_b($s) {
echo $s;
}
}
class C {
public function method_from_c($s) {
@egulhan
egulhan / cpuUsageInPercent.sh
Created June 11, 2014 14:07
How to get CPU usage in percent on Linux
top -bn1 | grep "Cpu(s)" | sed "s/.*, *\([0-9.]*\)%* id.*/\1/" | awk '{print 100 - $1"%"}'
@egulhan
egulhan / base64.js
Last active December 21, 2017 12:03
Encode/decode with/from base64 in Javascript
/**
* Base64 encode / decode
* http://www.webtoolkit.info/
* @source: http://www.webtoolkit.info/javascript-base64.html
*
*/
var Base64 = {
/**
* Base 64 char set
*/
@egulhan
egulhan / downloadFile.php
Created June 30, 2014 11:54
Make browser download a file without saving the it.
@source: http://php.net/manual/en/function.readfile.php
<?php
$file = 'monkey.gif';
if (file_exists($file)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($file));
header('Expires: 0');
@egulhan
egulhan / fileSizeConvert.php
Created June 30, 2014 11:59
Converts bytes into human readable file size
@source: http://www.php.net/manual/en/function.filesize.php#112996
<?php
/**
* Converts bytes into human readable file size.
*
* @param string $bytes
* @return string human readable file size (2,87 Мб)
* @author Mogilev Arseny
*/
@egulhan
egulhan / base64UsingJquery.js
Created July 1, 2014 07:24
Encode/decode with/from base64 using jQuery
@source: http://www.naveen.com.au/javascript/jquery/encode-or-decode-html-entities-with-jquery/289
function htmlEncode(value){
if (value) {
return jQuery('<div />').text(value).html();
} else {
return '';
}
}
@egulhan
egulhan / mime-types.php
Created July 2, 2014 10:34
Learn mime-types from extension name and vice-versa in PHP
<?php
/*
* @source http://stackoverflow.com/questions/1147931/how-do-i-determine-the-extensions-associated-with-a-mime-type-in-php
*/
function system_extension_mime_types() {
# Returns the system MIME type mapping of extensions to MIME types, as defined in /etc/mime.types.
$out = array();
$file = fopen('/etc/mime.types', 'r');
@egulhan
egulhan / just-microsoft-office-file-type-list.php
Last active March 2, 2023 06:44
List of MIME types as PHP array
<?php
/**
* List of Microsoft office file MIME types
* @date 2014-07-09
*/
return array(
'doc'=>'application/msword',
'dot'=>'application/msword',