Skip to content

Instantly share code, notes, and snippets.

@stewartduffy
stewartduffy / gist:1481230253d6fbc366df
Created March 3, 2015 22:57
Create GUID / UUID in JavaScript
function guid() {
function s4() {
return Math.floor((1 + Math.random()) * 0x10000)
.toString(16)
.substring(1);
}
return s4() + s4() + '-' + s4() + '-' + s4() + '-' +
s4() + '-' + s4() + s4() + s4();
}
@stewartduffy
stewartduffy / gist:6bd7fad208bf98043966
Last active August 29, 2015 14:16
JS get calculate GST
var calculateGst = function(price, taxRate) {
return (price * (taxRate * 100) / 100).toFixed(2);
};
var addGst = function(price, taxRate) {
return (price * 1 + ( price * (taxRate * 100) / 100 )).toFixed(2);
};
@stewartduffy
stewartduffy / gist:f6b774deeb8ed735db29
Created February 26, 2015 21:32
JS function to get file name (without path or file extention)
var fileName = function(filePath) {
var filename = filePath.split("/");
return filename[filename.length - 1].replace(/\.[^/.]+$/, "");
};
var filePath = "/downloads/tm/logos/IMG_30012014_185815.png";
console.log( fileName(filePath) );
@stewartduffy
stewartduffy / gist:481f21ea4906e611d934
Last active August 10, 2022 03:03
Regex to remove file extension from JS string.
var filenameFull = "tm_icons.png";
//Regex to remove
var filenameText = filenameFull.replace(/\.[^/.]+$/, "");
/**
*
* Name v0.0.1
* Description, by Chris Ferdinandi.
* http://gomakethings.com
*
* Free to use under the MIT License.
* http://gomakethings.com/mit/
*
*/
# Terminal Cheat Sheet
pwd # print working directory
ls # list files in directory
cd # change directory
~ # home directory
.. # up one directory
- # previous working directory
help # get help
-h # get help
function throttle( fn, time ) {
var t = 0;
return function() {
var args = arguments, ctx = this;
clearTimeout(t);
t = setTimeout( function() {
fn.apply( ctx, args );
}, time );
};
@stewartduffy
stewartduffy / array_import.php
Created May 14, 2013 09:32
Import php array into PODS table, WordPress
<?php
$data = array(
"Performance Coaching",
"Principal Responsibilities of Leadership",
"Strategic Performance Template",
"Team Performance Compact",
"Team Performance One",
"Management Performance Compact",
"Management Performance One",
"Leadership Performance Compact",
@stewartduffy
stewartduffy / wp_upload_limit.php
Created May 14, 2013 09:26
Chuck this in your .htaccess file to Increase upload limit in wordpress with .htaccess file
php_value upload_max_filesize 64M
php_value post_max_size 64M
php_value max_execution_time 300
php_value max_input_time 300
@stewartduffy
stewartduffy / double_where_clause.php
Created May 14, 2013 09:19
PODS CMS pods double where clause
<?php
/*
Template Name: Month Page Template
*/
?>
<?php
$found_month = false;
global $pods;
$month_slug = pods_url_variable(-1);