Compdigitec Labs

Free and open source XML beautifers to format XML

By admin | December 26, 2009

XML is a great format for storing data, but an improperly-formatted XML file (e.g. whole file on one line, unusual breaking, improper line wrap, etc) can be just as difficult to read as a binary blob. In order to make “blob” XML readable, here are some tools you can use to format XML so it’s readable.

If you found this article helpful or interesting, please help Compdigitec spread the word. Don’t forget to subscribe to Compdigitec Labs for more interesting articles!

Topics: (X)HTML, Internet | 12 Comments »

Simple C++ gettext-like toolkit

By admin | December 20, 2009

Here is a small gettext-compatible interface for reading simple translation catalogs (not to be confused with gettext’s *.mo style catalogs, which are binary) in form of “original/english string<tab>translated string”. It is not fool-proof, but you can play around with it and it works.

/*
 *      gettextpd.h
 * 		Main file for GettextPD
 *
 *      © Copyright 2009 Compdigitec. All rights reserved.
 *
 *      Copying and distribution of this file, with or without modification,
 * 		are permitted in any medium without royalty provided the copyright
 * 		notice and this notice are preserved.  This file is offered as-is,
 * 		without any warranty.
 */
#ifndef __GETTEXTPD__
#define __GETTEXTPD__

#include <stdlib.h>
#include <cstring>
#include <string>
#include <iostream>
#include <fstream>

// gettext functions
char* gettext (char *msgid);
std::string gettext (std::string msgid);
char* textdomain (const char *domain_name);
char* bindtextdomain (const char *domain_name, const char *dir_name);
char* setlocale (int category, const char* locale);

// macros
#define _(str) gettext(str)

// globals
std::string gtpd_locale = "";
std::string gtpd_domain = "";
std::string gtpd_location = "";

// function bodies
char* gettext(char* msgid)
{
	std::string x(msgid);
	std::string result;
	result = gettext(x);
	char* nb = (char*)malloc(sizeof(char)*result.length());
	strcpy(nb,result.c_str());
	return nb;
}

std::string gettext(std::string msgid)
{
	std::string path = gtpd_location + "/" + gtpd_locale + "/LC_MESSAGES/" + gtpd_domain + ".mo";
	std::ifstream stream;
	stream.open(path.c_str());
	std::string resultline;
	while(!stream.eof()) {
		getline(stream,resultline);
		if(strstr(resultline.c_str(),msgid.c_str()) != NULL) {
			break;
		}
		resultline = "";
	}
	if(resultline == "") {
		// not found
		return msgid;
	}
	int splitloc = resultline.find("\t");
	return resultline.substr(splitloc+1);
}

char* textdomain(const char *domain_name)
{
	gtpd_domain = domain_name;
	char* res = (char*)malloc(sizeof(char)*100);
	strcpy(res,domain_name);
	return res;
}

char* bindtextdomain (const char *domain_name, const char *dir_name)
{
	gtpd_location = dir_name;
	textdomain(domain_name);
	char* res = (char*)malloc(sizeof(char)*100);
	strcpy(res,dir_name);
	return res;
}

char* setlocale (int category, const char* locale)
{
	gtpd_locale = locale;
	char* res = (char*)malloc(sizeof(char)*100);
	strcpy(res,locale);
	return res;
}

#endif

Example usage:

// test.cpp
#include "gettextpd.h"
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
  setlocale( LC_ALL, "fr_FR" );
bindtextdomain( "hello", "." );
textdomain( "hello" );
std::cout << gettext("Hello, world!") << "\n";
std::cout << _("THis is A TeST StriNg") << "\n";
exit(0);
}

folder/fr_FR/LC_MESSAGES/hello.mo

Hello, world!	Zu bu zu translated str
THis is A TeST StriNg	test string translated this is#2

If you found this article helpful or interesting, please help Compdigitec spread the word. Don’t forget to subscribe to Compdigitec Labs for more interesting articles!

Topics: Linux | 9 Comments »

How to take out the system built-in beeper in Linux

By admin | December 18, 2009

Usually the system beeper (not to be confused with speakers) can be a rather useful tool in informing or alerting the user. Sometimes however, the beeper can be just plain annoying, especially if you already know what you are doing. For example, it is very annoying to have a laptop suddenly start beeping in the middle or a presentation or on a subway train. Here’s how to disable it to avoid such embarrassment.

To permanently disable:

Execute in a shell (Applications >> Terminal):

