Sunday, February 24, 2013

Pho places near Laurel

In Laurel, we have Pho 54 and Pho 88. Lisa and I both prefer Pho 54. There's apparently one in Burtonsville called Pho Real. Many folks seem to think that Pho Nam in Catonsville/Ellicott City is good. All of this from the following foodblogger's post:

http://howchow.blogspot.com/2010/02/pho-89-in-laurel-and-plan-to-visit-pho.html

Friday, February 22, 2013

Extracting one value from logged ascii packet data

Here is my personal trending tool for work, producing three columns space delimited file that can be imported into Excel

find . -name "*.log" -exec grep Keyword -H {} \; | sed -e 's/: 10/:10/' | awk '{print $1 " " $2 " " $68}' | sed -e 's/.l
og:2/.log: 2/' > ~/output.txt

Thursday, February 21, 2013

Using gnuwin32 find and grep

My issue is that I've just been too lazy to set up my $PATH correctly on my windows system, so I have to call out the full executable path thusly:

"C:\Program Files\GnuWin32\bin\find" . -name "filename.txt" -exec "C:\Program Files\GnuWin32\bin\grep" -H Keyword {} ;

Friday, February 8, 2013

Get UTC in python 2.5

This turns out to be quite native. Corresponding to functions like now() there is a utcnow(), etc. There is a function called strftime to convert a time value to a string with all the usual formatting. Sadly, for whatever version of python 2.5 that I have, the formatting option %f for milliseconds doesn't seem to work, even though if I just print() the time value it prints the milliseconds.

Here is a link that talks about utcnow(). It's in the question, but the rest of this thread is garbage:

http://stackoverflow.com/questions/1599060/how-can-i-get-an-accurate-utc-time-with-python

Here's a great review of the many possible ways to get the current time:

http://stackoverflow.com/questions/415511/how-to-get-current-time-in-python

Among my favorites are:

import datetime

datetime.now()
-or-
datetime.utcnow()

or:

import gmtime,strftime

strftime("%Y%m%d_%H%M%S.%f", gmtime())

or:

import datetime
datetime.datetime.now.().strftime("%Y%m%d_%H%M%S.%f")

see:
http://pleac.sourceforge.net/pleac_python/datesandtimes.html

or apparently now can just be called on its own?

import datetime
now.strftime("%Y%m%d_%H%M%S.%f")

(not quite. See: http://effbot.org/librarybook/datetime.htm

So, here's some info about no %f:

This link for strftime doesn't show %f as a formatting option:

http://www.tutorialspoint.com/python/time_strftime.htm

This link clears things up a bit, apparently time.strftime doesn't support milli-or-miro seconds, but other functions do. Also if the system doesn't support milliseconds, that is a cause of grief:

http://stackoverflow.com/questions/6677332/using-f-with-strftime-in-python-to-get-microseconds

Whenever I tried %f on my system, no result would be produced at all (silent failure). I got around that by using str() which does a conversion including milliseconds but doesn't seem to accept formatting and then just substituting out the characters I didn't want:

timeformatted= str(datetime.datetime.utcnow())

timeformatted = timeformatted.replace("-","")
timeformatted = timeformatted.replace(":","")
timeformatted = timeformatted.replace(" ","_")

This forum thread's commenters repeatedly urged the use of the funtion "translate", I'm not sure why I used replace instead:

http://stackoverflow.com/questions/10017147/python-replace-characters-in-string

Python spit array into equal parts

My need was to take some C code that read in n-byte chunks from a file, and instead take those chunks from an array instead. The problem was helped by the fact that the size of the source array was always fixed to the same size; it was a simple matter of setting up a loop of array size/chunk size and then setting a chunk-sized array to each chunk repeatedly and processing it. Here is the final code:

for row in range (0,[size/chunk]):
a = data[row*[chunk]:(row*[chunk])+[chunk]]

The little bit at the end is important; to subset arrays, the final element in [n:m] needs to be one larger than you would use in C, which would be [chunk-1].

Here's a really thorough discussion, using an unfamiliar keyword "yield" for several suggestions:

http://stackoverflow.com/questions/312443/how-do-you-split-a-list-into-evenly-sized-chunks-in-python/312644