I’m a twitter n00b. I joined up a month or so ago just to try it out, and occasionally i post something technology or work related. Turns out that I joined up right after they disallowed being able to subscribe to your “friends feed” feature without authenticating first. This is naturally a PITA because I use Google Reader, and it doesn’t pass down any credentials for me. Shit.

So my first reaction was to write a script in PHP which proxys the request on my behalf and authenticates me at the same time (hey it is silly-code Thursday after all). And that’s what this post was meant to be about. I was planning on blogging about my Thursday night somewhat learning PHP over again. In case you care, the code and links will come later.

As I was writing this to look up some references, I stumbled across this page which describes how you can use Yahoo Pipes to authenticate to Twitter and achieve the same result. What took me a few hours to learn and do in PHP, took me seriously less than 10 minutes using Yahoo Pipes. Absolutely remarkable. I’ll be spending more time playing around with that, now!

So if you care, the PHP version looked something like this:

<?php

include("HttpClient.class.php");

$client = new HttpClient('twitter.com');
//$client->setDebug(true);
$client->setPersistReferers(false);
$client->setUserAgent('Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3');
$reqHeaders["Accept-Charset"] = "ISO-8859-1,utf-8;q=0.7,*;q=0.7";
$reqHeaders["Keep-Alive"] = "300";
$reqHeaders["Connection"] = "keep-alive";
$client->setRequestHeaders($reqHeaders);

if (!$client->get('/statuses/friends_timeline/16832429.rss')) {
    die('An error occurred: '.$client->getError());
}
$pageContents = $client->getContent();
$requestArray = array_values(explode(';', $client->getHeader('Set-Cookie')));
$cookieArray;

$split = explode('=', $requestArray[0]);
$cookieArray[$split[0]] = $split[1];

$client->setCookies($cookieArray);
$client->setAuthorization('username', 'password');
if (!$client->get('/statuses/friends_timeline.rss')) {
    die('An error occurred: '.$client->getError());
}
echo $pageContents = $client->getContent();

?>

I used the HttpClient class to make the requests, which was the first result that came up in Google. Turns out this code hasn’t been updated since 2003 (incidentally that’s around the same time when I last did PHP), and there was a bug that the Authorization request header came AFTER the Cookie header, which (as it turns out) will be rejected by the webserver with a 401. That oddity alone took me an hour to figure out. *sigh*

This evening I wanted to wish someone a happy birthday. In my infinate geekdom, I figured writing a tiny app to do it would be a nice way to waste 20 mins this evening. I started off writing in Notepad (because this really isn’t worth opening Visual Studio for), and compiled using CSC jsut to make sure it worked in the end (oops, forgot a few semi-colons…)

using System;

public class BirthdayWisher
{
    public BirthdayWisher(string personName, DateTime birthDate)
    {
      this.PersonName = personName;
      this.BirthDate = birthDate;
    }
    public readonly DateTime BirthDate;
    public readonly string PersonName;

    const string BirthdayMessage = 
        "rnDear {0}! Wishing you a happy birthday for {1}. Congratulations on being {2} years old!";

    public void WishBirthday()
    {
      Console.WriteLine(String.Format(BirthdayMessage, PersonName, BirthDate.ToString("MMMM dd"), DateTime.Today.Year - BirthDate.Year));
    }
}

public class NaomiBirthday
{
  [STAThread]
  public static void Main(string[] args)
  {
    BirthdayWisher naomi = new BirthdayWisher("Naomi", new DateTime(1983, 11, 21));
    naomi.WishBirthday();
    
    Console.WriteLine("rnPress any key to end.");
    Console.ReadKey();
  }
}

So i sent her an IM message with that code and the following instructions to run this:
1. Copy the text above and save it to your desktop as a file called “birthday.cs”
2. Click “Start –> Run” and paste the following into the box and then press enter.

%windir%system32cmd.exe /c “%WINDIR%Microsoft.NETFrameworkv2.0.50727csc /out:”%USERPROFILE%birthday.exe” “%USERPROFILE%desktopbirthday.cs” > null&&”%USERPROFILE%birthday.exe”&& del “%USERPROFILE%birthday.exe” ”

Yes, i am a massive geek, but now I can re-use the same code for someone else’s birthday – yay for reuse! The harsest part about this whole thing wasn’t the code, but in the command-prompt syntax required to chain commands properly and get it to execute as i’d expect. Even after spending maybe 30 mins on it, I don’t think I got it right, and certianly it could be improved upon….I guess that leaves room for Happy Birthday v2 :)

Tonight’s been a busy night for silly coding :)

This first post is about a short-cut i’ve created do an instant twitter. Just create a bookmark with the following code (tested only in Chrome), and when you want to tweet, just click the bookmark, type your twitter message and then click “upload”.

Saves having to open the twitter window each time, etc etc…This code is based on something i found elsewhere on the net, but modified slightly so it doesnt need to use their custom server-side scripts – its all JS talking to Twitter.com

