Skip to content

Instantly share code, notes, and snippets.

@wheresalice
wheresalice / concurrent.php
Created September 29, 2011 09:14
Show the number of unique users using a Moodle website in blocks of 15 minutes
<pre>
<?php
require_once('config.php');
$sql = 'SELECT time/(15*60), COUNT(DISTINCT userid) FROM mdl_log
GROUP BY time/(15*60)';
print_r(recordset_to_array(get_recordset_sql($sql)));
?>
</pre>
@wheresalice
wheresalice / gist:1295188
Created October 18, 2011 11:16
Ensure people are using the www subdomain and https. This could be optimised, but it's nice to be able to switch out parts
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
php_value session.cookie_secure 1
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
@wheresalice
wheresalice / gist:1311754
Created October 25, 2011 07:48
Replacement Drupal function for email validation
function valid_email_address($mail) {
return (bool)filter_var($mail,FILTER_VALIDATE_REGEXP,array("options"=>array("regexp"=>"/^[a-z0-9!#$%&'*+\/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+\/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/")));
}
@wheresalice
wheresalice / gist:1316337
Created October 26, 2011 13:24
Mysqldump of tables with a prefix
mysql databasename -u [root] -p[password] -e 'show tables like "wp_153_%"' | grep -v Tables_in
| xargs mysqldump [databasename] -u [root] -p[password] > [target_file]
@wheresalice
wheresalice / gist:1319118
Created October 27, 2011 09:10
How to set a minimum height of a div across all browsers
#sidebar {
min-height: 580px;
height: auto !important;
height: 580px;
}
@wheresalice
wheresalice / moodlestatus.php
Created November 4, 2011 15:45
Returns a json array checking the Moodle version numbers and database access is working and the data directory exists
<?php
require_once('config.php');
require_once('lib/datalib.php');
require_once('version.php');
$moodle_release = substr($release,0,3);
if ($moodle_release == "1.9") {
$version = get_field('config', 'value', 'name', 'version');
}
<?php
// Register our shutdown function so that no other shutdown functions run before this one.
// This shutdown function calls exit(), immediately short-circuiting any other shutdown functions,
// such as those registered by the devel.module for statistics.
register_shutdown_function('status_shutdown');
function status_shutdown() {
exit();
}
// Drupal bootstrap.
@wheresalice
wheresalice / redisdns.py
Created November 27, 2011 12:56
Python DNS server with Redis backend
# A naive dns server with a Redis backend
# Set keys in Redis you want to be authoritative for (set google.com. 127.0.0.1)
# Tip: Use Redis's ttl functions to have temporary names
# Currently only does A records, feel free to fix that
#
# Licensed under the PSF License
# Thanks to: http://code.activestate.com/recipes/491264-mini-fake-dns-server/
# Author: @Kaerast <alice@kaerast.info>
import socket
@wheresalice
wheresalice / ducksboard.cfg
Created December 5, 2011 18:27
Push Nagios alerts to Ducksboard
# Needs extending to show correct image, but this is a minimally working setup
define command{
command_name alert-service-by-ducksboard
command_line curl -u $USER1$:ignored -d '{"value": {"title": "$NOTIFICATIONTYPE$", "image":"https://app.ducksboard.com/static/img/timeline/created.png", "content": "Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$"}}' https://push.ducksboard.com/values/$USER2$/
}
define command{
command_name alert-host-by-ducksboard
command_line curl -u $USER1$:ignored -d '{"value": {"title": "$NOTIFICATIONTYPE$", "image":"https://app.ducksboard.com/static/img/timeline/created.png", "content": "Alert: $HOSTALIAS$ is $HOSTSTATE$"}}' https://push.ducksboard.com/values/$USER2$/
@wheresalice
wheresalice / gist:1924566
Created February 27, 2012 15:21
Build Self-signed SSL Certificate & Key
openssl genrsa -des3 -out server.key -passout pass:riakssl 1024
openssl req -new -key server.key -out server.csr -passin pass:riakssl \
-subj /DC=US/DC=Massachussets/DC=Cambridge/O=Basho/OU=Engineering/CN=Riak
openssl rsa -in server.key -out key.pem -passin pass:riakssl
openssl x509 -req -days 365 -in server.csr -signkey server.key -out cert.pem -passin pass:riakssl
rm server.key server.csr