2010
09.03

saving a copy of this here since things on the interweb tend to disappear.

There is some very good info here: http://www.allard.nu/openbsd/ specifically, I found the following hints helpful:

‘isakmpd -d’
Start isakmpd with ‘isakmpd -d’. Isakmpd will output things like wrong file permissions and typos in the configuration file. On connect you might see things like “NO PROPOSAL CHOOSEN” which can either mean that your configuration parameters between the client and the server doesn’t match, or that you have typed the wrong pre-shared key.

‘isakmpd -L’ and ‘tcpdump -avs 1440 -r /var/run/isakmpd.pcap’
This one is really nice to check if your configurations between the client and the server match and also to learn howto create isakmpd.conf files for new clients. With ‘isakmpd -L’ isakmpd will dump, in tcpdump format, everything it sends and recieves to /var/run/isakmpd.pcap. You then check what happened with ‘tcpdump -avs 1440 -r /var/run/isakmpd.pcap’. Look here for an example output of isakmpd -L and tcpdump. This output is typically what you want to send to the mailing list when you want help with something if the above doesn’t help you.

2010
06.17

python stuff

from vegaseat at DaniWeb.Com.


Python Code Snippet (Toggle Plain Text)
# handling date/time data
# Python23 tested vegaseat 3/6/2005

import time

print "List the functions within module time:"
for funk in dir(time):
print funk

print time.time(), "seconds since 1/1/1970 00:00:00"
print time.time()/(60*60*24), "days since 1/1/1970"

# time.clock() gives wallclock seconds, accuracy better than 1 ms
# time.clock() is for windows, time.time() is more portable
print "Using time.clock() = ", time.clock(), "seconds since first call to clock()"
print "\nTiming a 1 million loop 'for loop' ..."
start = time.clock()
for x in range(1000000):
y = x # do something
end = time.clock()
print "Time elapsed = ", end - start, "seconds"

# create a tuple of local time data
timeHere = time.localtime()
print "\nA tuple of local date/time data using time.localtime():"
print "(year,month,day,hour,min,sec,weekday(Monday=0),yearday,dls-flag)"
print timeHere

# extract a more readable date/time from the tuple
# eg. Sat Mar 05 22:51:55 2005
print "\nUsing time.asctime(time.localtime()):", time.asctime(time.localtime())
# the same results
print "\nUsing time.ctime(time.time()):", time.ctime(time.time())
print "\nOr using time.ctime():", time.ctime()

print "\nUsing strftime():"
print "Day and Date:", time.strftime("%a %m/%d/%y", time.localtime())
print "Day, Date :", time.strftime("%A, %B %d, %Y", time.localtime())
print "Time (12hr) :", time.strftime("%I:%M:%S %p", time.localtime())
print "Time (24hr) :", time.strftime("%H:%M:%S", time.localtime())
print "DayMonthYear:",time.strftime("%d%b%Y", time.localtime())

print

print "Start a line with this date-time stamp and it will sort:",\
time.strftime("%Y/%m/%d %H:%M:%S", time.localtime())

print

def getDayOfWeek(dateString):
# day of week (Monday = 0) of a given month/day/year
t1 = time.strptime(dateString,"%m/%d/%Y")
# year in time_struct t1 can not go below 1970 (start of epoch)!
t2 = time.mktime(t1)
return(time.localtime(t2)[6])

Weekday = ['Monday', 'Tuesday', 'Wednesday', 'Thursday',
'Friday', 'Saturday', 'Sunday']

# sorry about the limitations, stay above 01/01/1970
# more exactly 01/01/1970 at 0 UT (midnight Greenwich, England)
print "11/12/1970 was a", Weekday[getDayOfWeek("11/12/1970")]

print

print "Calculate difference between two times (12 hour format) of a day:"
time1 = raw_input("Enter first time (format 11:25:00AM or 03:15:30PM): ")
# pick some plausible date
timeString1 = "03/06/05 " + time1
# create a time tuple from this time string format eg. 03/06/05 11:22:00AM
timeTuple1 = time.strptime(timeString1, "%m/%d/%y %I:%M:%S%p")

#print timeTuple1 # test eg. (2005, 3, 6, 11, 22, 0, 5, 91, -1)

time2 = raw_input("Enter second time (format 11:25:00AM or 03:15:30PM): ")
# use same date to stay in same day
timeString2 = "03/06/05 " + time2
timeTuple2 = time.strptime(timeString2, "%m/%d/%y %I:%M:%S%p")

# mktime() gives seconds since epoch 1/1/1970 00:00:00
time_difference = time.mktime(timeTuple2) - time.mktime(timeTuple1)
#print type(time_difference) # test
print "Time difference = %d seconds" % int(time_difference)
print "Time difference = %0.1f minutes" % (time_difference/60.0)
print "Time difference = %0.2f hours" % (time_difference/(60.0*60))

print

print "Wait one and a half seconds!"
time.sleep(1.5)
print "The end!"

2010
06.16

