Elod P Csirmaz’s Blog: 2011

30 October 2011

Use of uninitialized value in hash element: the reason for this warning in Perl

Once again it proved to be hard to find more information about a Perl warning, this time about the "Use of uninitialized value in hash element" one, despite it being what it says on the tin. One could (correctly) guess that it refers to a hash key, but what might be confusing is that Perl has no problems with

$a{undef} = 1;


Instead, it seems that this error is connected to one of the nice features of Perl: autovivification, as the following code does make Perl issue a warning:

$a{$b{1}} = 1;

So if you see this, look out for undefined references used as hash keys.

23 September 2011

Make Firefox open links in new tabs on a right click

Recently I got a trackball with only two buttons, which means I cannot use a middle click to open a link in a new tab (under Windows). I found it surprising that the developers of Firefox didn't think it would be useful to be able to customize what the mouse buttons do, but I was even more surprised how much I needed to search to find a solution.

Use the InstaClick add-on to make Firefox open a link in a new tab if you right-click it.

Also, visiting about:config and setting browser.search.openintab to true can solve the annoying issue that when you use the search box to start a search, the results replace your current tab.

17 July 2011

Perl: Wide character in subroutine entry

It took some time for me to trace what dies with the error "Wide character in subroutine entry," and searching for it didn't help much, either.

But in the end, it turned out that Digest::MD5::md5_hex() causes this error if its parameter contains a wide character:
use Digest::MD5 qw(md5_hex);
$x = "El\x{151}d";
md5_hex($x); # Dies with 'Wide character in subroutine entry'

I haven't tested other Digest::MD5 functions, but I hope this helps someone.

3 July 2011

PHP bug: binary characters in open_basedir allowed path and security issues

I must've been searching for the wrong keywords, as I only found the related bug report (here) after finding a fix to this problem:

I'm using WAMP Server under Windows, and when I specified "php_admin_value open_basedir" in the Apache configuration file, it worked fine after restarting all services in the WAMP server, but after the first reload, the open_basedir path magically transformed itself into a series of binary characters, and the restriction (obviously) failed. I also had the network connection reset a number of times while the browser was trying to load the page.

This was not an issue if open_basedir was specified in php.ini only.

