PC Nerding

The cheapest JS URL shortener ever

After my previous article about shortening urls using htaccess, today I’m posting a little JS snippet that will allow to shorten urls, using a JSON array to store shorter and longer urls. The script will look in url parameters for a short url and redirect to the associated longer url. Have a look:

<!-- // Function declaration
function shorturl_redirect() {
	// This JSON array contains all the shorturl/url pairs
	var urls =[	{ "shorturl":"?lndm" , "redirect":"" },
			{ "shorturl":"?example" , "redirect":"" },
			{ "shorturl":"?twitter" , "redirect":"" },
	// Get the url parameter
	var shorturl =;
	// If there's no url parameter stop script execution
	if(!shorturl || 0 === shorturl.length) { return; }
	// Now the function will look though urls array and if a valid shorturl is found it will redirect the browser to the longer url
	for(i = 0; i < urls.length; i++) {
		if(shorturl == urls[i].shorturl) {
// Function call
// -->

Now for an example, if you point your links to or the script redirect your browser to this site homepage.

Some quick notes:
- It will work on any hosting/subdirectory/webpage/cms/browser combination, unless the visitor is actively blocking JavaScript (eg. NoScript plugin on Firefox). All php cms still need to be fully loaded by the hosting environment before serving the script.
- I suggest placing this snippet (or .js file) between head tags, ideally you want the browser to stop loading html and go to the provided link.
- You can wrap the code into a JS anonymous function, since the code needs to be executed only once.
- The script is really small in size: the above example is only 834 bytes including comments. Byte size will vary according to your array size and url lenghts, for example I made an array with 50 entries and it was 5,3kb.
- It does not require additional libraries, eg. jQuery, or additional url shortening services, eg. or Yourls.
- Depending on the behavior you may want, you could change window.location.replace with window.location.href . For more information read here.

PC Nerding

Reading white text on black background

This will be a quick post.
If you, like me, really can’t read white text on black background (or can’t read purple on slighty darker glittering purple. Yes, I’m talking to you, MySpace nostalgic!) I have a quick solution for you: don’t and avoid headaches . If a site has a crap color setting, you probably can find the same copy-pasted content on other sites. If can’t find the same content on properly colored sites, use the awesome Web Developer Toolbar, available for both Firefox and Chrome (Opera too, in case your are looking for other NON-IE alternatives 🙂 ).

Once this plugin is installed and activated a new toolbar will appear. From there open the Disable menu and activate the Disable Page Colors option. Et voilà! Everything will transform into a bland black text on white background. Don’t let a bad developer decision turn you down on content!

PC Nerding

Password protecting yourself

When it comes to logins and passwords most, if not all, security sites tend to repeat those two important tips:
“use a two factor authentication, if available” and “use a different password for each different site/service”.

While for the first tip I can’t help too much since every site use a different type of authentication (some by text/sms, some by using a one-time password generator, some with a time based generator) I can tell you how I deal with the second one.

How do I use different password on different websites and how do I remember them all?
The answer is simple: use a password manager.

Now, the one included in browsers are sufficient for self use, but they are still somewhat vulnerable. For example if you store them in Firefox and your colleagues/family/friends have access to your computer, they can simply open Firefox and see your passwords with some easy steps. Same goes for Chrome and similar. I usually use those two browsers only on all operative systems, but the same applies for other browsers.

My family won’t steal my passwords!
When it comes to passwords, trust no one. If it’s a family computer and the same user account is shared between multiple people, you can’t know who is gonna use it. Your parents friends, your we-see-once-a-year cousin, your 14 year old sister’s boyfriend may have full access to it. You don’t want this to happen.

So, how do I protected my passwords?
Yet again, the answer is simple: password protect them.
But how?
Enter KeePass, the best (my opinion, ymmv) password manager out there. Do you know the best part about it? It’s 100% free and licensed under open source GPLv2.

Continue reading to learn more about KeePass and how it can help you protect your passwords.