Skip to content

Instantly share code, notes, and snippets.

@tmbritton
tmbritton / gist:3178616
Created July 25, 2012 20:53
Execute MySQL Query
if($result = mysqli_query($link, $sql)){
while($row = mysqli_fetch_array($result)) {
//Do Stuff
}
} else {
echo mysqli_errno($link) . ": " . mysqli_error($link) . "\n";
}
@tmbritton
tmbritton / gist:3178741
Created July 25, 2012 21:20
Get File Extension
function getExtension($filename){
if($array = explode('.', $filename)){
$last = count($array) -1;
$ext = strtolower($array[$last]);
return $ext;
} else {
return FALSE;
}
}
@tmbritton
tmbritton / gist:3179265
Created July 25, 2012 23:09
Attempt to write images from Blobs
<?php
$db['hostname']='localhost';
$db['username']='root';
$db['password']='root';
$db['schema']='old_wkf';
if(!$link = mysqli_connect($db['hostname'], $db['username'], $db['password'])){
echo mysqli_errno($link) . ": " . mysqli_error($link) . "\n";
}
if(!mysqli_select_db($link, $db['schema'])){
@tmbritton
tmbritton / gist:3182671
Created July 26, 2012 15:22
Attempt to get WKF images from web service
<?php
$db['hostname']='localhost';
$db['username']='root';
$db['password']='root';
$db['schema']='wkf_salad_map';
date_default_timezone_set('America/Chicago');
$path = 'wkfimages/';
if(!$link = mysqli_connect($db['hostname'], $db['username'], $db['password'])){
echo mysqli_errno($link) . ": " . mysqli_error($link) . "\n";
@tmbritton
tmbritton / Drupal sort view by NIDs
Created October 11, 2012 20:29
Drupal sort view by NIDs supplied as an argument
$args = $view->args[0];
$exploded = explode('+',$args);
$flipped = array_flip($exploded);
if($flipped[$row1->nid] < $flipped[$row2->nid]) {
return 0;
} else {
return 1;
}
@tmbritton
tmbritton / gist:3914241
Created October 18, 2012 19:25
Parse response from Food52
function food52_parse_question_array($payload, $header) {
$results = drupal_json_decode($payload); // api returns double-encoded json
$out = '<h2>' . $header . '</h2>';
// We then iterate through the array to build questions
foreach ($results as $i) {
$question = drupal_json_decode($i);
// Title
$linkurl = $_SERVER['SERVER_NAME'] . '/hotline/';
$linkoptions = array(
'attributes' => array(
@tmbritton
tmbritton / afterimport.sh
Last active October 12, 2015 07:48
After Drupal DB import shell script
#!/bin/bash
#script to clean up after new Drupal import from prod
#execute from a directory inside your Drupal docroot
drush dis cdn --yes
drush en views_ui --yes
drush en devel --yes
drush en context_ui --yes
drush en stage_file_proxy --yes
drush vset preprocess_css 0 --yes
@tmbritton
tmbritton / readCookie.js
Created January 21, 2013 20:55
Javascript read cookie
/**
* Read cookie values by key name.
*
* @param: string - key value we're looking for in cookie
*/
function readCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
@tmbritton
tmbritton / urldecode.js
Created January 21, 2013 20:59
Javascript url decode
/**
* Decodes url encoded strings
*
* @param: string - url or email address we want to decode
*/
function urldecode(url) {
return decodeURIComponent(url.replace(/\+/g, ' '));
}
@tmbritton
tmbritton / gist:5172191
Created March 15, 2013 18:58
.vimrc backup
syntax on
set number
set tabstop=2