Freitag, 17. Februar 2012

No need for temporary variable (Javascript)

Assume you have a function, and that function has a param (called 'config' herein) which may be a string or an object. Inside your function, you check for the type and if it's a string, you want to make this strings value a property of your object.

My first, fast approach was this one:
var url = config;
config  = {};
config.videoLink = url;

My second approach looked like this:
var url = config;
config  = {videoLink: url};

I thought about what's happening in those statements and realized that the temporary variable 'url' is not needed, because javascript is executing the assignement from right to left, means I can override 'config' with an object that keeps the original value of config as a property. See this third & final approach:
config = {videoHash: config};

So Javascript builds the object, assigns the value of config (string) to videoHash and assigns this object to config, which now is a object as desired.

Mittwoch, 1. Februar 2012

xfce4-screenshooter 1.7.9 - Segmentation Fault on startup

When starting xfce4-screenshooter, there's an segmentation fault message and it (of course) doesn't start up. The solution is pretty simple:

touch ~/.config/xfce4/xfce4-screenshooter

Source: http://www.linuxquestions.org/questions/slackware-14/where-to-get-xfce4-8-goodies-etc-885538/#post4382696