echo -e "\nblacklist pcspkr\c" >> /etc/modprobe.d/blacklist.conf

To temporarily disable:

Execute in a shell (Applications >> Terminal):

sudo modprobe -r pcspkr

If you found this article helpful or interesting, please help Compdigitec spread the word. Don’t forget to subscribe to Compdigitec Labs for more interesting articles!

Topics: Linux | 7 Comments »

Console-free gtkmm applications in Visual Studio 2008

By admin | December 6, 2009

When compiling Gtkmm programs on Microsoft Windows using Visual C++, a black console box pops up when you run the program. However, setting the application subsystem to Windows will cause the program to complain about WinMain and other problems. Here is a versatile solution from the Gtkmm mailing list to get Gtkmm to work on Windows transparently without breaking interoperability with other platforms, such as Linux, though some modifications were required to make it work.

Insert the following code before your main() and after your header #includes:

#ifdef WIN32
	#include <windows.h>
#endif

using namespace std;
using namespace Gtk;

int main(int argc, char* argv[]);

#ifdef WIN32

int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{
	// check windows version
         DWORD dwVersion = GetVersion();

         if (!(dwVersion < 0x80000000))
         {
                 MessageBox(0, _T("This application requires Windows 2000/XP or above!"), _T("Fatal Error"), MB_OK);
                 return -1;
         }

         return main(__argc, __argv);
}

#endif

Here is a sample Gtkmm application without console boxes on Windows:

#include <gtkmm.h>
#include <iostream>
#ifdef WIN32
	#include <windows.h>
#endif

using namespace std;
using namespace Gtk;

int main(int argc, char* argv[]);

#ifdef WIN32

int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{
	// check windows version
         DWORD dwVersion = GetVersion();

         if (!(dwVersion < 0x80000000))
         {
                 MessageBox(0, _T("This application requires Windows 2000/XP or above!"), _T("Fatal Error"), MB_OK);
                 return -1;
         }

         return main(__argc, __argv);
}

#endif

int main(int argc, char* argv[])
{
	Gtk::Main kit(argc, argv);
	Gtk::Window window;
	Gtk::Main::run(window);

	return 0;
}

Topics: Windows | 12 Comments »

Windows Live and Bad Behaviour plugin incompatiblity

By admin | November 16, 2009

While the Bad Behaviour plugin is an excellent plugin for blocking annoying comment spam and other stuff, but there is a known incompatibility with the Bad Behaviour plugin with the Windows Live. You can go and read the full article, but here is a quick drill-down of what you need to know:

Bad Behaviour LogsBad Behaviour Logs
We cant get information for this web activity...

We can't get information for this web activity...

WordPress has been added to your profile...

WordPress has been added to your profile...

Basically, the Bad Behaviour plugin for some reason seems to think that the Windows Live “robot” sends a bad User-Agent string, and blocks Windows Live from accessing your recent posts. To remedy this, add “65.54.233.0/24”, after line 19 in <blogpath>/wp-content/bad-behavior/bad-behavior/whitelist.inc.php. It should look like this after you’re done:

<?php if (!defined('BB2_CORE')) die('I said no cheating!');

