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 / 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
*/
@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 / 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 / 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 / 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 / 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 / PHP Database Backup Script.php
Last active October 12, 2015 18:32
PHP Database Backup Script
<?php
backup_tables('localhost','root','','lores_new');
/* backup the db OR just a table */
function backup_tables($host,$user,$pass,$name,$tables = '*')
{
$link = mysql_connect($host,$user,$pass);
@sarfraznawaz2005
sarfraznawaz2005 / Nice extend function.js
Last active October 12, 2015 18:31
Nice extend function
Function.prototype.extends = function(parent) {
var sConstructor = parent.toString();
var aMatch = sConstructor.match( /\s*function (.*)\(/ );
if ( aMatch != null ) { this.prototype[aMatch[1]] = parent; }
for (var m in parent.prototype) {
this.prototype[m] = parent.prototype[m];
}
};
// Note not Dog = Dog.extends(Animal)
Dog.extends(Animal);
@sarfraznawaz2005
sarfraznawaz2005 / flatten multi-dimensional array.php
Last active October 12, 2015 18:31
flatten multi-dimensional array
<?php
/**
*
* @flatten multi-dimensional array
*
* @param array $array
*
* @return array
*
*/
@sarfraznawaz2005
sarfraznawaz2005 / Using length to truncate arrary.js
Last active October 12, 2015 18:31
Using length to truncate arrary
var foo = [1, 2, 3, 4, 5, 6];
foo.length = 3;
foo; // [1, 2, 3]