Skip to content

Instantly share code, notes, and snippets.

View pfaocle's full-sized avatar

Paul Byrne pfaocle

View GitHub Profile
@pfaocle
pfaocle / sql_sync_wrapper.drush.inc.php
Last active December 21, 2015 22:09
An example of how to create a new Drush command which wraps an existing command.
<?php
/**
* @file
* An example of how to create a new Drush command which wraps an existing command, allowing some customisation.
*
* Note any file containing this snippet should be suffixed '.drush.inc', not '.drush.inc.php'.
*/
/* Implements COMMANDFILE_drush_command(). */
function sql_sync_wrapper_drush_command() {
@pfaocle
pfaocle / exiftool-fiddle.sh
Last active December 21, 2015 03:19
Use exiftool to fiddle the dates on photos (when I forget to set the date/time correctly on my camera).
#!/bin/sh
FILE_FORMAT="JPG"
# Show dates of all JPG files in current directory, in human readable format.
exiftool -d '%r %a, %B %e, %Y' -DateTimeOriginal -S -s -ext $FILE_FORMAT .
# Fiddle the dates - some date fields forward.
# Format is Y:M:D h:m:s
exiftool -F -AllDates+="2:6:0 0" *$FILE_FORMAT
@pfaocle
pfaocle / sql-long-lines.sh
Created July 4, 2013 15:37
Check a SQL dump for the longest line and either outputs the line, or a character count.
# Output longest line to bigfile.txt
cat ./local.sql | awk ' { if ( length > x ) { x = length; y = $0 } }END{ print y }' > bigfile.txt
# Count characters in longest line
cat ./local.sql | awk ' { if ( length > x ) { x = length; y = $0 } }END{ print y }' | wc -m
@pfaocle
pfaocle / SaveFileEntityDisplaySettings.php
Created June 3, 2013 21:41
Save File Entity file display settings in code - uses CTools exportables.
<?php
// We assume that a custom module is implementing a file formatter
// called 'mymodule_custom_file_formatter'.
$filetype = 'video'; // File type to alter file display for.
$display = 'preview'; // File display to alter - 'default', 'teaser' or 'preview'.
$video_display = file_display_new($filetype, $display, 'mymodule_custom_file_formatter');
$video_display->export_type = 1;
@pfaocle
pfaocle / date-form.php
Created September 27, 2012 19:22
PHP for CMS Developers - DateTime exercise
<html>
<head>
<title>PHP for CMS Developers - Exercise 1</title>
</head>
<body>
<p>Enter a date, using a format understood by <a href="http://php.net/manual/en/class.datetime.php">http://php.net/manual/en/class.datetime.php</a></p>
@pfaocle
pfaocle / phpfordevelopers-exercises.php
Last active December 22, 2015 15:04
PHP for CMS Developers - Classes & Exceptions exercises
// "Main"
<?php
/**
* PHP for Developers - Exercises
*
* main/testing
*/
spl_autoload_register(function ($class_name) {