Skip to content

Instantly share code, notes, and snippets.

@joshuamilford
joshuamilford / gist:1076339
Created July 11, 2011 17:29
PHP Image Resizer
function resize($incoming, $max_width, $max_height, $crop = true){
$original_name = explode('.', $incoming);
$original_ext = strtolower(array_pop($original_name));
$original_name = implode('.', $original_name);
if(!file_exists($incoming)) $error = 'Original file doesn\'t exist.';
else{
if(!$original_info = getimagesize($incoming)) $error = 'Original file isn\'t a valid image.';
else{
$original_width = $original_info[0];
$original_height = $original_info[1];
function urlize($string){
return preg_replace('/\-+/', '-', preg_replace('/[^a-zA-Z\-_]/', '', preg_replace('/\s+/', '-', strtolower($string))));
}
function getNamed($string){
$bad = array(
'€' => '€',
'‚' => '‚',
'ƒ' => 'ƒ',
'„' => '„',
'…' => '…',
'†' => '†',
'‡' => '‡',
'ˆ' => 'ˆ',
@joshuamilford
joshuamilford / gist:1223002
Created September 16, 2011 20:06
mysql ucfirst
CONCAT(UPPER(SUBSTR(field,1,1)), SUBSTR(field, 2))
@joshuamilford
joshuamilford / gist:2050344
Created March 16, 2012 14:40
php typography-izer
//escape everything in tags
preg_match_all('/(\<[^\>]+\>)/', $string, $tags);
foreach($tags[0] as $key=>$value)
{
$string = str_replace($value, str_replace(array('"', "'"), array('\"', "\'"), $value), $string);
}
//replace double quotes
preg_match_all('/(?<!\\\)"([^"]+)"/', $string, $matches);
foreach($matches[0] as $key=>$value)
@joshuamilford
joshuamilford / gist:2263987
Created March 31, 2012 13:06
display errors
error_reporting(E_ALL);
ini_set("display_errors", 1);
@joshuamilford
joshuamilford / gist:3305603
Created August 9, 2012 16:22
Fluid Grid Maker
<?php
$width = 960;
$columns = 12;
$margin = 10;
$column = ($width / $columns) - (2 * $margin);
echo '<pre>';
$spans = '';
for($i = 1; $i <= 12; $i++)
{
$spans .= '.span_' . $i . ', ';
@joshuamilford
joshuamilford / gist:5483804
Created April 29, 2013 18:53
round difference between 2 times to nearest quarter hour.
((round(((strtotime($end) - strtotime($start)) / 60) / 15) * 15) / 60)
@joshuamilford
joshuamilford / gist:5483806
Created April 29, 2013 18:54
round difference between 2 times to nearest quarter hour.
((round(((strtotime($end) - strtotime($start)) / 60) / 15) * 15) / 60)
@joshuamilford
joshuamilford / test
Created May 8, 2013 14:52
This is a test gist
lorem ipsum