Skip to content

Instantly share code, notes, and snippets.

View johnbocook's full-sized avatar
💯
I come here for the dark theme.

John Bocook johnbocook

💯
I come here for the dark theme.
View GitHub Profile
@johnbocook
johnbocook / getQueryColumns.cfm
Last active November 5, 2015 13:25
Retrieve a list of column names in the order as defined by SQL for use with CFSpreadsheet (generating a header row) and other loop functions.
<cfscript>
function getQueryColumns(theQuery){
if(isQuery(theQuery)) return arraytoList(theQuery.getMeta().getColumnLabels());
else return '';
}
</cfscript>
<!--- Example --->
<cfquery name="GetOrders">
SELECT orderid, customerfirstname, customerlastname, total
@johnbocook
johnbocook / drupal_mail.php
Last active November 5, 2015 14:03
Use drupal_mail to send an email
<?php
/**
* Implements hook_menu()
* Call a custom form as menu callback
* @return
* $items array of menu items created programmatically
*/
function test_menu() {
$items['test'] = array(
@johnbocook
johnbocook / missing_images.js
Last active January 16, 2018 03:53
Use jQuery to deal with missing images
// Hide the image on error
$("img").error(function(){
$(this).hide();
});
// Change the missing image to a default image
$('img').error(function(){
$(this).attr('src', 'no-image.jpg');
});
@johnbocook
johnbocook / AutoFocusInput.js
Last active November 5, 2015 14:14
You can place a user's cursor inside an input via focus as soon as the page is loaded. This helps ensure that visitors do not 'overlook' an important form item on your site.
//Change coolFormName to form's name.
<body onload="document.coolFormName.user.focus();">
<form name="coolFormName">
Name: <input type=text name=user size=10>
</form>
@johnbocook
johnbocook / GoBackButton.js
Last active November 5, 2015 14:16
Sends visitor back one page in their browser history.
//Improper - Does not always work on chrome
<a href="www.mypage.com" onclick="history.go(-1)"> Back </a>
//Proper
<a href="www.mypage.com" onclick="window.history.go(-1); return false;"> Back </a>
@johnbocook
johnbocook / DateFormatter.js
Last active September 28, 2017 07:07
Display's the current date in this format: Friday, June 11, 2015.
<script language="JavaScript">
var now = new Date();
var days = new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
var months = new Array('January','February','March','April','May','June','July','August','September','October','November','December');
var date = ((now.getDate()<10) ? "0" : "")+ now.getDate();
function fourdigits(number) {
return (number < 1000) ? number + 1900 : number;
}
@johnbocook
johnbocook / YearlyAbortionCounter.js
Last active November 5, 2015 14:26
Yearly Abortion counter updated by seconds.
<html>
<head>
<link type="text/css" rel="stylesheet" href="stylesheet.css" media="all">
</head>
<body>
<div id="abCounter">
<p id="title">Yearly Abortion Counter</p>
<p id="aborts">Loading ...</p>
</div>
@johnbocook
johnbocook / MyOCU Drupal Error: file_put_contents.md
Last active February 6, 2016 01:07
When this error is recieved - How to resolve.

The administration->configuration->media->file system temorary directories either do not exist, or are not writeable.

Warning: 
file_put_contents(temporary://something.tmp):       
failed to open stream:                            
"DrupalTemporaryStreamWrapper::stream_open" call  
failed in file_unmanaged_save_data() (line 1936   
of temporary directory 
@johnbocook
johnbocook / isset_and_empty.md
Last active August 29, 2015 14:23 — forked from juampynr/isset_and_empty.md
Isset and Empty

When dealing with arrays in PHP, checking for an index like if ($a['foo']) throws a PHP warning.

There are two ways to avoid these warnings: one is using isset(), which checks the existance of an array index. The second one is empty(), which not only checks for the existence of the array index, but also that the value that contains is not empty (not NULL, 0, '' or FALSE).

Here are some console examples:

juampy@juampybox $ php -a
php > $a = array('foo' => 'asdfasd');
php &gt; 
<script>
lp.jQuery(function($) {
var ruleID = 'zipCode'
var field = 'zip_code';
var message = 'Please enter a valid ZIP code';
var rules = module.lp.form.data.validationRules[field];