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
  • 12:09 (UTC +12:00)
View GitHub Profile
@cam8001
cam8001 / patch_name_generator.js
Created November 1, 2012 01:00
Bookmarklet to make Drupal.org issue micro-branch or patch name
javascript:alert(window.location.pathname.replace("/node/", '') + '-' + document.getElementsByTagName('h1')[0].innerHTML.replace(/'/g, '').replace(/[\s]/g, '-').toLowerCase());
@cam8001
cam8001 / field_formatter.module
Last active October 12, 2015 07:38
How to implement a custom field formatter
<?php
/**
* @file
* Sets up a field formatter, which can run custom theming or whatever else for a field.
*
* Once you have implemented the formatter, choose it on the 'display options' for a node.
*/
/**
@cam8001
cam8001 / gist:4016570
Created November 5, 2012 10:41
Drupal 6 syntax for theme_imagecache
<?php
// The raw path to the image.
$path = $node->field_product_image[0]['filepath'];
// Let imagecache generate a different sized image using 'Product_large'
$large_path = imagecache_create_url('Product_large', $path);
// Render the original image and save the path to the large one in the tag.
// Your output will be something like:
// <img src="blah.jpg" large_img="large-blah.jpg" class='img-swap' />
theme('imagecache', $path, '', '', array('large_img' => $large_path, 'class' => 'img-swap'));
@cam8001
cam8001 / gist:4046187
Created November 9, 2012 15:02
Hook node view implementation
/**
* Implements hook_node_view().
*/
function superpoll_node_view($node, $view_mode, $langcode) {
// Provide a link back to the parent poll on superpoll options.
if ($node->type == 'superpoll_option' && $view_mode == 'full') {
$node->content['linkback_to_poll'] = array(
'#theme' => 'superpoll_option_header',
'#title' => $node->title,
@cam8001
cam8001 / gist:4079725
Created November 15, 2012 16:53
sites.txt
13emerueuniversal.fr
13thstreet.de
13thstreet.pl
13thstreetuniversal.com.au
13thstreetuniversal.nl
calle13universal.es
divauniversal.asia
divauniversal.ro
divauniversal.ru
scifiuniversal.pl
@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 / homework.py
Created November 1, 2015 21:01
Cheatin' on homework
try:
number=int(raw_input("Enter the number you'd like to check here:"))
except ValueError:
print "Sorry, that isn't a number."
"""
multiply the first, third, fifth and seventh digits by 3, and then add the
resultants and the original other digits together to get a new number the
checksum
"""
@cam8001
cam8001 / test.php
Last active November 28, 2015 12:01
Test private/protected inheritance. run with `php -d display_errors test.php`
<?php
// Test private/public inheritance.
// run with `php -d display_errors test.php`.
class GotPrivate {
private $property = "Private Property: The dog goes woof.\n";
private function whatsUp() {
echo "Private Function: The dog also goes bark.\n";
}