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 / index.sh
Created August 13, 2011 08:35
Index all of your articles
View index.sh
#!/bin/bash
#
# Add all of your Drupal nodes to the search index.
#
# NOTE:
# * This should work when you have around 10 000 nodes.
# * I assume you have set search to add 500 nodes per cron run.
# * There are better ways of doing this, but it does the job.
#
@skwashd
skwashd / site-up.py
Created September 18, 2011 13:52
Python script to check if a remote site is up and measure the load time. Ideal for running from cron.
View site-up.py
#!/usr/bin/env python
#
# Check if a website is loading and contains a nominated string.
#
# Usage:
# site-up.py http://example.com/ 'text to search for'
#
@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.
View drush-coder-review-recursive.sh
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
@skwashd
skwashd / PoliceCar
Created January 25, 2012 10:24
Arduino LeoStick "Police Car"
View PoliceCar
/**
* 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 / install-curl.sh
Created January 28, 2012 12:07
Quickly and easily install and configure cURL with SSL support on RHEL5 (and derivatives)
View install-curl.sh
#!/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 / update-views.php
Created March 8, 2012 12:20
Update caching for a bunch of views
View update-views.php
$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 / typecast.php
Created June 24, 2012 07:16 — forked from berkes/typecast.php
gotcha with PHP typecasting
View typecast.php
<?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 / mymod.module.php
Created July 17, 2012 12:54
hook_entity_property_info snippet
View mymod.module.php
<?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 / 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.
View aliases.php
<?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";
View example.make
; 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"