Skip to content

Instantly share code, notes, and snippets.

View mikesprague's full-sized avatar

Michael Sprague mikesprague

View GitHub Profile
@mikesprague
mikesprague / convert-query-to-struct-array.cfm
Last active December 25, 2015 11:49
CFML: convertQueryToStructArray
<cfscript>
function convertQueryToStructArray( q ) {
var result = [];
for ( var row in arguments.q ) {
result.append( row );
}
return result;
}
@mikesprague
mikesprague / gist:5706268
Last active December 25, 2015 11:47
JavaScript: getRootWebSitePath
function getRootWebSitePath() {
var _location = document.location.toString();
var applicationNameIndex = _location.indexOf('/', _location.indexOf('://') + 3);
var applicationName = _location.substring(0, applicationNameIndex) + '/';
var webFolderIndex = _location.indexOf('/', _
location.indexOf(applicationName) + applicationName.length);
var webFolderFullPath = _location.substring(0, webFolderIndex);
return webFolderFullPath;
}
@mikesprague
mikesprague / gist:5721210
Created June 6, 2013 12:41
JavaScript: Math.round (modified to round number with decimal places)
Math.round = (function() {
var originalRound = Math.round;
return function(number, precision) {
precision = Math.abs(parseInt(precision)) || 0;
var multiplier = Math.pow(10, precision);
return (originalRound(number * multiplier) / multiplier);
};
})();
/*
example usage:
@mikesprague
mikesprague / Preferences.sublime-settings
Last active March 8, 2016 12:44
Sublime: My Default Settings
{
"Seti_SB_bright": true,
"Seti_SB_med": true,
"Seti_no_bar_undertabs": true,
"Seti_tabs_small": true,
"always_show_minimap_viewport": true,
"auto_complete_triggers":
[
{
"characters": "qazwsxedcrfvtgbyhnujmikolpQAZWSXEDCRFVTGBYHNUJMIKOLP",
@mikesprague
mikesprague / gist:5881937
Last active November 25, 2022 18:24
AWS: Bucket Policy Example (Allow Get by Referer)
{
"Version": "2008-10-17",
"Id": "http referer policy example",
"Statement": [
{
"Sid": "Allow get requests from certain domains (including local development)",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::bucket-name-here/*",
<?php
// define the path and name of cached file
$cachefile = 'cached-files/'.date('M-d-Y').'.php';
// define how long we want to keep the file in seconds. I set mine to 5 hours.
$cachetime = 18000;
// Check if the cached file is still fresh. If it is, serve it up and exit.
if (file_exists($cachefile) && time() - $cachetime < filemtime($cachefile)) {
include($cachefile);
exit;
}
@mikesprague
mikesprague / data-tables-server-side-example.cfm
Last active May 5, 2020 14:34
CFML: DataTables server-side code example from website
<cfscript>
/*
Script: DataTables server-side script for ColdFusion (short script style) and MySQL
License: GPL v2 or BSD (3-point)
ReWrite: 12/12/2011 John Fournier
Notes: Adobe ColdFusion 9 + limited inline documentation used, see other long examples for explanation
*/
datasource = 'jQueryDTable'; // set to your ColdFusion database
sTable = 'ajax'; // your table
aColumns = ['engine','browser','platform','version','grade']; // your columns
@mikesprague
mikesprague / gist:6000485
Created July 15, 2013 14:41
JavaScript: getObjectType() - Return object type
function getObjectType(obj) {
if(obj===null)return "[object Null]"; // special case
return Object.prototype.toString.call(obj);
}
@mikesprague
mikesprague / get-dominant-color.php
Created July 26, 2013 16:15
PHP: Get dominant color from an image (use final values get RGB value of dominant color, taken from: http://snipplr.com/view/67946/get-the-dominant-color-of-any-image/)
<?php
$i = imagecreatefromjpeg("image.jpg");
for ($x=0;$x<imagesx($i);$x++) {
for ($y=0;$y<imagesy($i);$y++) {
$rgb = imagecolorat($i,$x,$y);
$r = ($rgb >> 16) & 0xFF;
$g = ($rgb >> & 0xFF;
$b = $rgb & 0xFF;
img.grayscale {
filter: url("data:image/svg+xml;utf8,<svg xmlns=\'http://www.w3.org/2000/svg\'><filter id=\'grayscale\'><feColorMatrix type=\'matrix\' values=\'0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0 0 0 1 0\'/></filter></svg>#grayscale"); /* Firefox 10+, Firefox on Android */
filter: gray; /* IE6-9 */
-webkit-filter: grayscale(100%); /* Chrome 19+, Safari 6+, Safari 6+ iOS */
}
img.grayscale.disabled {
filter: url("data:image/svg+xml;utf8,<svg xmlns=\'http://www.w3.org/2000/svg\'><filter id=\'grayscale\'><feColorMatrix type=\'matrix\' values=\'1 0 0 0 0, 0 1 0 0 0, 0 0 1 0 0, 0 0 0 1 0\'/></filter></svg>#grayscale");
-webkit-filter: grayscale(0%);
}