Programmers 10 Commandments

taken from: Dirk’s Junk Box.

The Programmer’s 10 commandments
Tue, 03/04/2008 – 22:49 — Dirk
After more than a decade in the IT Industry, I have found, that few junior programmers make a success of their careers. Below I list what I consider the 10 commandments of a programmer should be. I’m convinced that any programmer that practice these will make a success of their career.

1. Know more than you “need” to know.
Knowing a programming language and being able to program in it is not enough. In today’s IT industry it is hardly enough to qualify you for doing a few loose projects at home.

You are working on a computer, that computer has both hardware and software components. You need to have a working knowledge and understanding of both. It is highly unlikely that you’ll be working on a stand-alone computer, so you also need to know at least the basics of networking.

So, when will you know enough? The answer is simple… NEVER!

    2. Learn at least one new thing every day!

Every successful programmer I’ve ever met, has made learning new things on a daily basis an art form.

The IT industry moves at a ridiculous pace, make peace with the fact that you will never catch up with the current scene of all the available technologies. Be aware of the fact, that if you do not learn new things regularly, you will be useless outside your current place of work within 18 months.

3. Getting it to work is NOT ENOUGH!
Take pride in what you do. Honestly, just because you finally got your program working, does not not mean it is done. Clean up your code, comment it where needed and test the damn thing thoroughly.

4. Consider those that come after you.
Think of the guy that has to maintain your code, as a homicidal psychopath, that knows where you live. Write your code in a way that would make sure he never gets the urge to seek you out.

Too many programmers write their code in a way understandable to nobody other than themselves and the compiler or translator they happen to be using at the time. Don’t be one of them and when you find one, bang them over the head with a clue-bat.

Download some source code from a reputable open source project and look at it, compare what you produce to it and you’ll quickly find where you can improve.

5. Document what you do.
With applications like Javadoc and doxygen, there are no more excuses.
If you don’t document your applications you can not, by the biggest stretch of the imagination, call yourself a programmer.

At best, you are a glorified typist.

6. Follow, respect and take responsibility for the development process.
The development process from requirement gathering, through testing, deployment and maintenance. Has been developed by those you are now learning from. They had to learn it from the school of hard knocks.

Respect this experience and use their knowledge.

So when exactly are you done?
Only once the application is deployed, running and requires no more changes, can you say you are done. Before you reach that point, you can not factually state that you have finished your work.

7. Respect your peers.
Throughout your career you will be working with many other programmers, developers, software engineers etc. etc. etc.

You might reach a point where you are factually the most experienced or trained individual on a team. This is when you need to be doubly careful. Do not allow yourself to become arrogant.

In years gone by, it was possible for a single programmer to see to an employers needs. These days, if you want to progress beyond “Hallow world”, you’ll have to learn how to work with others.

Nobody likes an arrogant SOB, no matter how good he is. This will eventually lead to that individual’s downfall.

The IT industry is one of the few where a good reputation can get you far beyond the level of your formal education. A bad reputation on the other hand, will see you getting stuck at the bottom of the pile, regardless of how many degrees or certificates you spam your CV with.

8. Respect the user.
Yes, there will be times when you think the user is the most irritating, uneducated, short sited being produced by this universe, for the sole purpose of making your life hell.

I’ve found, that when you respect the user, listen to their opinions and grievances while taking action to improve their lives. You invariably end up with someone, that will listen to you and take your advice.

Over the short term, this could take a lot of work and effort. But over the span of a career, those users are the best references you can possibly gather. They are the ones that will tell your future employer, that they are absolutely devastated at seeing you leave and that they don’t understand why your current employer can’t make a plan to keep you.

9. Demand the best of yourself.
Do what you have to, check it, improve it, check it again, read some relevant material on what you have to do, check it again, test it to death, clean up your code, test it again, do your documentation and… test it again.

Even after you have done this, you can be sure there is at least one more thing to do. Find it and do it.

Do all of the above to the best of your ability.

10. Demand the best from your peers.
You will never survive if you are the only one doing all the things needed in order to make sure your product is a good one.

Your peers share responsibility with you, if they are not doing their best it will come back to bite you when you least expect it. Do not tolerate incompetence, but also help and educate where needed.

2010
06.03

my .vimrc


syntax on
set nocompatible
set autoindent
set smartindent
set tabstop=4
set shiftwidth=4
set expandtab
set showmatch

# map F2 key to toggle auto indent while pasting indented code.
nnoremap :set invpaste paste?
set pastetoggle=
set showmode

2010
03.15

never forget *NIX tools…

*NIX Commands. These are endlessly useful.

EOP

2010
03.12

VIM info….

hopefully blogging this will help me remember!

I was setting up nagios at my new job and found myself in a position where all I have is vim to select, copy, and paste text(don’t ask, I use evilwm). I came across this useful bit of info from This page on creating splits or multi-file editing in VIM.
The below text is copied from the above link.

Opening a file in a split

Assuming you are already editing a file in a vim session and want to split the screen and edit a second file, you can use either of these commands:

:sp filename Splits the screen horizontally and opens filename in the new area.
:vsp filename Splits the screen vertically and opens filename in the new area.

For most purposes, horizontal splits are easier to manage. Any split can be further split — you can edit as many files in a single instance of vim as you like.

Managing splits

Once you are editing multiple files, you will probably need to move back and forth through your files and manage the size of the splits so that you can see the relevant portions of the files you’re interested in.

The prefix for all the below commands is — that is, hold down Ctrl and type w. Press before typing any of the below commands.


Moves to the next split.
k Moves to the split above the current split.
Up Moves to the split above the current split.
j Moves to the split below the current split.
Down Moves to the split below the current split.
+ Increases the size of the current split by one line. (Try combining this with counts -- e.g. 5+ will make the split five lines bigger.)
- (Minus sign) Decreases the size of the current split by one line.
_ (Underscore) Maximize the current split (that is, make it take up as much room as possible.)

Saving and quitting

Each split acts something like an individual instance of vim — so

:w

and

:q

work on the current split.
If you want those commands to apply to all the splits instead of just the current one, add a to them

--

for instance,

:wa

saves all the open files,

:qa

quits all open files (and exits vim), and

:wqa

saves and then closes all open files.

2010
02.18

commanding windows…

in my new job i’ve been tasked with something ugly. webifying a windows CLI command. in my venture to find a way for PHP to spawn an interactive shell I came across this site: CommandWindows.Com.

Yes, yes, yes… windows sucks and we all know it(this is a very good blog post, highly recommend reading it!).
It turn’s out good’ol sysinternals made psexec.exe with the purpose of spawning CLI commands that require interactive console(eg. Platform LSF tools).

Put this one in the books for some way back memory I hope to never need in the future.

2010
02.12

horrible, ugly, bad BASH string operations…

I do and do not recommend learning this.

Advanced BASH Programming – String Operations

They certainly can come in handy though if you don’t want to do some basic grep/awk work.

little example:

$ foo="my words"
$ echo ${foo#my}
words
$ echo ${foo:1}
y words
$ echo ${foo:2}
words
$ echo ${foo:3}
words
$ echo ${foo:4}
ords
$ echo ${foo:1:2}
y
$ echo ${foo:1:3}
y w
$ echo ${foo:1:4}
y wo
$ echo ${foo:1:5}
y wor
$ echo ${foo:1:6}
y word
$ echo ${foo:2:6}
words
$ echo ${foo:3:6}

2010
02.01

Debugging python…

insert

import pdb; pdb.set_trace() 

in to area of code area you would like to debug then run script.

These commands allow you to step through the code from the point of where pdb.set_trace() is placed in your script.

p – print the content of an object
n – next line
c – continue through rest of script, to next break point, or next pdb.set_trace()
s – step in to function/routine and make edits or view
var = ‘new value’

start with this script.

#!/bin/env python
import pdb

var_0 = 'day'
var_1 = 'night'

print '   var_0: %s\n   var_1: %s' % (var_0, var_1)
#pdb.set_trace()

print 'from %s in to %s and back again.' % (var_0, var_1)

run it with the pdb line commented and you get this.

$ ./day.py
   var_0: day
      var_1: night
      from day in to night and back again.

Now uncomment the pdb line and run it again.

$ ./day.py
 var_0: day
 var_1: night
> /home/msnow/bin/day.py(10)()
-> print 'from %s in to %s and back again.' % (var_0, var_1)
(Pdb) n
 from day in to night and back again.
--Return--
> /home/msnow/bin/day.py(10)()->None
-> print 'from %s in to %s and back again.' % (var_0, var_1)
(Pdb) n
$

This shows you part of the program running, then dropping in to the debugger just before the area of code you want to look at.
Now we will change the values assigned to val_0 and val_1 withough editing the file.

$ ./day.py
 var_0: day
 var_1: night
> /home/msnow/bin/day.py(10)()
-> print 'from %s in to %s and back again.' % (var_0, var_1)
(Pdb) var_0
'day'
(Pdb) var_1
'night'
(Pdb) var_0 = 'morning'
(Pdb) var_1 = 'evening'
(Pdb) n
from morning in to evening and back again.
--Return--
> /home/msnow/bin/day.py(10)()->None
-> print 'from %s in to %s and back again.' % (var_0, var_1)
(Pdb) n
$
2010
02.01

i’ve been learning bits of python here and there for work and for play and I came across a simple solution to a simple problem I had to solve in python.
There are some things in python that once you realize how things work you think “that is so simple!”. I had one of those moments.

This particular solution came up when the need to compare user disk quotas arose on different filers.

list_a = { 'a' : 123, 'b' : 456 }
list_b = { 'a' : 321, 'b' : 654 }
list_c = {}
for key, val in list_a.items():
    for que, wal in list_b.items():
        if key == que:
            list_c[key] = [ val, wal ]
list_c
{'a': [123, 321], 'b': [456, 654]}