Skip to content

Instantly share code, notes, and snippets.

View skwashd's full-sized avatar
👨‍💻
planning, coding, reviewing

Dave Hall skwashd

👨‍💻
planning, coding, reviewing
View GitHub Profile
@skwashd
skwashd / deploy_sevices_client.module
Last active December 21, 2015 14:18
Example deploy_services diff logic. Most of the hacks needed to make this work have been documented. This is a PoC, not production ready.
<?php
/**
* Implements hook_menu().
*/
function deploy_services_client_menu() {
$items = array();
//$items['job/%wf_job/diff/entities'] = array(
// dev hack
$items['job/123/diff/entities'] = array(
@skwashd
skwashd / mymodule.module
Created July 7, 2013 14:14
Extract a list of all Organic Groups groups with their names. Works with OG 7.x-2.x - tested with 7.x-2.2.
<?php
/**
* Extract a list of all available Organic Groups.
*
* This is ugly and inefficient, but it is the only way
* I could figure out how to do it, but hey it works.
*
* This is designed to work with OG 7.x-2.x
*
; Example drush make file using the github download type.
api = 2
core = 7
projects[] = drupal
; Module
projects[bean_boxes][type] = "module"
projects[bean_boxes][download][type] = "github"
@skwashd
skwashd / aliases.php
Last active December 10, 2015 01:28
Output PHP alias functions as a PHP array string. Code based on a conversation with klausi on #drupal-contribute.
<?php
/**
* Extract list of PHP function aliases and output it as a PHP array string.
*/
$source = file_get_contents('http://sprunge.us/EaEe');
$xml = new SimpleXMLElement($source);
echo "<php\n\$alises = array(\n";
@skwashd
skwashd / mymod.module.php
Created July 17, 2012 12:54
hook_entity_property_info snippet
<?php
// ...
$properties['url'] = array(
'label' => t('URL'),
'description' => t("The URL of the job's view page."),
'getter callback' => 'mymod_entity_metadata_get_properties',
'type' => 'uri',
'computed' => TRUE,
);
// ...
@skwashd
skwashd / typecast.php
Created June 24, 2012 07:16 — forked from berkes/typecast.php
gotcha with PHP typecasting
<?php
$amount = 12.50;
print (int) $amount * 100; # => 1200 # My implementation. I was wrong.
print (int) ($amount * 100); # => 1250 # After bugfix. PHP first casts, then multiplies.
@skwashd
skwashd / update-views.php
Created March 8, 2012 12:20
Update caching for a bunch of views
$res = db_query('SELECT * FROM views_display WHERE ...');
while ($record = db_fetch_array($res)) {
$options = unserialize($record['display_options']);
$options['cache'] = array(
'type' => 'time',
'results_lifespan' => 3600,
'output_lifespan' => 3600,
);
db_update('views_display')
@skwashd
skwashd / install-curl.sh
Created January 28, 2012 12:07
Quickly and easily install and configure cURL with SSL support on RHEL5 (and derivatives)
#!/bin/sh
#
# Install and configure cURL with SSL support on RHEL 5 (and derivatives)
#
yum install curl -y
wget http://curl.haxx.se/ca/cacert.pem -O /etc/pki/tls/certs/ca-bundle.crt
@skwashd
skwashd / PoliceCar
Created January 25, 2012 10:24
Arduino LeoStick "Police Car"
/**
* Arduino LeoStick "Police Car"
*
* Written by Dave Hall - http://davehall.com.au
*
* Licensed under the terms of the WTFPL - http://sam.zoy.org/wtfpl/
*/
int SPEAKER = 11;
int LED_GREEN = 9;
@skwashd
skwashd / drush-coder-review-recursive.sh
Created November 27, 2011 06:36
Run drush coder-review over all modules in a subdirectory. Some commonly used directories are excluded. This isn't perfect, but it will do.
for mod in $(find -maxdepth 2 -type d | egrep -v '\(.|.git|js|css|model|include|plugins\)$'); do name=$(echo $mod | sed -e 's/^.*\/\(.*\)$/\1/'); echo Processing $name; drush coder-review style comment security sql $name; done