Skip to content

Instantly share code, notes, and snippets.

View AlexPashley's full-sized avatar

Alex Pashley AlexPashley

View GitHub Profile
@AlexPashley
AlexPashley / order.js
Created September 8, 2013 10:33
Order an array of objects with JavaScript Courtesy of david walsh: http://davidwalsh.name/array-sort
// sort scores in order
scores.sort( function(obj1, obj2) {
return obj1.attempts - obj2.attempts;
});
@AlexPashley
AlexPashley / check_file_is_audio.php
Created August 1, 2013 11:20
PHP: function to check if a file is an audio file, returns boolean response Requires PHP >= 5.3
/**
* Gets real MIME type and then see if its on allowed list
*
* @param string $tmp : path to file
*/
function check_file_is_audio( $tmp )
{
$allowed = array(
'audio/mpeg', 'audio/x-mpeg', 'audio/mpeg3', 'audio/x-mpeg-3', 'audio/aiff',
'audio/mid', 'audio/x-aiff', 'audio/x-mpequrl','audio/midi', 'audio/x-mid',
@AlexPashley
AlexPashley / csv_to_multi_array.php
Created July 23, 2013 12:33
PHP: Load a CSV file and convert it to a multi dimensional array
<?php
/**
* Converts CSV to multi dimensional array
*/
function csv_to_multidimension_array($filename='', $delimiter=',')
{
if(!file_exists($filename) || !is_readable($filename)) {
return false;
}
@AlexPashley
AlexPashley / redirect.php
Created July 22, 2013 09:05
PHP permanent redirect
<?php
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://www.example.co.uk");
?>
@AlexPashley
AlexPashley / aliases.bat
Created July 18, 2013 16:18
Makes windows command prompt emulate linux commands
@ECHO OFF
doskey ls=dir
doskey clear=cls
doskey 7z="C:\Program Files\7-Zip\7z.exe"
@AlexPashley
AlexPashley / mixins.scss
Created July 5, 2013 14:44
SASS: Mixins for CSS
/* MIXINs */
@mixin transition( $val : ease 0.5s ) {
-webkit-transition: $val;
-moz-transition:$val;
-o-transition:$val;
-ms-transition:$val;
transition:$val;
}
@mixin text-shadow( $top: 3px, $left: 3px, $blur: 3px , $colour: #333 ) {
@AlexPashley
AlexPashley / new_gist_file
Created July 3, 2013 22:05
JSON: Sublime Text 2 - Key Bindings
// hints
/*
# Ctrl + / # | comment line
# Ctrl + alt + x # | prefix css
# Ctrl + Shift + K # | Delete line
# Ctrl + Shift + a # | select text in <HTML> tag <p>[here]</p>
# Ctrl + ALT + M # | MINIFY SELECTED TEXT
*/
@AlexPashley
AlexPashley / hide php extension
Created July 3, 2013 22:02
APACHE: Hide .php extension with apache
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php
</IfModule>
@AlexPashley
AlexPashley / emailsFromCommandLine.sh
Created July 3, 2013 21:59
SHELL: Send emails from linux command line
# inline
mail -s "Subject of Message" [email protected] < /dev/null
# variables as parameters
$MSG="This is the body of the email address"
$SUBJET="Test Email Subject"
$ADDRESS="[email protected]"
echo $MSG | mail -s $SUBJECT $ADDRESS
@AlexPashley
AlexPashley / roundNearestMultiple.php
Created July 3, 2013 21:56
PHP: Round to nearest multiple with PHP
/**
* Round up to the nearest multiple of your choice.
*
* @param int $number
* @param int $near
* @return int
*/
function get_nearest_multiple( $number, $near )
{
$nearest = round($number/$near)*$near;