Skip to content

Instantly share code, notes, and snippets.

Verifying that +mikealmond is my blockchain ID. https://onename.com/mikealmond
@mikealmond
mikealmond / mb_str_shorten.php
Created June 5, 2012 20:46
mb safe string shortener
<?php
function mb_str_shorten($content, $maxCharacters, $showDots = "&hellip;", $stopAtSpace = true, $encoding = 'UTF-8')
{
if(mb_strlen($content, $encoding) > $maxCharacters) {
if(!$stopAtSpace) {
return mb_substr($content, 0, $maxCharacters, $encoding) . $showDots;
} else {
$toReturn = mb_substr($content, 0, $maxCharacters, $encoding);
@mikealmond
mikealmond / fixPermissions.sh
Created February 22, 2012 15:01
Fix file and folder permissions on web roots
find . -type d -exec chmod u=rwx,g=rx,o=rx {} \;
find . -type f -exec chmod u=rw,g=r,o=r {} \;
@mikealmond
mikealmond / .aliases
Created February 17, 2012 21:50
The polite way to ask for a sandwich
alias please="sudo"
@mikealmond
mikealmond / script.js
Created February 7, 2012 02:43
Conditionally send data to a jQuery Ajax request
var data = {
'id': 1,
'body': $('#body').val()
};
if (hasTitle == true) {
data['title'] = $('#title').val();
}
$.post('/ajax/update-something', data, function (response) {
$('#template').html(response);
});
@mikealmond
mikealmond / gist:1677026
Created January 25, 2012 16:16
Swap the values in two variables without using a third variable in one line
<?php
$x = 'foo';
$y = 'bar';
$x ^= $y ^= $x ^= $y;
print $x; //bar
print $y; //foo
@mikealmond
mikealmond / gist:1670944
Created January 24, 2012 16:22
Uploading multiple files with HTML5 and PHP
<input type="file" multiple name="photos[]">
<?php
$total = count($_FILES['photos']['name']) - 1;
for ($i = 0; $i <= $total; $i++) {
uploadFile($_FILES['photos']['tmp_name'][$i]);
}