Skip to content

Instantly share code, notes, and snippets.

@banksy89
banksy89 / gist:4960692
Last active December 13, 2015 19:09
Rake file for calling all PHPUnit unit tests within a directory
# setting the path of Admin suite unit tests
admin_units = "admin/tests/units"
desc "Testing all admin unit tests"
task :admin_units do
puts "Going to test all unit tests now....hold tight...."
tests = Dir.entries(admin_units)
tests.each do |file|
if file != '.' && file != '..'
units = Dir.entries("#{admin_units}/#{file}")
@banksy89
banksy89 / Years between two dates
Created August 29, 2012 13:18
Get the number of years between two dates using PHP DateTime class
// My Birthday :)
$date_1 = new DateTime( '1989-06-15' );
// Todays date
$date_2 = new DateTime( date( 'Y-m-d' ) );
$difference = $date_2->diff( $date_1 );
// Echo the as string to display in browser for testing
echo (string)$difference->y;
@banksy89
banksy89 / gist:3334259
Created August 12, 2012 20:32
Returns the path of a given Twitter usernames avatar
function getTwitterAvatar ( $username )
{
$twitter_xml = simplexml_load_file ( "http://twitter.com/users/".$username.".xml" );
return $twitter_xml->profile_image_url;
}
@banksy89
banksy89 / Displaying Main YouTube Video Image
Created July 3, 2012 16:44
Gets the main image for a YouTube image, to be used for a placeholder.
function getYouTubeKey ( $video )
{
preg_match ( '#\\?v=([^&]+)\\&#s', $video, $vid );
if ( count ( $vid ) > 0 )
{
// The correct match is the second item in array
return $vid[ 1 ];
}
else
@banksy89
banksy89 / gist:2788320
Created May 25, 2012 14:06
PHP - Function for getting Long and Lat from Google & a function for calculating distance between two Lat and Longs
function getLatLong ( $postcode )
{
$pc = preg_replace ( '/\s/', '', $postcode );
$pc = 'http://maps.google.com/maps/geo?q='.$pc.',+UK&output=csv&sensor=false';
$result = explode ( ",", file_get_contents ( $pc ) );
return array ( $result[ 2 ], $result[ 3 ] );
}
function getSourceCode ( $website )
{
// The link to the website
$code_lines = file ( 'http://webite.com' );
// Loop through the code and build string
foreach ( $code_lines as $line => $code )
$lines .= "<strong>{$line}. </strong> " . htmlspecialchars( $code ) . "</ br>\n";
return $lines;
@banksy89
banksy89 / gist:2788298
Created May 25, 2012 13:58
PHP - Count the number of Facebook Fans a page has
function facebook_fans ( $fb_page )
{
$data = json_decode( file_get_contents( "https://graph.facebook.com/" . $fb_page ) );
echo $data->likes;
}
@banksy89
banksy89 / gist:2701064
Created May 15, 2012 11:39
Finds the most common value within an array.
function commonValue ( $array )
{
$counted = array_count_values ( $array );
arsort ( $counted );
return ( key ( $counted ) );
}