Skip to content

Instantly share code, notes, and snippets.

@wheresalice
wheresalice / gist:949611
Created April 30, 2011 11:33
Sinatra Dropbox Oauth
require 'rubygems'
require 'erb'
require 'sinatra'
require 'dropbox'
configure do
enable :sessions
end
def authed?
@wheresalice
wheresalice / redis.io
Created May 4, 2011 13:46
A basic Redis client in Io.
//metadoc Redis Alice Kaerast 2011
/*metadoc Redis description
redis is an open source, advanced key-value store
<br />An example:
<pre>
myredis := Redis clone connect("127.0.0.1:6379")
myredis send("rpush", "foo", "bar")
</pre>
*/
@wheresalice
wheresalice / AntiMalware.feature
Created May 17, 2011 14:16
What I want from an offline antimalware tool.
Feature: Offline system cleaning
We often come across Windows machines which have unknown malware installed.
There are relatively few entry points for such malware to run.
It should be possible to build an open source tool which scans these, even if the system is offline.
Background: Mount the offline system
Given I've mounted the hard disk
Scenario: The disk is scanned
@wheresalice
wheresalice / make.sh
Created May 20, 2011 14:49
Build scripts for Squidguard 1.4 with LDAP support
sgversion=`awk '/Version/ {print $2;}' squidguard.spec`
wget -c `awk '/Source/ {print $2;}' squidguard.spec | sed s/%{version}/$sgversion/g`
cp squidGuard-$sgversion.tar.gz ~/rpmbuild/SOURCES/squidGuard-$sgversion.tar.gz
rpmbuild -ba squidguard.spec
sgrelease=`awk '/Release/ {print $2;}' squidguard.spec | cut -c 1`
cp ~/rpmbuild/RPMS/*/squidguard-$sgversion-$sgrelease.*.rpm .
@wheresalice
wheresalice / ldap-account-manager.spec
Created May 26, 2011 13:14
Ldap Account Manager 3.4.0
# $Id: ldap-account-manager.spec 7981 2009-11-03 03:05:34Z dag $
# Authority: dag
# Tag: test
Summary: LDAP Account Manager
Name: ldap-account-manager
Version: 3.4.0
Release: 2%{?dist}
License: GPL
@wheresalice
wheresalice / gist:1129313
Created August 6, 2011 12:46
Regex to parse an ATCO CIF Bus Service
service = "QSNKDT E91F220080427300001010000010 696 0 I"
service_exception = "QE20100920201009240"
service_origin = "QO450024175 1725 T1F0"
service_destination = "QT25001940 1649 T1F0"
service_regex = /^QS([NDR])(.{4})(.{6})(\d{8})(\d{8})([01]{7})([SH ])([ ABX])(.{4})(.{6})(.{8})(.{8})(.)$/
service_exception_regex = /^QE(\d{8})(\d{8})([01])$/
service_note_regex = /^QN(.{5})(.{72})$/
service_origin_regex = /^QO(.{12})(\d{4})(.{3})(T[01])(F[01])$/
service_intermediary_stop_regex = /^QI(.{12})(\d{4})(\d{4})([BPSN])(.{3})(T[01])(F[01])/
@wheresalice
wheresalice / img_to_map.rb
Created August 20, 2011 10:54
Create a game map in redis from a txt file which imagemagick has conerted from png to txt
require 'redis'
@redis = Redis.new
# width & height of the map
@x = @y = 0
grassdatafile = open('../resources/maps/land3g.txt')
grassdatafile.readlines.each { |line|
@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])?$/")));
}