Monday, May 23, 2016

From where I cloned my local repo?

If you want to determine the URL from where you cloned your local repository, use this command.

git config --get remote.origin.url

Friday, January 15, 2016

How to read attachment in servicenow scoped application

While working on a servicenow application, I came across a scenario where I need to read the attachment contents (XML in my case) and parse them. Quick google search leads to code snippets using GlideSysAttachment.getBytes() which is no longer available to scoped applications, since Fuji patch 9. After trying for a while, I could read the attachment. Here's the code I used for this.

The sys_attachment table contains the actual attachment, along with table name and table sys id to which this attachment belongs to. Query sys_attachment table, providing table name (optional, because table_sys_id itself is supposed to be unique) and table_sys_id. Then, while iterating over result set, call GlideSysAttachment.getContent(), passing the sys_attachment glide record as argument.

Monday, December 14, 2015

Chunk IPv4 range into multiple sub-chunks

One of my non-programmer-but-in-IT friends came to me last week, asking help to chunk a range of IPv4 addresses into N small chunks. And, here's the PHP code I came up with within 10 mins.

What it simply does is, explode the input range, and convert start and end IP address into long, using ip2long(). Then, using range() expand it into a whole list. Once that is done, then decide number of elements that should go into each chunk - remember, the optional argument to this function tells how many chunks are to be prepared. the formula is there on code line number 11.

Once you have this number, call array_chunk() to create chunks. Finally, iterate over them, get start and end IP of each of them (which are still long numbers), convert them back to IPv4 address using long2ip() and create the range string for them.

Do you find it useful? Copy it! Have any suggestion, let me know in the comment!!