javascript:void(window.open(“http://twitter.com/home?status=” + window.prompt(“Enter your twitter status”, “bored…”), ‘tweeting’, ‘scrollbars=no,width=550,height=250,top=175,left=75,status=yes,resizable=yes’))

I’m digging deeper into WPF and learning more about XAML, web-XAML and XBAP. This evening i’ve stumbled across a nasty side-effect. When i’m creating an XBAP project in Visual Studio and run it without the debugger, the XBAP gets cached somewhere and any subsequent changes don’t show up – It keeps running the old XBAP file.

I’ve done a little digging and found out that the XBAP is cached by Click-Once when you run it outside the debugger. When executed, the application is deployed and run using Click-Once which (amongst other things) versions the assembly, checks for dependencies on the target machine and loads the application. If the application has been cached, then it will use the cached version instead. However you don’t have this problem when you’re running through the debugger because the process is launched by Visual Studio, and it will always run the latest assembly. This bugs me because I more frequently run my development apps outside the debugger and only attach when I need to. I know when my code is generally going to work, and most errors can be spotted without the need for attaching a debugger to the process.

Anyway the temporary solution is to add a pre-build event which clears the Click-Once cache and upon execution, the correct version of my app will be spawned. The command for the event is:

%windir%system32rundll32 %windir%system32dfshim.dll CleanOnlineAppCache

You can also run the command mage.exe -cc which is a CLI tool to do the same thing. More research is required into Click-Once and all this. Please note that this is a preliminary post, and I haven’t done much research in depth into the problem – if you know of a better way, i’d like to hear it!

Well if you believe what you read on the wires, this would be probably the country’s greatest step towards a communist state after our somewhat draconian immigration policies.

I’m not a civil libertarian – in fact I get annoyed when the libertarians jump up and down about us losing our rights with this, that, and the other. Pick the battles worth fighting and fight until you win; that’s what I believe in. Otherwise, you run the risk of stretching yourself too thin.

However the news about a nation-wide internet filter has got me concerned. It wasn’t that long ago we sent an entire media cohort over to China for the Olympics and learnt that despite their initial promises, China still filtered what internet sites people could access. Did we (as a society) not learn from what we saw there? Where a dictator state has the infrastructure in place to police what should be a completely free medium? Clearly not. Seems like they’re pressing ahead with the bill and trying to lay down the foundation for such a system.

….And then where to? It starts with kiddy filtering and illegal activities, but then where to? Should the government be trying to stop us from accessing this kind of material, or should it be up to the parents to educate and/or prevent their kids from getting access to this content. The government’s rationale for taking such a progressive move? If we cant educate parents and children on how they can do it, we’ll just do it ourselvesCitation needed.

On the flip-side, I wonder if the government would continue to be so “progressive” and prevent people from hurting themselves by outlawing smoking? Or is that too cynical of me?

It’s no secret that i’ve had a job on the side for a number of months now tutoring programming at the local university. I won’t get into the gritty details about the experience (at least not yet), but I want to briefly talk about my experience with catching out students who have cheated in their assignments.

The subject is Visual Basic .NET. I’m not a great VB.NET programmer, in fact i’m not a VB.NET programmer at all, but i’m able to stay one week ahead of the students and generally have an answer to the questions they ask. If I don’t have an answer, I at least offer the consolation of providing them a solution in C# :). The major assessment for this subject is to write a project (based on some given specs) in VB.NET and submit your working binaries + all code in a compressed ZIP file, and we mark it based on some marking scheme.

When the project works, I don’t really need to delve into too much depth when assessing their solution. The fact that it works indicates they’ve understood at least the majority of what was being asked of them and I’m satisfied that it works.

However – when it doesn’t work, my triggers get fired. Why did they submit an assignment which doesn’t work?. I attach a debugger, and start looking at code. Any programmer will understand what i’m about to say…Code, is a lot like a face. You see it once and then in future, although you might have a problem figuring out WHERE you originally saw it, you’ll recognise the same code.

Where am I going with all this? Well firstly – I found one assessment which didn’t work. Attached debugger, saw code, imprinted in brain. 3 DAYS LATER I opened another person’s assignment, assignment didn’t work (hmmm i’ve seen an error like that before….), attached a debugger and saw code (hmmm….I know i’ve seen that code before….). Hopefully now the title of this post makes more sense. So yes, I indeed did find two students who cheated. They used the same code, and made obvious attempts at trying to cover it up….Not terribly clever attempts, mind you…Which then led me to wonder how many others have also done the same thing…And here’s where I talk about my QnD app to check for duplicates.

Some time back, I posted about some technologies I wanted to play around with. This was a good opportunity to start with that and some features of framework 3.5 i’ve been meaning to try out.

The basic idea behind the utility is to search through a folder (and its subfolders) and find files which are identical (or similar). I want it to be modular so that I can write several different algorithms for determining similarity and swap them in/out easily. The first iteration I knocked together in a few hours and sure enough, I found another set of students who had copied their work. The first algorithm used is just a straight file-compare. Nothing fancy, just straight text comparisons. If two students have the same code byte for byte, they would need the excuse of the century to explain how it is not plagiarism.

Although I haven’t added Castle Windsor to it yet, i’ve at least written it in such a way that it will be easy for me to implement. Code is attached below in case you wish to go forth and conquer.

DuplicatesChecker Code