Skip to content

Instantly share code, notes, and snippets.

View sarfraznawaz2005's full-sized avatar
🏠
Working from home

Sarfraz Ahmed sarfraznawaz2005

🏠
Working from home
View GitHub Profile
@sarfraznawaz2005
sarfraznawaz2005 / Image2HTML.php
Last active October 12, 2015 18:32
Image2HTML
<?php
function img2html($image, $letters='') {
/*
img2html:
takes an image as an array of data that is created by PHP
for uploaded files.
*/
$suffix = preg_replace('%^[^/]+/%', '', $image['type']);
$getimagefunc = "imagecreatefrom$suffix";
@sarfraznawaz2005
sarfraznawaz2005 / Simple function to benchmark code.php
Last active October 12, 2015 18:32
Simple function to benchmark code
<?php
function benchmark($function, $args = null, $iterations = 1, $timeout = 0)
{
set_time_limit($timeout);
if (is_callable($function) === true) {
list($usec, $sec) = explode(" ", microtime());
$start = ((float)$usec + (float)$sec);
@sarfraznawaz2005
sarfraznawaz2005 / PHP Toggle Encypt Decrypt Function.php
Last active October 12, 2015 18:32
PHP Toggle Encypt Decrypt Function
<?php
function toggleEncryption($text, $key = '') {
// return text unaltered if the key is blank
if ($key == '') {
return $text;
}
// remove the spaces in the key
$key = str_replace(' ', '', $key);
@sarfraznawaz2005
sarfraznawaz2005 / Short URLs using bit.ly.php
Last active October 12, 2015 18:32
Short URLs using bit.ly
<php
function shortURL($url)
{
$url = urlencode($url);
$ch = curl_init('http://api.bitly.com/v3/shorten?login=sarfraznawaz2005&apiKey=R_182a565c28e4eafd0e23aa113464e73e&longUrl=' . $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
$resultArray = json_decode($result, true);
$shortURL = $resultArray['data']['url'];
@sarfraznawaz2005
sarfraznawaz2005 / Accessing Joomla Framework Outside of Joomla.php
Last active October 12, 2015 18:32
Accessing Joomla Framework Outside of Joomla
<?php
// include the following at the top of your script
define( '_JEXEC', 1 );
define('JPATH_BASE', dirname(dirname(__FILE__)));
define( 'DS', DIRECTORY_SEPARATOR );
require_once (JPATH_BASE . DS . 'includes' . DS . 'defines.php');
require_once (JPATH_BASE . DS . 'includes' . DS . 'framework.php');
$mainframe = JFactory::getApplication('site');
//From there you can do normal development as if you were inside of Joomla's framework
@sarfraznawaz2005
sarfraznawaz2005 / log php vars to custom browser console.php
Last active October 12, 2015 18:33
check/log php vars to custom browser window/console
<?php
/**
* varLog
*
* Logs messages/variables/data to browser by creating custom console/floating window at bottom
*
* @param $name
* @param $data
* @author Sarfraz
*/