function bb2_whitelist($package)
{
 // DANGER! DANGER! DANGER! DANGER! DANGER! DANGER! DANGER! DANGER!

 // Inappropriate whitelisting WILL expose you to spam, or cause Bad
 // Behavior to stop functioning entirely!  DO NOT WHITELIST unless you
 // are 100% CERTAIN that you should.

 // IP address ranges use the CIDR format.

 // Includes four examples of whitelisting by IP address and netblock.
 $bb2_whitelist_ip_ranges = array(
 "64.191.203.34",    // Digg whitelisted as of 2.0.12
 "208.67.217.130",    // Digg whitelisted as of 2.0.12
 "10.0.0.0/8",
 "172.16.0.0/12",
 "192.168.0.0/16",
 "65.54.233.0/24",
//        "127.0.0.1",
 );

 // DANGER! DANGER! DANGER! DANGER! DANGER! DANGER! DANGER! DANGER!

 // Inappropriate whitelisting WILL expose you to spam, or cause Bad
 // Behavior to stop functioning entirely!  DO NOT WHITELIST unless you
 // are 100% CERTAIN that you should.

 // You should not whitelist search engines by user agent. Use the IP
 // netblock for the search engine instead. See http://whois.arin.net/
 // to locate the netblocks for an IP.

 // User agents are matched by exact match only.

 // Includes one example of whitelisting by user agent.
 // All are commented out.
 $bb2_whitelist_user_agents = array(
 //    "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) It's me, let me in",
 );

 // DANGER! DANGER! DANGER! DANGER! DANGER! DANGER! DANGER! DANGER!

 // Inappropriate whitelisting WILL expose you to spam, or cause Bad
 // Behavior to stop functioning entirely!  DO NOT WHITELIST unless you
 // are 100% CERTAIN that you should.

 // URLs are matched from the first / after the server name up to,
 // but not including, the ? (if any).

 // Includes two examples of whitelisting by URL.
 $bb2_whitelist_urls = array(
 //    "/example.php",
 //    "/openid/server",
 );

 // DANGER! DANGER! DANGER! DANGER! DANGER! DANGER! DANGER! DANGER!

 // Do not edit below this line

 if (!empty($bb2_whitelist_ip_ranges)) {
 foreach ($bb2_whitelist_ip_ranges as $range) {
 if (match_cidr($package['ip'], $range)) return true;
 }
 }
 if (!empty($bb2_whitelist_user_agents)) {
 foreach ($bb2_whitelist_user_agents as $user_agent) {
 if (!strcmp($package['headers_mixed']['User-Agent'], $user_agent)) return true;
 }
 }
 if (!empty($bb2_whitelist_urls)) {
 $request_uri = substr($settings['request_uri'], 0, strpos($settings['request_uri'], "?"));
 foreach ($bb2_whitelist_urls as $url) {
 if (!strcmp($request_uri, $url)) return true;
 }
 }
 return false;
}

?>

The edit to line 20 is the change required in order to accommodate Windows Live services on your WordPress blog. If you found this article helpful or interesting, please help Compdigitec spread the word. Don’t forget to subscribe to Compdigitec Labs for more interesting articles!

Topics: Internet | 9 Comments »

New e-mail phishing alert – “It’s Easy, Secure and Free!” in big bold letters

By admin | November 2, 2009

According to a recent news report, some 20,000 e-mail accounts have been hijacked from Internet phishing. This includes major e-mail providers such as Hotmail and Gmail. This results in spam being sent on behalf of the hijacked accounts and creates a major headache for both the hijacked and the non-hijacked caused by both spam and unauthorized usage of the victims’ accounts.

E-mail spam sample

E-mail spam sample

Major hallmarks of the spam include misspellings in the message, poor grammar and in the center a big bold sentence which goes like this:

It’s Easy, Secure and Free!

Followed by a link to a suspicious website that looks something like superb-blocked-check.com or see-alarming-block-check.com.

Things you can do to stay clear of this:

Topics: Internet | 7 Comments »

Virtual MIDI Keyboard in Ubuntu

By admin | October 4, 2009

On Windows, you could find many freeware virtual piano software. But on Linux, you have no such easy setup or such choice. There are two major pieces virtual piano software – they are Virtual Keyboard and Virtual MIDI Piano Keyboard.

Virtual Keyboard

Virtual Keyboard

Virtual MIDI Piano Keyboard

Virtual MIDI Piano Keyboard

You should be sure you have your sound card proper set before you start this – i.e. make sure you can play a file in Totem or something.

To install Virtual Keyboard:

sudo apt-get install vkeybd

To install Virtual MIDI Piano Keyboard (download vmpk.deb to /tmp first):

sudo dpkg --install /tmp/vmpk.deb

After you have chosen one (or both) of the above, install the remaining dependencies:

sudo apt-get install qjackctl zynaddsubfx

After you have installed everything, run the following and restart your computer:

sudo su -c 'echo @audio - rtprio 99 >> /etc/security/limits.conf'
sudo su -c 'echo @audio - memlock 250000 >> /etc/security/limits.conf'
sudo su -c 'echo @audio - nice -10 >> /etc/security/limits.conf'

After restarting, open the JACK control center (Applications >> Sound & Video >> JACK Control), and start the JACK server. Once it is started, click the Connect button at the lower left corner. Start ZynAddSubFx and Virtual Keyboard/Virtual MIDI Piano Keyboard and go back to the JACK control center, select Connect, then the ALSA tab. Connect the Virtual Keyboard/VMPK on the left to your sound card and the ZynAddSubFx. Connect your sound card on the left to the right. The result should look something like this:

JACK audio connecitons

JACK audio connecitons

After that is complete, go back to Virtual Keyboard/Virtual MIDI Piano Keyboard and click on a few piano keys. Enjoy!

Topics: Linux | 10 Comments »

Mini-PulseAudio sound checklist

By admin | September 27, 2009

If you’ve been having trouble with your sound in Ubuntu or any other Linux distribution that uses PulseAudio, here is a mini-checklist for sound in Ubuntu in case it is not working properly (i.e. no sound at all, static-like sound or loud obnoxious buzzing sounds).

Ubuntu Sound Preferences Dialog

Ubuntu Sound Preferences Dialog

First, a few general hints in case the checklist doesn’t help exactly or you are on another distribution. You would usually, in 99% of cases not run PulseAudio as root or system-wide, as for most sound applications, it will cause them to start feverishly spitting out access denied errors. You also should check your distribution’s audio groups, as you must have added yourself (and any other users who might want to use sound) to their respective groups, which varies among distributions. Also, you should check if your sound is muted out or not plugged into your sound jack. This sounds silly but it is very common to spend 6/7 hours figuring out why sound doesn’t work only to find the speakers aren’t plugged in.

  1. Open a terminal and run cat /etc/default/pulseaudio | grep PULSEAUDIO_SYSTEM_START. If the response is blank or anything other than “PULSEAUDIO_SYSTEM_START=0” (with a zero), then go and edit it (sudo nano -w /etc/default/pulseaudio) and either add PULSEAUDIO_SYSTEM_START=0 or change it so it the value is equal to 0.
  2. Start ALSA subsystem – sudo /etc/init.d/alsa-utils start.
  3. Make sure you have installed the correct sound driver for your card or have it auto-detected by udev. Try to run alsamixer and if you can move around sliders, then the device was properly detected. You can try the Ubuntu Wiki article for setting up sound cards.
  4. In the GNOME Sound Preferences dialog (System >> Preferences >> Sound), set all playback and capture devices to PulseAudio.
  5. Add yourself to the pulse, pulse-rt and pulse-access – sudo adduser <username> pulse, sudo adduser <username> pulse-rt and sudo adduser <username> pulse-access.
  6. Kill all existing instances of PulseAudio – sudo killall pulseaudio.
  7. Restart the computer.

If you found this article helpful or interesting, please help Compdigitec spread the word. Don’t forget to subscribe to Compdigitec Labs for more interesting articles!

Topics: Linux | 7 Comments »

Enable and disable VBoxTray on demand

By admin | September 12, 2009

If you have upgraded to VirtualBox 3, even though it may be way faster and more efficient (and now supports DirectX), there is still one feature that managed to fall through the cracks and regress: clipboard support is incomplete. For example, if you go into Windows Explorer and right click any file and “Copy”, when you get to another folder you will find the “Paste” button is greyed out as if there is nothing on the clipboard.

For a temporary fix you can use until the VirtualBox team decides the problem is large enough to fix (open a command prompt with Win+R and cmd):

taskkill /F /T /IM VBoxTray.exe

This disables the VirtualBox Guest Additions module, which seems to be causing the problem currently. However this also takes away some neat features such as auto-resizing the guest, mouse and keyboard integration. To re-enable it when you are done:

start VBoxTray.exe

If you found this article helpful or interesting, please help Compdigitec spread the word. Don’t forget to subscribe to Compdigitec Labs for more interesting articles!

Topics: Windows | 6 Comments »

Media Player Classic – a small lightweight media player

By admin | August 27, 2009

Windows Media Player is generally an good bulit-in media player, but in recent version seems to have become big and unnecessarily bloated with size, and also has become very slow. A good alternative to it would be Media Player Classic, a lightweight, small and fast media player that resembles very closely the good old-fashioned Media Player 6.4 (you may remember it as wmplayer2.exe). Not only is it small and lightweight (needing only one exe file), you can also use it as a replacement for WMP which supports DVDs, Blu-Ray, MP4, WMA, and many other media files, while keeping low CPU and memory usage.

Media Player Classic 6.4.9.1

Media Player Classic 6.4.9.1

If you found this article helpful or useful, please help Compdigitec spread the word. Don’t forget to subscribe to Compdigitec Labs for more useful or interesting articles!

Topics: Windows | 9 Comments »

If you found this article helpful or interesting, please help Compdigitec spread the word. Don’t forget to subscribe to Compdigitec Labs for more useful and interesting articles! « Older Entries Newer Entries »