Skip to content

Instantly share code, notes, and snippets.

@dustincurrie
dustincurrie / sanitize.sh
Created December 1, 2010 20:21
Sanitize user table in Drupal with Drush
#!/bin/bash
drush sqlq "UPDATE {users} SET pass = md5('pass') WHERE uid > 1;"
drush sqlq "UPDATE {users} SET mail = concat('myaddr+', replace(mail, '@', '_'), '@testdomain.org') WHERE uid <> 0 AND instr(mail, '@testdomain.org') = 0;"
@dustincurrie
dustincurrie / gist:724169
Created December 1, 2010 20:36
Theme node body with a template file in the feature
<?php
/**
* Implementation of hook_theme().
* DRUPAL WONT SEE THIS HOOK UNTIL YOU CLEAR YOUR CACHE
*/
//Create myfeature-node-body.tpl.php in your feature and use $node to theme the node body
@dustincurrie
dustincurrie / gist:724183
Created December 1, 2010 20:39
Show background image in jquery cycle on IE
/*
jQuery Cycle has a bug in IE 7 and 8 where a white background is added to cycle elements. That will override background images. If your cycle object has a background image and you use the cleartype fix, the background won't show. Cycle has a property 'cleartypeNoBg' to address this issue. Set the property to true.
*/
$('.mycycleclass')
.cycle({
fx: 'scrollHorz',
cleartype: true,
cleartypeNoBg: true,
});
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Crash IE6 + IE7</title>
<!--[if IE 6]>
<script>
for (x in document.write) {
document.write(x);
}
@dustincurrie
dustincurrie / gist:729560
Created December 5, 2010 22:46
Safely turn string variable in Drupal (i.e. listing of paths in textfield) into an array and back to a string
<?php
$array = preg_split('/\n/', trim(variable_get('string_variable', '')));
//add remove entries in the array
variable_set('string_variable', implode("\n", $array));
@dustincurrie
dustincurrie / gist:750719
Created December 21, 2010 22:18
Create sql user and database
CREATE DATABASE databasename;
CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON databasename.* TO 'username'@'localhost';
FLUSH PRIVILEGES;
@dustincurrie
dustincurrie / gist:895383
Created March 30, 2011 21:47
Calculate size of all MySQL databases
SELECT s.schema_name, CONCAT(IFNULL(ROUND(SUM(t.data_length)/1024/1024,2),0.00),"Mb") as Data_size,
CONCAT(IFNULL(ROUND(SUM(t.index_length)/1024/1024,2),0.00),"Mb") as Index_size,COUNT(table_name) total_tables
FROM INFORMATION_SCHEMA.SCHEMATA s
LEFT JOIN INFORMATION_SCHEMA.TABLES t ON s.schema_name = t.table_schema
WHERE s.schema_name not in("mysql","information_schema","test") GROUP BY s.schema_name order by Data_size DESC;
@dustincurrie
dustincurrie / gist:938829
Created April 23, 2011 17:53
Programmatically create quicktabs
<?php
function mymodule_block($op = 'list', $delta = 0, $edit = array()) {
switch($op) {
case 'list':
$blocks['mymodule_quicktabs'] = array('info' => t('[mymodule] Quicktabs'));
return $blocks;
break;
case 'view':
switch ($delta) {
@dustincurrie
dustincurrie / gist:965993
Created May 11, 2011 06:01
Load a block in Drupal
<?php
$block = module_invoke('module_name', 'block', 'view', 'block_delta');
@dustincurrie
dustincurrie / elb.sh
Created August 18, 2011 06:18
Run a command on all instances attached to an AWS ELB
#!/bin/bash
# Runs a command on all instances attached to a load balancer
# Elastic Load Balancer Tools from http://aws.amazon.com/developertools/2536
ELB=prod-axs-aeg
COMMAND='service varnish restart'
INSTANCES=$(elb-describe-instance-health $ELB | awk -F " " '{print $2}')