Cross-Platform Command Line Tools
source link: http://portablecommandline.blogspot.com/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Tuesday, June 23, 2009
Transparent legend in your plots
- Create an image file from your plot and then "photoshop" it (or gimp it...)
- Add the alpha channel directly in the plotting tool...
from pylab import * t = linspace(-2*pi,2*pi) y1=cos(t); y2=sin(t); plot(t,y1,label='Cosine') plot(t,y2,label='Sine') xlabel('Time') ylabel('y')
axis([-2*pi,2*pi,-1,1])
leg=legend()
savefig('namehere.png')
close()
Now we see from the resulting plot that the legend covers some of the graph. Now, before the "savefig" command, add the following:
frame=leg.get_frame()
frame.set_alpha(0.4)
The resulting plot is shown below the original. Better, don't you think? :-)
PS! Click on the plots to show larger versions!
Monday, June 15, 2009
Coding is better with java ... the coffee, that is.
Saturday, June 13, 2009
Automate text processing with string methods
Have you ever had the need to reorganize a text file? Say you have some file that is organized in the following way:
Variable1
20
Variable2
30
....
Say you would like to reorganize that into something more spreadsheet-like, such as
Variable1 20
Variable2 30
---
Easy enough by hand in Excel or OOo calc if there are a couple of values. What if your list contains 20.000 entries? Then a script is your hero. Let's make a command line tool to reorganize such files using Python. We want the script to work like this on the command line:
>> reorganize inputfile.txt outputfile.txt
Therefore, we need to import the sys.argv list (containing command line arguments). Next, we need to use file methods to read the contents of file A into a list that we can operate on. The start of our script is thus:
#!/usr/bin/env python
from sys import argv as filenames
inputfile=open(str(filenames[1]),'r')
inputlist=inputfile.readlines()
inputfile.close()
Now we have a Python list like this:
inputlist=['Variable1\n','20\n','Variable2\n','30\n']
where the '\n' thing means line break. We cannot just write this directly to a new file, we need to strip the '\n' from list elements with even index numbers (indexing starting at zero) and we need to add '\t' to the same list elements to get a tab-separated file easily. An easy way to do this is the following; make two lists, one holding the "names" and one holding the "values". While making these lists, remove all line breaks using the replace method of string objects and replace them with tab characters ('\t'). The code:
ColA=[]; ColB=[];
for k in range(0,len(inputlist)/2):
ColA.append(inputlist[2*k].replace('\n','\t')
ColB.append(inputlist[2*k+1]
Then, simply write to the output file:
outputfile=open(filenames[2],'w')
for k in range(0,len(ColA)):
outputfile.write(ColA[k]+ColB[k])
outputfile.close()
Putting these commands together yields a script that gives you the desired result... (This is a tool I use every day - text processing is so much simpler for a scripter than for the average Excel user). Note that it is possible to do this directly in a spreadsheet using macros. I might consider writing the solution to that one day to. Or not.. :-)
Friday, June 5, 2009
regKPI: register a KPI value in a database or text file
Thursday, May 28, 2009
A simple console program
Tuesday, May 26, 2009
Console programs
- alpine: e-mail client for the console (easy to use and with a ton of features)
- midnight commander: file organizer
- vim: text editor
- gnuplot: open source plotting program
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK