Skip to content

Instantly share code, notes, and snippets.

@robballou
robballou / move_feature.sh
Created June 7, 2012 17:35
Move a feature tar file into the drupal directory
#!/bin/bash
#
# Move the feature tar file contents into your site and remove it
#
# Usage:
# move_feature.sh [feature file] [drupal directory]
#
#
<?php
function my_module_form($form, &$form_state) {
$form['sample_field'] = array(
'#type' => 'checkboxes'
'#title' => 'Sample',
'#options' => array('test' => 'Test')
);
$form['select_box'] = array(
@robballou
robballou / myip.sh
Created May 25, 2012 20:42
What is my IP?
#!/bin/bash
IP=`curl -s http://whatismyip.org/`
echo $IP
@robballou
robballou / gist:2704120
Created May 15, 2012 18:48
Custom Module block code
<?php
// hook_block_info
/**
* Our block specific code
*/
function custom_module_block_view($delta = '') {
if ($delta == ''){
// current node
@robballou
robballou / gist:2703698
Created May 15, 2012 17:53
Custom Module basic block hooks
<?php
/**
* Implements hook_block_info
*/
function custom_module_block_info() {
$blocks['custom_module_my_block'] = array(
'info' => t('My block'),
'cache' => DRUPAL_CACHE_PER_PAGE,
);
@robballou
robballou / gist:2589066
Created May 3, 2012 20:36
custom_content_pages example page callback #1
<?php
function custom_content_pages_about() {
// load our content: since our path starts with the alias for this
// node, we can lookup the node source that way
$node_path = drupal_lookup_path('source', arg(0) .'/'. arg(1));
// now we can the actual node
$node = menu_get_object('node', 1, $node_path);
// set the title
@robballou
robballou / gist:2589032
Created May 3, 2012 20:28
custom_content_pages example hook_menu() implementation
<?php
/**
* Implement hook_menu()
*/
function custom_content_pages_menu() {
$items['custom/%/about'] = array(
'page callback' => 'custom_content_pages_about',
'access arguments' => array('access content'),
);
<?php
/*
Based on rules from http://en.wikipedia.org/wiki/Roman_numerals
*/
function romanToInt($roman){
$int = 0;
$characters = str_split($roman);
$previous = null;
$values = array('I' => 1, 'V' => 5, 'X' => 10, 'L' => 50, 'C' => 100, 'D' => 500, 'M' => 1000);
foreach($characters as $character){
<?php
$names = 'Jeff';
// if User() is a class, this will be an error since classes are not callable. If it
// is a class then it would be "new User();"
$user = User();
// $names is not iterable, so this will error out
foreach($names as $name)
{
<?php
/*
I felt it was best to treat this a bit more completely by pulling in an open source library.
So, cheating a bit and using simplehtmldom since it's best if we account for
both href & target attributes (if a link has a target, we don't want to repeat it)
http://simplehtmldom.sourceforge.net/
A solution without using this library could use preg_match_all to parse out the href's but