Skip to content

Instantly share code, notes, and snippets.

View cam8001's full-sized avatar
💭
lol no

Cameron Tod cam8001

💭
lol no
  • Amazon Web Services
  • Wellington, New Zealand
  • 01:26 (UTC +12:00)
View GitHub Profile
@cam8001
cam8001 / gist:4161656
Created November 28, 2012 14:31
Import translations po file on install.
/**
* Imports translations from a .po file into the local database.
*
* @param string $filepath
* Full filepath to a .po translations file.
*/
function maya_updates_api_import_translations($filepath, $langcode) {
_maya_updates_api_load_locale();
drupal_load('module', 'file');
watchdog(__FUNCTION__, 'Importing @file string translations.', array('@file' => $filepath), WATCHDOG_NOTICE);
@cam8001
cam8001 / gist:4176661
Created November 30, 2012 16:05
hook_menu_example
<?php
/**
* Implements hook_menu().
*/
function mymodule_menu() {
$items['user/%user/bb_licenses/%'] = array(
'title' => 'Saludar',
'page callback' => 'gestionar_licencia',
'page arguments' => array(1,3),
'type' => MENU_CALLBACK,
@cam8001
cam8001 / gist:4258295
Created December 11, 2012 12:43
Using preprocess_html to add custom classes to the HTML tag. Add to a file called template.php in the 'nes' theme.
<?php
/**
* Implements hook_preprocess_html().
*/
function nes_preprocess_html(&$variables) {
// Add some special classes to the HTML tag, so that we can style on a per-view basis.
// Get the current function handling the page.
$variables['menu_item'] = menu_get_item();
// If it is a views.module provided page, add some classes to the html tag.
@cam8001
cam8001 / content_by_friends.views_default.inc
Last active December 14, 2015 08:29
Drupal flag_friends: View of content by currently logged-in user's friends
$view = new view();
$view->name = 'user_content_friend';
$view->description = '';
$view->tag = 'default';
$view->base_table = 'users';
$view->human_name = 'User content friend';
$view->core = 7;
$view->api_version = '3.0';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
@cam8001
cam8001 / Add PECL library to hosting
Created March 11, 2013 15:25
How to add PECL source files (NOT binary modules) to Acquia hosting.
#!/bin/bash
$ pear install Net_SmartIRC
downloading Net_SmartIRC-1.0.2.tgz ...
Starting to download Net_SmartIRC-1.0.2.tgz (184,705 bytes)
........................................done: 184,705 bytes
install ok: channel://pear.php.net/Net_SmartIRC-1.0.2
# Now the class is downloaded to my local include path.
#!/bin/bash
TMP="/tmp"
DB_USER="root"
DB_PASSWD="password"
SITES_DIR="/var/www"
S3_BUCKET="s3://bucket-name"
DATE=$(date +%Y-%m-%d)
# Backup all databases to S3
for DB in $(mysql --user=$DB_USER --password=$DB_PASSWD -e 'show databases' -s --skip-column-names|grep -Ev "^(information_schema|performance_schema|mysql)$");
@cam8001
cam8001 / install_googlecl.sh
Created June 13, 2013 19:03
Installing googlecl on OS X
#!/bin/bash
brew install python
pip install http://googlecl.googlecode.com/svn/trunk/
google docs list
# Then this will happen:
# Please specify user: me@email.com
# Please log in and/or grant access at https://www.google.com/accounts/OAuthAuthorizeToken?oauth_token=NYAN-NYAN-NYAN&hd=email.com
# *your browser opens, you grant access, it gives you a token, you paste it in next*
# Please enter the verification code on the success page:
@cam8001
cam8001 / what_the.sh
Last active December 18, 2015 17:19
Speed difference between GNU grep and OSX 10.8 BSD grep
$ grep --version
grep (BSD grep) 2.5.1-FreeBSD
$ ggrep --version
ggrep (GNU grep) 2.14
# Here it goes
$ time cat varnish_log_200_only.txt | ggrep -F 'www.some.url.gov' | wc -l
957979
@cam8001
cam8001 / test.module
Created September 5, 2013 00:16
When using Scheduler to publish or unpublish nodes, update most recent node revision to have same author as node.
<?php
/**
* Implements hook_scheduler_api().
*
* @param $node
* The node object being acted upon.
* @param $action
* Action being performed. Either 'publish' or 'unpublish'.
*
* @see _scheduler_publish()
@cam8001
cam8001 / itunes_metadata_example.xml
Created September 12, 2013 14:26
iTunes basic film metadata example.
<?xml version="1.0" encoding="UTF-8"?>
<package xmlns="http://apple.com/itunes/importer" version="film4.5">
<provider>Paramount</provider>
<language>en-US</language>
<video>
<type>film</type>
<subtype>feature</subtype>
<vendor_id>09736156444</vendor_id>
<isan>0000-0000-03B6-0000-O-0000-0000-2</isan>
<upc>09736156444</upc>