Fix weird flux menu

Some distro’s just add all the items under single menu and thus the menu itself becomes unusable because of the number of items in the submenu and this I did not like and hence ceated this simply python script to fix that. For using the script, back up you “menu” file, redirect the output of this script to ‘menu’ file again.

 

#!/bin/python

F = open("~/.fluxbox/menu", "r")
count=0
mkc=1
started=0

for line in F:
    print line.rstrip()

    if '[submenu]' in line.lower() and started == 1:
        print '[end]'

    if '[end]'  in line.lower():
        count=0
        mkc=1
        if started > 0:
             started=0
             # print "Count is {}".format(count)
             # print "Started is {}".format(started)
             print '[end]'
    if '[exec]'  in line.lower():
        if count > 15 :
            if started > 0:
                started=0
                print '[end]'
                # print "Count is {}".format(count)
                # print "Started is {}".format(started)
            print '[submenu] ({})'.format(mkc)
            started=1
            mkc+=1
            count=0
        # print count
        count+=1

change the output format for time command

If you are doing some scripting and using ‘time’ command, then you know sometimes it becomes difficult to capture the output as the output would be something like this:

: amit ; time ls

real    0m0.002s
user    0m0.000s
sys 0m0.001s

So, it is better to change that format. Here is simple example:

1
 
TIMEFORMAT=’real %3R user %3U sys %3S pcpu %P’ time ls
amit ;  TIMEFORMAT=’real %3R user %3U sys %3S pcpu %P’ time ls
0.00user 0.00system 0:00.00elapsed 0%CPU (0text+0data 2432max)
0inputs+0outputs (0major+109minor)pagefaults 0swaps
amit ; TIMEFORMAT=’real %3R user %3U sys %3S’
amit ; time ls
real 0.001 user 0.001 sys 0.000
amit ;
amit ; TIMEFORMAT=’TIMEOUTPUT = real %3R user %3U sys %3S’
amit ; time ls
TIMEOUTPUT = real 0.001 user 0.001 sys 0.000
amit ;

Generate random string for various use case

Some times I need random string, for example to use as email seperator or to use in some API. One way is to use tools like /dev/[u]random or od and other such. But they seem cubersome after I figured this out.

openssl rand <length>
openssl rand 10

This alone without some parameters is not interesting thoug. You can use ‘-base64’ or ‘-hex’ to select the encoding.

So if you execute the above you will get something like this

$ openssl rand -hex 10
591e96110af8aecb760b

$ openssl rand -base64 10
TnuUXuiZXv2ktw==