Fortunately, the issue seems to have been fixed. It was a problem when I used Apache version 2.2.11 and PHP ver 5.3.0, but with Apache ver 2.2.17 and PHP ver 5.3.4, everything works fine. I think it was a PHP bug (although I also read an initial PHP bug report where it was apparently claimed that it wasn't), so if you encounter this error, all you have to do is to upgrade PHP.

Be warned, though, it seems that specifying open_basedir in itself is not safe enough; this report by the hardened PHP project suggests disabling the symlink function as well to avoid a possible hack.

9 June 2011

Parameterized surfaces in Blender

I was searching for a way to create a parameterized 3D surface in Blender when I found the XYZ Function Surface function of the 3D Function Surfaces add-on by Martin Buerbaum.

I saw that it wasn't enough for my needs, so I rolled up my sleeves, and implemented a couple of modifications (as I knew nothing about Python or Blender, I was quite pleased that I succeeded in this), most importantly I added helper functions to make the formulas easier to construct; tube-like surfaces can now be closed; the script can now create more objects at once and I also fixed the wrapping and some internal stuff.

Martin was very kind to review my changes and suggest some modifications, and I'm happy to say that the new version of the add-on is available from the Blender Extensions SVN repository here! I hope it makes its way, in one form or another, into a future release of Blender.

Oh and the thing I made with it? A 3D-printable version of a statue I designed about 9 years ago - available from Shapeways.

26 April 2011

When browsers won't remember your password - server-side issues

Just a quick note about something I've been trying to research: IE and Chrome appears to refuse to remember login details (username and password) entered into a login form if the form is sent via AJAX. Moreover, IE won't recognize a form as a login form if it contains more than two fields. See stackoverflow about Chrome and msdn about Explorer.

15 April 2011

Silencing an Android phone with exceptions for calls and messages from certain contacts

I was searching for a way to silence my Android phone (calls and
message notifications) during the night but with exceptions for a few contacts. However, the apps I found usually asked for a lot of permissions, or used undocumented features of the operating system that could break with any future update.

I found a solution to achieve this using two free apps that seem to ask for minimal permissions, that is, you can be sure they don't access parts of your system they shouldn't.

The main idea is to use a silent mp3 as your general ringtone and message notification tone during the night instead of turning the volume down. To make calls from specific contacts still go through, simply specify a special ringtone for those contacts. (Open the contact and change "Ringtone" in the "Information" section from "Default" to something else.)

You can download a silent mp3 file from here. Copy it into /Media/audio/alarms, /Media/audio/notifications and /Media/audio/ringtones on the SD card of your phone to make it available as a ringtone and notification tone. (You may need to create these directories if they don't exist already.)

You also need to add special notification tones to messages coming from specific contacts if you want to be alerted to them during the night. I used the SMS Popup app to do this. It has many nice features, but I disabled most of them, and used the so-called "contact notifications" only which you can set up in Notifications -> Contacts Notifications -> Add. (Note that the notifications played by SMS Popup are in addition to the ones by the system. It is generally advised that you turn the default alert off when using SMS Popup, but if you did, you wouldn't be able to turn the default alert silent during the night using this set-up.)

The only thing that remains to do is to change the ringtone and the notification tone to the silent mp3 file in the evening, and back to your usual tone in the morning. Quick Profiles can make this very easy if you set up your profiles in the following way (I also included a profile to use when you don't want your phone to ring at all -- maybe at the theatre).

PROFILE:NightSilentNormal (Day)
Ringer mode:RingSilentRing & Vibrate
Media volume:no change0%50%
Change ringtone:to Silent.mp3no changeto your usual
Change notification sound:to Silent.mp3no changeto your usual


Basically, you can configure your "Normal (Day)" profile to set everything back to normal after either the "Night" profile or the "Silent" profile.

You can also make Quick Profiles manage your alert volume, or you can untick "Alarm in silent mode" on the settings page for alarms to make sure that they don't sound in the theatre, but still wake you up if the profile is set to "Night."

Hope you'll find this post useful!

24 February 2011

Mini Linux with SSH

I was searching for mini Linux distributions for a while, as I wanted to create a USB drive from which a PC would boot very quickly, and then I could SSH to other machines to do some maintenance.

The smallest distribution I could find was the 'microcore' version of Tiny Core Linux. However, SSH is not part of it by default, but it is in an extension that one needs to download (together with some other extension packages it depends on) after Linux has booted.

Now Tiny Core Linux can store extensions on a local disk, but it cannot read NTFS, so what I did was to include these extensions in the distribution itself.

If you need a lightweight, fast Linux with SSH, here's how to install it:
  • Download the microcore 3.5 ISO file (from here)
  • Use UNetbootin to create a bootable USB drive. This should unpack the ISO file onto your USB drive
  • Download the microcore.gz that includes the extensions necessary for SSH from here, and replace the one in USBDRIVE/boot/microcore.gz
  • You can also configure USBDRIVE/syslinux.cfg to make the boot process faster. Here's what I use:
    DEFAULT linux
    LABEL linux
    KERNEL /boot/bzImage
    APPEND initrd=/boot/microcore.gz embed multivt noswap nozswap nofstab noicons norestore

  • Enjoy! For me, this Linux boots up in a couple of seconds.

My microcore.gz includes gcc_libs.tcz, openssl-0.9.8.tcz and openssh.tcz in /tce/, and these are loaded using tce-load in /opt/bootlocal.sh.

9 January 2011

"Petrified" references in Perl -- a third type of references

In Perl, one can use soft / symbolic references to variables by creating a variable that contains the name of the referenced variable:

$ref = "myvar";
$$ref = 0; # Sets $myvar to 0

Soft/symbolic references are unsafe, as explained here.

The other way to create a reference is to initialize the reference as a pointer. This is safer as it is explicit:

$ref = \$myvar;
$$ref = 0; # Sets $myvar to 0

$hashref = \%myhash;
$hashref->{'key'} = 0; # This is the same as ${$hashref}{'key'}
$myhash{'key'} = 0; # Has the same effect as the line above

These are called hard references, and Perl's OO system is largely based on them.

However, there is a third case: when two variables point to the same value without either being a reference. (I haven't found an explicit documentation of this, so I named this case "petrified" references.) This can be achieved this way:

*myvar1 = *myvar2;
$myvar1 = 0;
$myvar2 = 0; # Has the same effect as the line above

One can even make a variable point to where a hard reference points to. For example, %myhash2 will point to the anonymous hash referenced by $hashref:

$hashref = {'key' => 0};
*myhash2 = $hashref;
$myhash2{'key'} = 1; # Note that myhash2 is a hash, not a hashref!
$hashref->{'key'} = 1; # Has the same effect as the line above

This is very useful if, for backwards compatibility, one needs to refer to the same value using multiple names, or one needs to cross namespaces.

For some guidance on the * notation, please see section 7 in http://perldoc.perl.org/perlref.html#Making-References.