Skip to content

Instantly share code, notes, and snippets.

View haroonabbasi's full-sized avatar
💭
always looking out for new tools new libraries

Haroon Abbasi haroonabbasi

💭
always looking out for new tools new libraries
  • Lahore
View GitHub Profile
class FileManager
{
/**
* Returns content of given file
*
* @access public
* @param string
* @return string
*/
public function readFile($path)
@haroonabbasi
haroonabbasi / AppError.php
Created September 24, 2014 08:32
Error Handler Class Log Error/Exceptions in log file. From http://clivern.com/php-errors-handling/
class App_Error extends Exception
{
private $error_log;
private $log_file = "log/error_log.php";
public function __construct($message)
{
parent::__construct($message);
$file = basename($this->file);
@haroonabbasi
haroonabbasi / laravel
Created September 25, 2014 13:27
Laravel Awesome List
packages.
http://packalyst.com
code templates
http://laravel-recipes.com
http://clivern.com/
schema designer
http://laravelsd.com/
Eloquent ORM
@haroonabbasi
haroonabbasi / new_gist_file.php
Created November 21, 2014 11:13
Updated Index for Resulted array in cakephp
function updateIndex($array) {
if (isset($array)) {
$result = array();
foreach ($array as $inner) {
$result[key($inner)][] = current($inner);
}
return $result;
} else {
return NULL;
}
function get_mime_type($file)
{
        // our list of mime types
        $mime_types = array(
                "pdf"=>"application/pdf"
                ,"exe"=>"application/octet-stream"
                ,"zip"=>"application/zip"
                ,"docx"=>"application/msword"
                ,"doc"=>"application/msword"
@haroonabbasi
haroonabbasi / new_gist_file.php
Created November 21, 2014 11:50
EmailToName
function EmailToName($email) {
$output = str_replace(array('.', '-', '_', ',', ':'), ' ', substr($email, 0, strpos($email, '@')));
$output = str_replace(array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9), '', $output);
$output = ucwords($output);
return $output;
}
@haroonabbasi
haroonabbasi / new_gist_file.php
Created November 21, 2014 11:51
isEmail Mail Validator Function
public static function isEmail($email) {
if(filter_var($email, FILTER_VALIDATE_EMAIL)) {
return TRUE;
} else {
return FALSE;
}
}
@haroonabbasi
haroonabbasi / new_gist_file.php
Created November 21, 2014 11:52
Php PDO Conection
try {
$conn = new PDO('mysql:host=localhost;dbname=myDatabase', $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch(PDOException $e) {
echo 'ERROR: ' . $e->getMessage();
}
@haroonabbasi
haroonabbasi / new_gist_file.php
Created November 21, 2014 11:58
Array To CSV
function toCSV(array $data, array $colHeaders = array(), $asString = false) { 
    $stream = ($asString)
        ? fopen("php://temp/maxmemory", "w+")
        : fopen("php://output", "w"); 
 
    if (!empty($colHeaders)) {
        fputcsv($stream, $colHeaders); 
    }
 
    foreach ($data as $record) {
@haroonabbasi
haroonabbasi / new_gist_file.php
Created November 21, 2014 11:59
Get Real IP Address
function GetRealIpAddress(){
if (!empty($_SERVER['HTTP_CLIENT_IP'])){
//check ip from share internet
$ip = $_SERVER['HTTP_CLIENT_IP'];
}
elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])){
//to check ip is pass from proxy
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
}
else{