Category — computers
Perl Binaries with PAR
This is something that rears it’s ugly head from time to time, the need to create stand alone scripts that I can give to a none programmer to run on a Windows box. The last time I played with this, it was to create a version of the get_iplayer script for my dad to run. This time it was to run some network diagnostics scripts we’d hacked together on a machine we had no access to.
The machine we needed to run it on was a fairly well locked down ‘doze box, so installing Perl was unlikely to happen. The last time I used a nice little app called linux2perl. It worked fairly well, but the free version had a 2 second delay and a splash message on the start of the app.
So I decided to take a look at the Perl Archiving Toolkit (PAR). The PAR toolkit actually generates intermediate shippable packages, that are actually zip files with all the required modules included to run a script. So a PAR script can be packaged up and shipped to any user with perl and it’ll run regardless of architecture (almost… think XS), or installed modules.
To my delight, creating an executable was nice and simple:
pp -o outfile.exe infile.pl
PP is the PAR Packager, which is nice little utility to convert the PAR files to executables for the current OS. Or as the CPAN page puts it “You may think of pp as perlcc that works without hassle.”
You’ll still need a windows box to build the binaries, but once they’re built they are completely shippable and can be sent to other boxes. Although they do end up being rather large, my simple script was a little under 4 Meg, leading me to wonder if more than just the libraries I used were packaged up too.
Either way it worked perfectly, I even repackaged the get_iplayer script for the old man.
April 8, 2009 No Comments
P3P Policies are a joke
Initially I thought P3P policies might be quite useful. A nice way to see how a site promises to use my data and I could even configure my browser to treat my privacy settings accordingly.
It was a nice thought at least. Unfortunately the reality is somewhat different. The only browser that seems to even support P3P privacy policies is Internet Explorer. When I say “support”, what I actually mean is, make a complete hash of.
It appears that if you want to use cookies on a third party domain, in an iframe or a image tag for instance, in IE you need to have a P3P policy defined.
Okay, no problem we’ll set ours up. Unfortunately the site I was working on has terms and conditions that state that they can use users data for pretty much anything. Initially IE didn’t appear to have a problem with the policy stating this. The third party cookies worked a treat, but for some insane reason Microsoft in their wisdom decided to turn all first party cookies into session cookies. Which meant the whole system wouldn’t function.
This ain’t news‘ lead developer Mark discovered that Facebook are using a very strange P3P policy, that only contained “CP=HONK”. As we could find no reference to this anywhere we discovered through trial and error that you can put any gibberish in, and IE lets all first party and third party cookies work fine!
So in essence, the only browser that supports P3P policies is IE, and to get round them just put in some Lorem Ipsum. Now that’s a security model.
April 1, 2009 2 Comments
Which distro?
After deciding I’d do what I thought would be a nice and straight forward Debian upgrade from Etch to Lenny, I managed to completely hose my server.
Eventually I discovered that the amd64 version of Xen simply doesn’t work. Anyway, I have no need for Xen on the server any more, and since the nice people at Citrix seem to have completely hidden the open source versions, I’m going to get rid.
So now the question is what do I whack on the server in its place? My distro of choice recently, for my personal boxes, has been Gentoo. However I just can’t convince my self that it’ll be stable enough. Or more that if it’s not, tracking down any problems could be a nightmare.
I suppose, another option could have been Redhat, but I’ve just never managed to “gel” with it. Debian would be an obvious choice to stick with, but with them ripping out xen so abruptly, I’m just not feeling the love. I’m sure I’ll be forced to make a descision soon enough.
March 25, 2009 2 Comments
Using your own modules as Catalyst Models
So you want to write a funky new model for Catalyst you say. Well the easy way to start would be to use the helper script to create a nice new model and start adding functionality. Woah there! One minute. If you continue down this route then a year down the line when it’s time to reimplement your site you are stuck with Catalyst. Or what if you need to write another app that uses your model.
So how do we get round this? We write a standard Perl module. Forget Catalyst for the time being, and of course write it like it’s meant for CPAN. Develop your module and use a test suite to test it as you go. No point waiting for Catalyst to restart every time you want to test a change and get the advantage that your tests will still hold true when you come back to this code in 6 months.
Eventually you will get to the point when your module is ready to be plugged into Catalyst. Now it’s time to create a model. Run the helper script as you would normally to do this. Now comes the interesting part…. As Catalyst instantiates all the models at initialisation time we still need to initialise our module so we use the COMPONENT method. We create a COMPONENT method within our model that initialises an instance of the module we created.
Something like:
use MyModule;
sub COMPONENT {
my ($self, $c, @config) = @_;
return MyModule->new(@config);
}
So now we have an instance of our model to work with. The config can be set from the Catalyst config by setting
$c->config->{'Model'}->{'MyModule'} = [<SOME CONFIG>];
The COMPONENT method is called when the Catalyst app is initialised and so it’s only called once per instance. If you want to initialise your module on a per request basis add a retrieve method to return a new instance of your module.
October 30, 2008 No Comments
Generating RSS Feeds
RSS Feeds are inherently repeated patterns over and over again with a bit of text in the middle for a link and some content. So what’s the best way to generate one. I’ve debated this to my self now for a few days and can’t really come up with a strong enough argument to sway me one way or the other.
As I see it there are three realisting posibilities. These are….
- Generate the feed using print/sprintf statements. This has the advantage of being quick, having very little memory footprint and requiring less processing power. The major draw back is that the XML isn’t validated. Another drawback is that it won’t be the prettiest solution.
- Use a templating system. If you pick the right templating system this could be quite fast, with HTML::Templates caching for example this could be done fairly quickly and fairly painlessly. Again the big disadvantage is that the XML isn’t parsed and validated.
- Use an XML module such as XML::Simple or XML::Feed. XML::Feed you say, that sounds like it’s designed to do just the job. Well yes it is, but it aslo uses a full DOM to build up the feed, as would XML::Simple so it’s comparitively slow compared to the first two methods. The major advantage being that it would pretty much always generate validatable XML.
So with the first two sollutions we could generate the output and then validate it with an XML Parser to check it, but surely that takes away the major benifits of either sollution. If we use the templated sollution, so long as we ensure that the content within the template variables is XML friendly and in CDATA tags etc, surely we can guarantee that the XML output should be fine.
So do we go with a less elegant, more speedy sollution or a more elegant less speedy sollution. Of course we could cache the output of the more elegant sollution if the feed data wasn’t changing too often, making the argument a no brainer, but what if the data changes every few seconds…. I just can’t make up my mind.
October 27, 2008 1 Comment
Speed up your site
Much of this will be obvious to most people, it is to me, yet still I hadn’t (and still haven’t for some) actually done it for all the sites I currently manage.
Today I had the misfortune to end up using a slower than slow internet connection and discovered that a good chunk of the Internet becomes practically unusable at those slow speeds. So I took a look at some of the pages we had loading. The HTML content itself wasn’t too bad only a few kilobytes so I took to the YSlow plug-in for Firefox. This nifty little piece of kit will show you all kinds of information relating to how quickly your site loads and what optimisations you can make.
I was horrified to discover that the total size of some of our sites was nearly a megabyte so I started reading. Maybe half an hour or so later the home page of the site in question was down to less than 100k with all the images, CSS, JavaScript, flash and html. Most of this was achieved by minimising the JavaScript and by enabling mod_deflate in Apache.
Much improved already but I still didn’t really want our users to have to wait for 100k to download every time they visited the home page, so caching was in order. Adding expires headers to the content in Apache achieves this, but with the addition of ETags you can override the cached content when it is updated. Always good when I make a change to CSS that the users actually see it! Happily for static content Apache automatically provides ETags based on the modification time of the content.

