Tag Archives: applications

NCOER Spreadsheet

Last week, I complained about how bulky VBA (Visual Basic for Applications) can be.  My current project is to create a spreadsheet to keep track of upcoming NCOERs.  This is an easy task in anything but the most used and abused application the admin personnel in the Army use, Microsoft Excel.  Now, the data is easy enough to pull once you get an SSL connection with this website (to access you need to use an AKO Username/Password.)  The Interactive Web Response System will allow you to pull data on any past, due or current NCOERS (Evaluations).  This is great as I can track our evaluations as they move up the chain and will see when they are late.  Unfortunately, the web designers have only sorted the information by last name.

So, my basic program is complete.  I can make a connection (fortunately, MSXML6.0 makes an easy post request to an SSL website… something that if using Python, is not an easy task.)  It would appear that it is utilizing Internet Explorer’s library for the connection.  Once the connection is made and the data is loaded, then I parse.  Here is where VBA gets bulky.  Fortunately, I can use a reference to VBScript’s RegEx object, but it is far from being as complete as say, any other regex engine in any other language.  On top of that, parsing text through splits and such is an amazing pain.  Here’s an example.

Python:

import re
test = 'A simple "test of the languages" will show how bad VBA is!'
a = re.findall(re.compile(r'".*"',re.I),test)
print "Result = %s" % a[0]
## Result = "test of the languages"

VBA:

Private Sub CommandButton1_Click()
    ' must include Microsoft VBScript Regular Expressions 5.5 in references
    Dim re As New RegExp
    Dim testing As Variant
    Dim test As String
    ' to escape quotes "" can be used or chr(34).
    ' unbelievably, chr(34) is easier to read than ""
    test = "A simple " & Chr(34) & "test of the languages" & Chr(34) & " will show how bad VBA is!"
    re.Pattern = Chr(34) & ".*" & Chr(34)
    re.IgnoreCase = True
    Set testing = re.Execute(test)
    Range("A1").Value = "Result = " & testing(0)
    ' Result = "test of the languages" in "A1"
End Sub

See the difference?  I know it’s pretty close but keep in mind, this is a single line of text.  Multiple lines, large text files, etc. can be horrendous.  What in the world is left, mid and right anyhow?  I know 90% of this is that I refuse to touch this language if I can avoid it but still, this is ridiculous!!

Microsoft Access : XFDL Viewer – Introduction

I know, I said it yesterday that it is rare that I develop on Windows, but this is a long promised application.  In 2007, my unit administrator (in the U.S. Army Reserves) suggested code that would allow batch loading XFDL forms from MS Access.  Due to the scope of the Apps 4 The Army project, I was limited to using a web application.  Now that the project is submitted and done, I am free to do my original plan, which is code to do the same process in MS Access.

Starting this today, I realized how much I hate doing Visual Basic.  Particularly, VBA is very painful!!  It’s not that the language is bad but it just always feels bulky and pieced together to me.  It seems to lack the professionalism of C/C++ and the flow of Python.  But, I may be alone in that.

I have a question for my readers though. Would anyone have an interest in seeing this project on SourceForge?  The Apps 4 the Army project is no longer my intellectual right, but a desktop application, a MS Office Plugin, etc… that’s all good to make public.  So let me know, if I get readers saying we’d like to help; then I will happily move this project to SourceForge!

To the authors of Hamster.

I found your project listed on this blog (which is a great read for Linux users)!  I will not rewrite that author’s excellent post, if you’re curious what Hamster is, go read the blog!  This tool is great for anyone obsessed with data and time tracking.  Essentially, it will show you what you do during the day.  For those who are bad at time management (me), then this tool can help increase performance.  But in using it, I found that I wanted something more.  Specifically, I didn’t want to tell it what I was doing.  I mean, I switched from coding my wardriver to blogging five minutes ago and I still haven’t updated.  Even worse, what happens when I’m multitasking between work, programming, army, etc.  I would like this application to update what is happening as I change it, rather than take the five seconds to update my current task.  I know, I’m lazy.

So what do I think should happen?  Well, I’ve commented on the post that I found this program that I would like it to be automated.  Take a ‘picture’ every minute of active processes and then use that data to associate that program with your current activity!  For example, the browser is open (you can even catch the website name) and you have a setting that associates that program/page with an activity, Hamster then updates what you are doing.  You could even go so far as to use what window is in front, the next behind, the next behind, etc to rank the amount of work you are doing with that task.

With my Army project done, my wardriver being worked on at a steady pace, I think this would be a fun program.  Anyone else interested in this?  Let me know through your comments…

Garmin Wardriver – Prototype Released

This project went together smoother than I thought it would.  The source code and application are available on it’s SourceForge page.  I’m still working to create a range for the networks and then use circles as points.  I’m thinking if I factor in strength, I can come up with an approximate (no where near exact) range.  Unfortunately, without the right antenna, it’s not likely to come up with a direction but I can get the entry and exit and create a circle around it from that.  Unfortunately, to convert the minute data to feet will take some fancy math due to variations in minutes with the longitude.  More on that in a future post.

For those wanting to use the application, here are the steps to get it working.

  1. Ensure you have iwlist, gpsbabel and Google Earth installed.
    • sudo apt-get install wireless-tools gpsbabel googleearth-package
  2. Plug in your gps.
  3. Test with ‘sudo gpsbabel -T -i garmin -f /dev/ttyUSB0
  4. If that pulls data, run ‘sudo ./garminwardriver.py
  5. Open your ‘out.kml’ in Google Earth (Start Google Earth->File->Open)

And there you go, data that can be drawn on any wifi card with any GPS device (if you change the code for your device).  Try it out and let me know if it works or what errors you come up with.  This is just a prototype, so expect v1.01 to be out soon with updates.

Update:

I wrote this post and completely forgot to add the screen shots!

apprunning
Gathering Data
googleearth
Google Earth Data

Garmin Wardriver – Part 2

I’m very happy to say, this is a simple project, to get working in its most basic form.  Note, I said it’s most basic form so no hate mail on the fact that this is nothing more than a quick script!  There are plans to actually go deeper, make this open to more than my device, not use already existing programs, etc.  But for the basic concept and starter, I’ve made this program use gpsbabel to get the gps information and iwlist to get the network information.  I had started with pywifi but found this to be a problem because there was an overbound error.  This bug will be reported, it seems it has a problem with converting an integer to a float on a 64bit machine.

So with no futher ado, here is the script:

#!/usr/bin/env python
import os, re, time

# DEATH FUNCTION
def die(msg):
	print ' [*] ERROR: %s' % msg
	exit(1)

# ENSURE WE ARE ROOT
def checkroot():
	if os.getuid() != 0:
		die('Run this program as root.')
	return

# GET NETWORK INFO
def getessid(dev):
	nets = os.popen('iwlist %s scan' % dev).read()
	pat  = re.compile(r'ESSID:".*"')
	mess = re.findall(pat, nets)
	found= []
	for find in mess:
		found.append(find.split('"')[1].split('"')[0])
	return found

# GET GPS INFO
def getposition(dev):
	pos = os.popen('gpsbabel -i garmin,get_posn -f %s' % dev).read()
	pos = pos.splitlines()[1].split(' ')
	return [pos[1],pos[2]]

# RUN IT
def main():
	checkroot()
	found = getessid('eth1')
	pos   = getposition('/dev/ttyUSB0')
	for find in found:
		print 'ESSID: %s @ %s | %s' % (find,pos[0],pos[1])
	exit(0)

if __name__ == '__main__':
	main()

So what you see here is that I’m using os.popen() to call my programs to draw data.  Unfortunately, iwlist is painfully slow, to the point there’d be a five second delay on some slower machines between the call and having the data ready.  This is why I want to develop the application to not be dependent on other programs, but for the time being, this works as proof of concept in the data gathering stage.  It’s now just a matter of adjusting the code to run this constantly and load data to an overlay when entering and leaving an ESSID’s area.

Any comments for improvements?  Don’t forget, you can join this project any time on SourceForge!

Garmin Wardriver

For my birthday, my wife got me a GPS (Garmin Venture HC).  I have been disappointed in it’s integration with Linux, most particularly it’s ability to communicate with gpsd (usb input, not serial).  I had high hopes of doing some wardriving and kismet does not gather any of the data despite it’s configuration.  I can get gpsd to get some cryptic messages from the device but I found that this command: `gpsbabel -T -t garmin -f /dev/ttyUSB0` will generate the current coordinates.  So instead of getting frustrated, I’ve decided to open my first SourceForge project.  You can find it listed as Garmin Wardriver.

The concept seems simple enough, generate location through direct communication with the GPS device or through the gpsbabel command above and then gather a list of local ESSID’s with their strength.  With this data, updated each second, one could generate a location for entering an ESSID’s area, it’s strength as you move through and when out.  Output this to an overlay for a program such as Google Earth and that is a wardriver!  I can see this branching to more advanced uses but for the basic proof of concept, a command line program should suffice.  This will be written in Python and I’ve looked into utilizing the pygarmin and pywifi modules instead of generating information from preexisting programs.

Violating IT Policy!

So, I work as a social worker and we are not expected to do much more than document with our computers. For job security reasons, I use my hobby programming in work to make the workplace more efficient and ensure that I have a job tomorrow! There are some problems with this, most notably, we are not setup to do programming. So I’m going to list my favorite tricks to get setup at work.

First of all, although we work through a company ethernet connection; we do have some flexibility. For one, I read the IT Policy and it specifically states I cannot install an executable onto the harddrive. Well, problem easily solved, I have a flash drive, so in comes a website for portable applications.  Here’s the applications I use the most.

*        GOOGLE CHROME

Google Chrome is a great browser.  It’s ability to interpret javascript leaves IE# in the dust!  As for it’s portability, just like most of these, just run the executable and install it to your flash drive (or if you want a little more speed and less portability, your harddrive).  Now, Google Chrome works great right out of the box, except one thing.  It’s flash needs to be updated.  Fortunately, this is easy to solve and there are only a few steps.

  1. Get FlashPlayer XPI for Windows.
  2. Rename the *.xpi to *.zip and copy flashplayer.xpt and NPSWF32.dll
  3. Paste those two files into <install directory>/App/Chrome-bin/<version>/ directory.  Replace install directory with where you installed the application and version with the folder that is your version number.

**            NOTEPAD++

This stuff is simple, but I thought I’d post a link for the plugins.  These are easy to install, plugins go in the \Plugins\ folder, configuration files go in the \Plugins\Config\ and documentation goes in \Plugins\Doc\. Here are my favorite plugins:

***   BOA CONSTRUCTOR

For this to work, you’ll need Portable Python which installs similar to most things but it altered file associations and so I just extracted it and then it runs fine.  You’ll also want to install wxPython which is a module for python located on the Portable Python Page.  For Boa Constructor, download the file and install it on a computer of your own.  From there it copies onto the flash drive just fine, just make sure to update the settings for your main python exectuable since it won’t be in the computer’s path.

****       CODEBLOCKS

CodeBlocks is another program that will copy straight from the computer to your flash drive to make it portable.  The real trick is getting paths set and configuring WX if you’re interested in rapid development of GUI’s in C.  So here’s the quick run through.  For paths, I struggled with this on my work computer but it will not read paths that have a space.  It sees that space as the end of your path, so when setting a path for a library, for example WX, make sure you store that in a location that does not have a space in the path.  As for configuring WX, here’s what I did.  I went to the WX Pack site and got the package, which is great.  No need to compile or anything, does it all on it’s own with a directory to link your CodeBlocks library to, just be aware, this will take a lot of space on your flash drive, but with all of these things, you can always store them locally if you are daring that much against your local IT Department!

*****          CYGWIN

The biggest pain and the best program to have for avid Linux users.  This site makes a great tutorial on how to do this.  And rather than reiterating this, I’ll add my own changes.  The biggest thing was I changed the startup script and then linked that script on my desktop.  The first thing to do is to install Cygwin on your flash drive, be aware it may not install all the programs you want.  I did it three times before it all worked.  Then you have to mount the drive as you cannot do this or it will write to the registry.  As for my script, here’s what I wrote:

;rem creating a startup script
@echo off
:: clear
cls

:: locate directory
echo Locating directory...
for /F %%A in ('cd') do set WD=%%A
:: create path
echo Setting Path...
set path=%WD%\bin;%path%
set SHELL=/bin/bash
set CYGWIN=codepage:437
set HOME=/home/zbert
:: mount fs
echo Mounting File System...
bin\mount -bfu %WD%/ /
bin\mount -bfu %WD%\bin /usr/bin
bin\mount -bfu %WD%\lib /usr/lib
:: login
echo Logging in...
echo.
echo.

if "%1" == "" GOTO noopt
	if "%1" == "c" goto cmd
	if "%1" == "-c" goto cmd
	if "%1" == "--cmd" goto cmd
	if "%1" == "h" goto help
	if "%1" == "-h" goto help
	if "%1" == "--help" goto help
	echo  [*] ERROR: Unrecognized option.
	goto usage

:usage
echo usage: cygwin [c^|h^|-c^|-h^|--cmd^|--help]
goto help

:help
echo.
echo          Portable Cygwin Loader v1.0
echo.
echo     Commands:            *Run normal with no options.
echo        c ^| -c ^| --cmd     Run in Command Prompt.
echo        h ^| -h ^| --help    Display Help Message
echo.
echo        Copyright Skelton Computers © 2009
echo.
goto end

:cmd
echo cls > bin\bash -l -i
GOTO end

:noopt
bin\bash -l -i
GOTO end

:end
set path=%WD%\bin;%path%
@echo on