Stacking Script Event Loaders

I’ve been playing around with JavaScript once when I’ve encountered a problem about my scripts not working, especially those attached to event handlers. You could probably see JavaScript declarations like this on a script or another:

window.onload = functionName;

And, soon, I found out that a lot of plugins I have use the same declaration for initializing their scripts. So, I looked for references and realized that they overwrite one another by declaring that assignment operation over and over again. Looking for solutions, I came across two possible ways to do it:

  1. if (typeof window.onload != 'function') {
    	window.onload = newOnLoadFn;
    } else {
    	var onLoadStack = window.onload;
    	window.onload = function() {
    		onLoadStack();
    		newOnLoadFn();
    	}
    }
  2. var onLoadStack = window.onload;
    window.onload = function() {
    	if (typeof onLoadStack == 'function' && onLoadStack) {
    		onLoadStack();
    	}
    	newOnLoadFn();
    }

Coding preferences applies, as either basically does the same effect of stacking window.onload events. You could put them on a function if you must:

function addOnLoadEvent(newOnLoadFn) {
	if (typeof window.onload != 'function') {
		window.onload = newOnLoadFn;
	} else {
		var onLoadStack = window.onload;
		window.onload = function() {
			onLoadStack();
			newOnLoadFn();
		}
	}
}

And call events using:

addOnLoadEvent(
	// declaration of function type
);

I would recommend anyone distributing scripts to make use of this to avoid conflicts with other event-triggered scripts users may have beside yours. Thanks!

Open MSO 2007 Files in Earlier Versions

I personally prefer the older version of Microsoft Office 2003 than the newer MSO 2007.[1] I have classmates who use the newer version on their Vistas, but I still work on documents, spreadsheets and presentations on my MSO 2003 with a Windows XP. In a situation like this where group projects and collaborative works are a necessity to get things done, and a non-ideal working environment of different computers with different software,[2] I happily share a solution for those people who cannot just give up an older licensed copy for a cracked upgrade.

Microsoft Office 2007 has a multitude of changes compared to the earlier versions. It doesn’t have the standard menu-and-toolbar environment we are used to be working on, but a general-purpose Office button and the Ribbon of the new Fluent User Interface. It also comes with a set of new file formats from the Office Open XML specification, primarily the .docx, .xlsx and .pptx file formats. Using ZIP compression, these new file formats are a lot smaller than the old formats[3] MSO 2003 or earlier versions create.

If you still have your Microsoft Office version at 2000, XP (2002) and 2003, you may want to install the Microsoft Office Compatibility Pack for Word, Excel, and PowerPoint 2007 File Formats. This will enable you to open, edit, and save documents, workbooks, and presentations in the file formats new to Microsoft Office Word, Excel, and PowerPoint 2007. You just need to update to the latest service packs for those earlier versions. There are, however, some document element differences you may encounter while working on a newer file format with an older application version.

Footnotes:

  1. ^ especially because I know a bug I still haven’t had news about being fixed.
  2. ^ or software versions.
  3. ^ .doc, .xls and .ppt, respectively.

Lots’u-pdates~a

OK. So, I’m craving for pizza.[1] Well, it’s actually Yellow Cab I’m looking for if you’re really interested in sending me some. LOL

Anyhow, I’ve managed to update my WordPress installation from 2.2.2 to 2.5 yesterday evening, fixed a little about the tag cloud in my templates that will now use the system native to WordPress, fixed some tags whose display contained spaces and/or hyphens, and updated some plugins I am using.

I was actually watching the CSS Naked Day website around that time along with the UST Online Grades page. Unfortunately, they both weren’t updated even if I try to reload them pages once in about every 5 to 10 minutes. 😛 So, I just slept.

I really thought there would be no CSS Naked Day this year. Made me sad, really. Dustin’s blog was updated March 9 when I last checked it before today. However, a good morning dawned upon me when I woke up. Someone commented on my plugin page asking me to update it, telling me Dustin moved the CSS Naked Day to the 9th. So, there, I updated it already!

I have just one problem though. My site coughs up HTTP header errors whenever I try to respond to comments on my blog entries. The comments get posted still, but the errors are still annoying. Is there anyone else out there producing similar errors after updating to WordPress 2.5? Tell me please, and maybe how to eliminate it as well. Thank you!

Update: Apparently it was the Extended Live Archives plugin I was using that causes the error. I have just tested it using my own comment below. It seems that the problem was already existent even months ago with the 2.3 release because of the database changes, but I already admitted I haven’t been fully aware of blogging news lately. The plugin remains disabled, so you might notice a little barer homepage than before. There seems to be a fix, though I guess I have to do it a little later as I am already tired after a full half day of tweaking with my installation.

Footnote:

  1. ^ I’m always craving actually. OMG! I have to go on a diet. LOL

Fix Blurry Icons in Ubuntu

If you’ve recently tweaked the appearance of your Ubuntu installation, and selected anything other than the default Human theme, chances are that you may find some of your icons blurry. This is because the Human theme uses 24×24 icons and (probably) all others use 22×22. Therefore, choosing anything other than Human theme would compress all remaining icons on the main menu that has no corresponding icon from the newly selected theme, making them blurry.

For example, the following image has been taken after choosing the Glossy theme:

Blurry Icons
Note the icons for Keyring Manager and Network (highlighted)

If you don’t like the Human theme, but would like to preserve the crisp icons, you have to create a GTK+ 2 settings file. Do the following steps on a per-user basis:

  1. Open your favorite text editor, and create a text file ~/.gtkrc-2.0.[1]
  2. Place the line, gtk-icon-sizes = "panel-menu=24,24".
  3. Save and exit.
  4. Log off and re-log onto your account.

But, you may want to share the crisp icons for other users, too. So, you might as well hack into the theme file. The following steps would tell you how:

  1. Open a terminal application.[2]
  2. Type in, sudo <text editor command> /usr/share/themes/<theme directory>/gtk-2.0/gtkrc.[3]
  3. Type in your password for superuser status.
  4. Place the line, gtk-icon-sizes = "panel-menu=24,24" on any line outside any brackets.
  5. Save and exit.
  6. Log off and re-log onto your account.

The menus would then use 24×24-pixel icons that retains the original crisp.

Crisp Icons
Note the icons for Keyring Manager and Network (highlighted)

I’ve used more than a couple searches and mailing list pages to figure this out, but the most unambiguous workaround source surprisingly comes from the OpenOffice.org section on the Ubuntu bug tracker on Launchpad.

Footnotes:

  1. ^ where ~ points to your home directory
  2. ^ click on: Main Menu » Applications » Accessories » Terminal
  3. ^ for example: sudo nano /usr/share/themes/Glossy/gtk-2.0/gtkrc to edit the Glossy theme on nano

P.S.:

I haven’t actually tried the per-user setting file, but the system-wide theme hack worked for me, definitely. I just included it according to the instructions I’ve read for those who cannot acquire a superuser status on their systems, thus, the permission to edit the theme files.

Prevent Autorun-driven Virus Infections

USB flash drives and portable hard disk drives are commonplace today as PCs and digital media are conquering the market. But, while ease of use and portability of the UFD and HDD [as well as their digital content] increases, the spread of malware[1] on them also increases. There are several ways to prevent this from happening,[2] with or without the help of an AV product.

Case 1: Clean PC+AV, Infected UFD/HDD; Automatic

This is the easiest, though not necessarily the best solution[3] to detect and clean autorun-driven malware.

  1. Update the anti-virus product on your computer before plugging in the portable drive.
  2. Do not open your drive contents after plugging.
  3. Scan your portable drive for malware immediately.
  4. Clean all infections found by your anti-virus.

Case 2: Clean PC, Infected UFD/HDD; Manual

In some cases, an anti-virus product or an update is not available, or the anti-virus product is just not strong or smart enough.[4] We could do a manual search and destroy for the malware.

  1. Plug on the drive to your computer.
  2. Use the Folders Explorer Bar[5] to open the drive contents on Windows Explorer, instead of double-clicking the drive icon on the main window; or
  3. Right-click on the drive icon on the main window, and select Explore or Open, and not Autoplay or Autorun
  4. Look for the file named autorun.inf.
  5. Open the file using Notepad or the text editor of your choice.
  6. Take note of the line that says, open=<path\filename.ext>, where <path\filename.ext> is the location of the malware itself.
  7. Locate the malware and delete it along with the autorun.inf file.

Case 3: Infected PC

You would know if your PC is already infected when it copies the malware and the autorun files to your portable drives automatically. If your AV software couldn’t handle cleaning your system from it, or if you have none, consider browsing the Web for manual detection and cleaning procedures as different variants and, therefore, locations of them would be hard to summarize in this post. Try Trend Micro‘s Virus Encyclopedia.

Case 4: Clean PC and UFD/HDD; Prevention

Here’s the nifty part, this is based on a hack from a friend who works on an anti-virus company.

  1. Create a folder on the root of your portable drive.
  2. Rename it as autorun.inf.
  3. Right-click on the folder, and click Properties. Alternatively, select the folder, then go to the File menu, and select Properties. KB shortcut: [Alt]+F, R
  4. Under the General tab, on the Attributes section, check Read-only and Hidden. KB shortcuts: [Alt]+R, and [Alt]+H, respectively

The above instructions would prevent other infected computers from copying an autorun directive to your portable drive. It doesn’t necessarily mean an instance of the malware itself would be prevented from being copied as well. It just protects you from your own muscle memory of instantly double-clicking the drive icon to open the contents, but instead, running the malware to be installed on your clean PC.

Footnotes:

  1. ^ malicious software; collective term for viruses, worms, trojan horses, spyware, et al.
  2. ^ Cases assume you’re on the virus-prone Microsoft Windows platform.
  3. ^ Your AV would probably delete only the instances of the malware and not the autorun.inf file for it is intended as a convenience feature for legitimate software manufacturers. You could safely delete the autorun file manually.
  4. ^ This pertains to my experience with a fully-updated AVG Anti-Virus Free Edition on my classmate’s notebook, which was not able to detect a simple autorun-driven malware.
  5. ^ If not visible by default, go to View on the menu bar, locate Explorer Bar, and then check Folders. KB shortcut: [Alt]+V, E, O