A (high octane) Christmas tale of woe…

Posted in Livejournal

Buying me an espresso maker for Christmas was a demonstration of how well my aunt knows me.
By the end of the day I’ll be twitching to much to check into rehab - is anyone going to be in the Brighton area to assist me?
On the plus side, I can use the usb mug warmer my brother bought me.
Furthermore (and I’m not sure if this is a good thing or not…) Sainsburys just delivered my groceries - which included coffee…

No Comments »

314

Posted in Livejournal

Just found this http://tomythius.livejournal.com/66369.html from my time in East Slope.
It’s heartening to realise how far I’ve come in six months - about a mile south and slightly up the hill.
Oh, and these days it’s tinned mandarin segments.

No Comments »

Ok stop… It’s ldap time!

Posted in Livejournal

So, I’m back. Not going to bore y’all with details of my whistle-stop Christmas, except of course to inform you that I’m the proud owner of a lovely new camera.
To business though. Tonight I’ve written a small script that authenticates a user against the USCS ldap server and displays their friendly name:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<?php
$uid = '';$passphrase = '';
echo("Starting auth module<br/>");
$ldpR = ldap_connect('ldap.sussex.ac.uk');
if(!ldap_start_tls($ldpR)){
    trigger_error('Cannot start TLS, credentials must not be sent in the clear !!',E_USER_ERROR);
}
$bind = @ldap_bind($ldpR); // try anon binding
if ($bind) {
    echo("Searching for uid: $uid.<br/>");    // anon binding worked, huzzah!
    $search = ldap_search($ldpR, "ou=unix,ou=uscs,o=university of sussex", "uid=$uid"); // search for username
    if (ldap_count_entries($ldpR,$search)==1) { // must be exactly one username        // Username exists, check pw
       echo("Checking pw<br/>"); 
       $bind = @ldap_bind($ldpR,"uid=$uid,ou=unix,ou=uscs,o=university of sussex",$passphrase); // rebind, with credentials
        if ($bind){
            echo("User $uid authenticated!<br/>");
            $entry = ldap_first_entry($ldpR, $search);
            $values = ldap_get_values($ldpR, $entry, 'cn');
            echo $values[0];
        } else {
            echo("Mismatch<br/>");
        } 
     } else {        // Username either doesn't exist, or contained a *
        echo("Username error<br/>");
    } else {    // anon binding failed
echo("Anon bind fail<br/>");
?>

I’m actually thinking of scrapping any user-table of my own, ldap is so quick… And if we’re going to be minimalist it’s all we need.
So there we go, a quick and dirty way of authenticating against ldap.
Much love,
Tom

No Comments »

A safe console.log

Posted in Livejournal

I seem to be on a bit of a geek-spree of late. What can I say? I writes what they wants me to write!
Anyway, today I learnt the hard way that the Firebug console object (though “wicked cool”) is only available when the client has the ‘bug installed. A bit of a D’Oh! moment… Should have been obvious, but I was seduced by firebugs wonderful simplicity and elegance… *sigh*
“What do we do then?” I hear you cry! (Aware, no doubt, that your mortal souls are in peril!)
Well, we don’t want to maintain two versions of the code do we? One with firebug consoling and one without. That, m’dear, is silly. What we want is for console.log to be ignored where it won’t work…
This simple function is the answer:

1
2
3
4
5
6
7
8
9
var errors = new Array();
function firebugconsole (message) {
try {
console.log(message);
} catch (err) {
errors.push(err+":"+message);
// Do we want to do something else with this?
}
}

It basically acts as a wrapper which stops the parser barfing if it doesn’t recognise the ‘console’ object.
Note that you need to have something in the catch part, or IE will get maaaaad! I’ve opted to add each error to an array that never gets used, but you could do anything.
Hope this helps someone out there!
=]

PS If you wanted to, you could enhance the function by adding support for all the console methods (debug, info trace etc). I didn’t need to, but I bet it’d be fairly simple.

No Comments »

I support a full body map

Posted in Livejournal

Now’s your chance to kill British prudishness:
http://www.nhs.uk/Pages/Bodymapvote.aspx
The NHS are hosting a public debate over whether it is appropriate to show genitals on their new body-map site.
Take a look, and email them your views.

No Comments »

Str_replace is my hot hot sex

Posted in Livejournal

This, on the other hand, is my hot hot sex.

1
$text = str_replace('="/', '="http://sussex.ac.uk/', $text);

Struggled for ages with regex before realising that this nifty one-liner is good enough to externalise all internal links and images.
Huxxah!

4 Comments »

Happy spaghetti time!

Posted in Livejournal

You can thanks USIS for this mess…

<?php
function splitdesc ($desc, $option) {
$data = explode('</p>', $desc, 2);
if ($option == 'start'||$option == 'finish') {
$months = array(1=>"January",2=>"February",3=>"March",4=>"April",5=>"May",6=>"June",7=>"July",8=>"August",9=>"September",10=>"October",11=>"November",12=>"December");
$separated = explode(' at ', $data[0], 2);
$date_array = explode(" ", substr(trim($separated[0]), 18));
if ($option=="finish") $subtime = 1;
else $subtime = 0;
$time = explode(' until ', $separated[1], 2);
$ampm = explode(" ", $time[$subtime], 2);
$time_array = explode(":", $ampm[0]);
if ($ampm[1] == 'pm') $h24 = 12;
else $h24 = 0;
return mktime(
$time_array[0] + $h24, // Hours, corrected from 12h time
$time_array[1], // Minutes
0, // Seconds
array_search(substr($date_array[3], 0, strlen($date_array[3])-1),$months), // Month, minus the comma and looked up
substr($date_array[1], 0, strlen($date_array[1])-2), // Day, minus ordinal
$date_array[4]); // Year
} else {
return $data[1];
}
}
?>

Spaghetti code at its finest.
Basically I needed to chop up events from feeds like this into a useful format; complicated when the time/date is given as a string mixed into the description…
Bah! Bloody university!

No Comments »

308

Posted in Livejournal

Terry Pratchett aintn’t dead, but he has got alzheimers:
http://www.theregister.co.uk/2007/12/13/terry_prachett_alzheimers/
Poor bastard.

No Comments »

307

Posted in Livejournal

The phrase “wicked cool”,
Is underused these days. Fight!
Struggle for the words!

Loving haiku today

No Comments »

Exodus

Posted in Livejournal

And because today seems to be a day of LJing…
Check this out: http://exodus.to/content/category/6/24/57/

Exodus is a nonprofit, interdenominational Christian organization promoting the message of Freedom from homosexuality through the power of Jesus Christ.

Emphasis original.

No Comments »

« Previous Entries