Thursday, 9 June 2011

Regex to trim number to two decimal places

Not very generic, but at least easy to understand:
m/^(.+?\.[0-9]{2})/;
123.456789 becomes 123.45

Thursday, 2 June 2011

Line-breaking long words without spaces

Often I'll have a problem where very long strings of text (URLs for example) break my formatting. Wouldn't it be nice if there was a way to split them over lines even if the characters weren't line breaking?

I came across this post that shows a hidden characters that act as breaking characters:

http://www.robinlionheart.com/stds/html4/spchars

Here's an example using ​repeated several times with the alphabet:

ABCDE​FGHIJ​KLMNO​
PQRST​UVWXYZ​​

ABCDE​FGHIJ​KLMNO​PQRST​UVWXYZ​ABCDE​FGHIJ​KLMNO​PQRST​UVWXYZ​ABCDE​FGHIJ​KLMNO​PQRST​UVWXYZ​ABCDE​FGHIJ​KLMNO​PQRST​UVWXYZ​ABCDE​FGHIJ​KLMNO​PQRST​UVWXYZ​ABCDE​FGHIJ​KLMNO​PQRST​UVWXYZ​ABCDE​FGHIJ​KLMNO​PQRST​UVWXYZ​ABCDE​FGHIJ​KLMNO​PQRST​UVWXYZ​

Saturday, 28 May 2011

Serving static and dynamic content with Node.js and node-static

With a little bit of help from Nodejitsu and Ben Nadel here's a simple js file for serving static and dynamic content. Static content must be in the /s/ directory, which makes it perfect for serving images or css. Note I am listening on 0.0.0.0 to allow external connections. During development you may want to restrict it to 127.0.0.1.
var sys = require('sys');
var http = require('http');
var nodestatic = require('node-static');

var staticServer = new nodestatic.Server(".");

var server = http.createServer(
function (req, res)
{
var url = require('url').parse(req.url);

var pathfile = url.pathname;

sys.puts('request: ' + pathfile);

if (pathfile.search(/^\/s\//) == 0)
{
staticServer.serve(req, res)
}
else
{
res.writeHead(200, { "Content-type": "text/html" } );
res.end('Hello world');
}
}
);

server.listen(8080, '0.0.0.0');

sys.puts('listening..');

Thursday, 26 May 2011

Fedora 15 / Gnome 3 / Gnome Shell: Where is the system tray?!

After using Fedora 15 for a few hours by sheer luck I managed to find the system tray:

Move the mouse to the bottom right corner of the screen.

Seems a bit odd to have icons that you traditionally want shown all the time hidden away...?

Wednesday, 25 May 2011

Fedora 15 / Gnome 3 doesn't show Gnome Shell

Today I've been installing Fedora 15 as an upgrade to Fedora 14 on my Eee 1015PEM.

Two issues I had:

1) When rebooting following the preupgrade install (where the files are downloaded whilst the system is in use) the system wasn't able to mount /tmp with the following error:

"An error occurred mounting device tmpfs as /tmp: mount failed (-2, None)"

Luckily someone came across the same issue in the F15 beta and logged the issue here:

https://bugzilla.redhat.com/show_bug.cgi?id=683434

Simple answer: comment out the tmpfs lines in /etc/fstab prior to install. DON'T try rebooting with the old OS as you'll find X and its apps may struggle to start. If this happens and you can't get into an X terminal window try CTRL+ALT+F2-F7, which switches consoles.

2) Having installed and rebooted I was informed that Gnome Shell (the fancy new UI) wouldn't start as my hardware wasn't capable of it. Having panicked and searched for drivers for my Intel GMA 3150 chipset I was sinking into my mire until I came across this post:

http://osdir.com/ml/fedora-test-list/2011-05/msg00290.html

suggesting running:

gnome-shell --replace &

I didn't hold much hope other than causing more damage but having run the command the UI changed instantly into the new mode. I left it for several minutes and the UI seemed to freeze. A hard reboot saw the UI come back to life and so far it's been working fine.