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 / ScreenSizeCheck.js
Last active August 29, 2015 13:56
The easy way to find out your screen's dimensions -- with jQuery -- (works with PhoneGap).
console.log( "window=" + $(document).width() + "x" + $(document).height() );
@johnbocook
johnbocook / drupal_mail.php
Last active August 29, 2015 13:56
Module that will send email using drupal_mail. Drupal 7
<?php
/**
*
* Implements hook_menu()
* Call a custom form as menu callback
* @return
* $items array of menu items created programmatically
*/
function test_menu() {
@johnbocook
johnbocook / DynamicBackground.js
Created January 31, 2015 02:04
Gets pathname (domain.com/pathname) and add's background image of same name.
//Get Pathname and Add background image of path for dynamic backgrounds.
var loc = window.location.pathname.substring(1);
if (loc === '') {
$( "#marketing-header" ).css('background-image', 'url(/img/default-bg.jpg)');
} else {
$( "#marketing-header" ).css('background-image', 'url(/img/'+loc+'.jpg)');
};
@johnbocook
johnbocook / DrupalUploadRename.php
Created January 31, 2015 06:27
Rename Files on Upload in Drupal 7
/**
* Implements hook_file_insert().
*/
function MYMODULE_file_insert($file) {
$hash = 'public://' . md5($file->filename) . '.' . pathinfo($file->filename, PATHINFO_EXTENSION);
file_move($file, $hash, 'FILE_EXIST_REPLACE');
}
<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];
@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; 
@johnbocook
johnbocook / ProgramInjector.js
Created January 31, 2015 01:01
Populates Drupal 7 Webform select options based on Json object from another system
/* Author Note:
* Uses a Json object to populate Drupal 7's webform select options. You have to modify webform to accept external select options to be posted.
* On remote Json failure, A local Json object is loaded. I have a cron script that updates the Local Json object daily from remote server.
*/
//Remove required webform select option
$("#edit-submitted-programs-list option[value='NA']").each(function() {
$(this).remove();
});
//Get list of programs from Server
@johnbocook
johnbocook / urlParms.js
Created January 31, 2015 00:53
Takes parameters passed via URL and places them into Drupal 7 webform fields
/* Author Note:
* Captures URL parameters and inputs into Drupal webform
* Used for PPC Landing Page marketing. Passing SourceId, Adid, KwId to converted leads and submiting to database with lead.
* URL Ussage http://www.domain.com/?sid=Adwords&cmid=CampainID&adgid=AdGroupID&adid=AdID&kwid=KeyworkID
*/
//Split apart URL and extract Parameters
var parseQueryString = function() {
var str = window.location.search;
var objURL = {};
@johnbocook
johnbocook / PhoneFormatter.cfc
Last active November 5, 2015 13:23
Cold Fusion Componet to Clean and Format Phone Numbers
<cfscript>
function formatPhone(varInput) {
var curPosition = "";
var i = "";
var varMask = "(xxx) xxx-xxxx";
var newFormat = "";
var startpattern = "";
//Remove all non digits
varInput = ReReplace(trim(varInput), "[^[:digit:]]", "", "all");
@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