Skip to content

Instantly share code, notes, and snippets.

@adaptive
adaptive / gist:14936
Created October 5, 2008 21:17
generating hashes in php (SHA-256, SHA-512)
<?php
// SHA-256, SHA-512
$var = 'lorem ipsum';
$hash256=hash('sha256', $var);
$hash512=hash('sha512', $var);
echo $hash256 $hash512;
?>
@mpezzi
mpezzi / gist:849284
Created March 1, 2011 15:22
PHP Array of Countries
<?php
$countries = array(
'AF' => 'Afghanistan',
'AL' => 'Albania',
'DZ' => 'Algeria',
'AS' => 'American Samoa',
'AD' => 'Andorra',
'AO' => 'Angola',
'AI' => 'Anguilla',
@mncaudill
mncaudill / similar.php
Created October 31, 2011 05:33
PHP version of simple image similarity algorithm
<?php
# Algorithm found here: http://www.hackerfactor.com/blog/index.php?/archives/432-Looks-Like-It.html
$filename = 'image.jpg';
list($width, $height) = getimagesize($filename);
$img = imagecreatefromjpeg($filename);
$new_img = imagecreatetruecolor(8, 8);
@d3nj3ll
d3nj3ll / autosave.js
Created January 19, 2012 13:50
Client-side Autosave Using localStorage with jQuery in textarea
$(document).ready(function() {
///////////////////////
//
// Recovery Below
//
///////////////////////
// Retrieve the object from storage onReady
var autosave = localStorage.getItem('file');
@agarzon
agarzon / random_color.php
Last active September 11, 2023 17:04
PHP Random Color Generator Hex
<?php $color = dechex(rand(0x000000, 0xFFFFFF)); ?>
<body style="background-color: <?php echo $color; ?>;">
<h1><?php echo $color ?></h1>
</body>
@jonathanmoore
jonathanmoore / gist:2640302
Created May 8, 2012 23:17
Get the share counts from various APIs

Share Counts

I have always struggled with getting all the various share buttons from Facebook, Twitter, Google Plus, Pinterest, etc to align correctly and to not look like a tacky explosion of buttons. Seeing a number of sites rolling their own share buttons with counts, for example The Next Web I decided to look into the various APIs on how to simply return the share count.

If you want to roll up all of these into a single jQuery plugin check out Sharrre

Many of these API calls and methods are undocumented, so anticipate that they will change in the future. Also, if you are planning on rolling these out across a site I would recommend creating a simple endpoint that periodically caches results from all of the APIs so that you are not overloading the services will requests.

Twitter

@picandocodigo
picandocodigo / create_thumbnails.sh
Created May 15, 2012 14:46
Create thumbnails from images in a directory (with Imagemagick)
for i in *.jpg; do
convert -thumbnail 200 $i thumb.$i
done
@cam-gists
cam-gists / phone.php
Created November 28, 2012 21:33
PHP: format Phone Number
function format_phone($phone)
{
$phone = preg_replace("/[^0-9]/", "", $phone);
if(strlen($phone) == 7)
return preg_replace("/([0-9]{3})([0-9]{4})/", "$1-$2", $phone);
elseif(strlen($phone) == 10)
return preg_replace("/([0-9]{3})([0-9]{3})([0-9]{4})/", "($1) $2-$3", $phone);
else
return $phone;
@iwek
iwek / html5-blank-template
Created January 19, 2013 03:50
HTML5 Blank Template with jQuery
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Blank HTML5</title>
<style>
</style>
</head>
<body>
@irazasyed
irazasyed / random_strgenerator.php
Last active December 3, 2020 03:13
PHP: Generate random string
/**
* Generate and return a random characters string
*
* Useful for generating passwords or hashes.
*
* The default string returned is 8 alphanumeric characters string.
*
* The type of string returned can be changed with the "type" parameter.
* Seven types are - by default - available: basic, alpha, alphanum, num, nozero, unique and md5.
*