As can be seen in the screen grab above, with the caching you can certainly get a large difference in the amount you need to download. I was happy enough with the result, until I got back to my usual Internet connection and loaded the page. Wow! So I thought it was annoyingly slow on the previous connection, well on the faster connection it was practically instant and that makes these improvements a must in my mind! Not to mention the obvious benefits to the bandwidth charges.
October 23, 2008 1 Comment
Internet
Well, I’ve been reliably informed that I now have an Internet connection at home. Typical that it is today that I manage to sort my 3g card out so that it’ll work with Ubuntu. Anyway it now works a treat. In fact I’m on a train posting now. Ain’t milk brilliant….
February 13, 2008 No Comments
Merry Christmas etc….
Merry Christmas and other such festive malarchy. I’m back in work for one day only, between Christmas and new year. Then it’s off to London as soon as I finish this evening.
After looking for some technical stuff earlier today and finding nothing but videos I’m wondering whether it’s time to start posting some videos on here. Anyone know of any good video players for blogs? Something you tube like, but I might as well host them my self. Actually thinking about it there is probably a plugin for WordPress. Time to investigate….
December 27, 2007 No Comments
IE 1000
LOL, Microsoft reported that they are preparing IE8 for release, and these are some of the possible names they banded around the office.
IE 7+1
IE VIII
IE 1000 (think binary)
IE Eight!
iIE
IE for Web 2.0 (Service Pack 2)
IE Desktop Online Web Browser Live Professional Ultimate Edition for the Internet (the marketing team really pushed for this one ![]()
Ie2.079 (we might still use this for the Math Major Edition)
Being a maths fan I quite like e2.079.
December 13, 2007 No Comments
last.fm
Check out my last fm station!
table.lfmWidget20070807125105 td {margin:0 !important;padding:0 !important;border:0 !important;}table.lfmWidget20070807125105 tr.lfmHead a:hover {background:url(http://cdn.last.fm/widgets/images/en/header/radio/regular_black.png) no-repeat 0 0 !important;}table.lfmWidget20070807125105 tr.lfmEmbed object {float:left;}table.lfmWidget20070807125105 tr.lfmFoot td.lfmConfig a:hover {background:url(http://cdn.last.fm/widgets/images/en/footer/black.png) no-repeat 0px 0 !important;;}table.lfmWidget20070807125105 tr.lfmFoot td.lfmView a:hover {background:url(http://cdn.last.fm/widgets/images/en/footer/black.png) no-repeat -85px 0 !important;}table.lfmWidget20070807125105 tr.lfmFoot td.lfmPopup a:hover {background:url(http://cdn.last.fm/widgets/images/en/footer/black.png) no-repeat -159px 0 !important;}
|
|
August 7, 2007 No Comments