Sunday, 7 May 2017

Getting method name within the same method

For logging in some server side javascript, I had the need of getting the name of the method within the same method. There are 2 ways of doing this:
- accessing arguments.callee.toString() and applying regex extraction to get the name
- accessing arguments.callee.name

It does not always work though. ECMA strict mode does not allow it but their is no alternative either.

Wednesday, 1 March 2017

Unable to locate "adwaita" theme engine

While running KDE on Arch linux, on a number of occassions, I get to see the following error.

(java:20732): Gtk-WARNING **: Unable to locate theme engine in module_path: "adwaita"

[828:828:0708/183334:ERROR:browser_main_loop.cc(249)] GTK theme error: Unable to locate theme engine in module_path: "adwaita"

The mitigation of the issue is installation of gnome-themes-standard package.

Monday, 27 February 2017

[Newtonsoft] Checking for null valued keys in parsed JObject

Using Newtonsoft's Json package, when we need to parse a string to get a JObject, we can do it as follows:

JObject o = JObject.Parse(serializedJsonString);
 
This is of course the case when you don't have a model class for the Json response coming in. For keys that can have a null value, checking for null values as follows is intuitive.

o["key"] == null

However, it is also incorrect. Due to the way in which null values are stored in the parsed object, the proper way of checking for null valued keys is as follows:

o["key"].Type == JTokenType.Null
 
Of course, you should do both checks and the former check should be done earlier to ensure that the key exists before checking whether the value is null.