Wednesday, 9 July 2014

Pretty print JSON

I really need to spend some time looking at things like JSON, however I came across a quick way to pretty print JSON, using json.tool python module.

example from top of script (or from help once imported json.tool module)

$ echo '{"json":"obj"}' | python -m json.tool
{
"json":"obj"
}


Tuesday, 1 April 2014

psql - expanded mode

I was looking at some postgresql tables trying to diagnose a problem, the amount of data in the table was making it difficult to see the separate records and not being familiar with what data I needed I could not just select the columns I was interested in.

I had see someone produce some output from a similar table where it was clearer laying out the records and so I was curious how this could be achieved a quick search through the docs mentioned "expanded mode". This can be enabled using

\x on


This gives the output to queries in the following format

select * from random_table;
-[ Record 1 ]------+------------------------------------------
column_1   | some data
column_2   | some other data
-[ Record 2 ]------+------------------------------------------
column_1   | some data 2
column_2   | some other data 2
--------------------------------------------------------------


This was much clearer for me to see what was going on on the terminal.

Friday, 21 February 2014

Launching Javascript from new tab in firefox

I had a piece of javascript that would take a case id as an argument and open a page on a ticketing tool and to make use of it I created a bookmark in firefox and assigned it to a keyword.

This means I could use the keyword with the case id in the url bar and open up the case directly, similar to setting up proxy bookmark.

However in the versions of firefox I was using, when a new tab was opened it loads a new tab which did not allow me to run javascript.

One solution to this is to change what loads in the new tab, preferably you do not want to load a webpage every time a tab is opened.
To set what to open in the new tab, open about:config, click on the "I'll be careful, I promise!" button and then search for "tab" in the search box.
There should be a setting browser.newtab.url, right click on this and select Modify and enter the url you want to have in each new tab.
As mentioned you don't want this to load a webpage every time, so I use about:blank.

First post of 2014

What no posts in 2014 yet.

I have been really busy with work and therefore have not managed to play with much fun stuff outside of work.

I aim to add some posts as often as I can.

Thursday, 28 November 2013

gnuplot changing font

I was following some instructions on using gnuplot, however the instructions for changing the font used in the graphs was wrong. Therefore I had to figure out how to achieve this.
I was looking to output some graphs to png images, so I added the following to the top of my command file used to draw the graphs
set terminal png enhanced font "<full path to font>"
set output "<filename>"
There is also an environment variable GDFONTPATH which can be set to directories containing font files, if this is used the above lines can be changed to
set terminal png enhanced font "<font name>"
set output "<filename>"

Tuesday, 26 November 2013

ioctl decoding

I was interested to know how to decode an ioctl hex string, I worked through the example described in the kernel documentation at /ioctl/ioctl-decoding.txt
Then I tested it out on an ioctl code listed in an error message in a server log, here is my working (this is for an x86_64 server, other architectures may vary)

ioctl code in hex is
cc770002

Which in binary is
11001100011101110000000000000010

First two bits gives us the macro used
11
this according to the document is _IOWR (Read/Write)

The next 14 bits give the size of the arguments
00110001110111
which in decimal is 3191

The next 8 bits are an ascii character, which in my example gives NULL (could well be an issue and why the message appears in the logs for that application)
00000000

The final 8 bits gives the function number, in my example this is
00000010
which in decimal is 2

If I had the sourcecode of the application I could go and look up this function using the character and the function number. In the example above, looks like a bug in the application is generating the wrong character and the ioctl call will fail.

Thursday, 21 November 2013

bc setting defaults

I have never really thought much about this, but for years whenever I start bc I always set the number of decimal points (scale) by issuing

scale=<number>

To automatically set this (and other settings) place them into a file (I called mine .bcrc) and set the environment variable BC_ENV_ARGS to point to this file.

BC_ENV_ARGS=$HOME/.bcrc

To set this variable up for every shell add to your shells start up files.