Code Sample Geek

Auto Connect to VPN on Boot & Login in MacOS Sierra

I added VPN connectivity to my network and I wanted to make sure the connection to the remote VPN was always running. One way to do this is to use AppleScript to check the connection status. The problem I had was that the AppleScripts that I found no longer worked with MacOS Sierra.

After some digging, I got it to work. Here’s my script:

on idle
  set myVPN to "VPN (dallas)" -- set name of VPN connection
    set isConnected to do shell script "scutil --nc show \"" & myVPN & "\" | grep -c Connected"
  on error
    set isConnected to "0"
  end try
  if isConnected = "0" then
    do shell script "scutil --nc start \"" & myVPN & "\""
  end if
  return 15 -- how often to check, seconds
end idle


Change the variable myVPN to the name of your network connection. Here mine is VPN (dallas).

Also modify the return value if you want the time between checks to be longer or shorter. Here I’ve set mine to 15 seconds.


These are the some of the pages that I started with. The instructions for script generation and auto-boot still apply. So you can still reference them for those other tasks:


Some other tech references which helped:
* “on idle” reference

Code Sample Flex Programming Technology

LightCharts – Lightweight charts for Flex



A lightweight line-chart library for Flex.


I created LightCharts for a project of mine that involves tracking many stock market symbols. Originally I was using the Adobe Flex Charting library, but found that performance suffered greatly given the number of charts I was using (around 60+), the amount of data displayed, and the constant real-time updates. Of course this isn’t necessarily due to poor coding on Adobe’s part, it’s just that their library contains an amazing amount of features to handle a variety of needs, consequently it’s very heavy. I didn’t need a lot of features, just a nimble way to display data.

I searched the Internet for other charting libraries which I could use and stumbled across a fantastic set of components created by Keith Peters called Minimal Comps. Keith’s library is extremely lightweight and it would have been a good fit, but MinimalComps is geared towards the pure Flash environment and not Flex – a major issue being the disparity in the component lifecycle.

Nonetheless, I was inspired by his code so I decided to use it as a starting point, adding and changing what I needed along the way.

Code Sample Geek Programming Python

Generating Random Session IDs

For any online service you must login so you can gain access to your stuff. So that you only have to put in your password once, the website must maintain a special unique character sequence called a session key to know that you have already authenticated.

There is a problem with these keys, however, if they are not truly random. This is detailed in a paper I stumbled upon entitled Brute-Force Exploitation of Web Application Session IDs by David Endler. It covers ways in which these keys can be “hacked” because they are not unique, but rather follow some sequence which can be guessed. He lists some major websites which he was able to get access to information that should have been private.

The paper got me thinking about how to generate random session keys, so I created some quick Python scripts using Twisted which demonstrates my solution. (This was my first time using Twisted, so it’s very possible that there is a better way to structure the code).


The character buffer in the server is used to generate new keys.

To fill the buffer:

  1. Create a list of websites which themselves deliver random web pages (eg, wikipedia)
  2. Select a website from random and ask for a random page
  3. Grab the data within the HTML body tags and put that string in the character buffer
  4. When the buffer needs more data, go back to 1.

To generate X number of keys:

  1. Grab two random lengths of the character buffer. Use one to re-seed the random generator and the other as the basis for the new session key. Create the session key using MD5 and the key seed
  2. Update() the current MD5 session key using a generated random character / string
  3. Add that key to the buffer.
  4. When the key buffer needs more keys, go back to Step 1. For every Y number of keys generated, go back to Step 0.


We don’t use a new seed for each MD5 session key because the buffer will be emptied too quickly. Of course, the settings for the buffer size, etc could be tweaked.


Running the server code on my Mac Mini (2.16GHz Dual Core) and 5 clients on another machine, I was able to service ~8000 keys/sec (~750 million keys/day).


My experiment satisfied my curiosity and answered the questions from my own project.

There are, of course, many tweaks that can be made. Send me the code changes to your favorites and I’ll include them.

“Click to download the client server files.”:/downloads/code/


Code Sample Flex How-To Programming

How to do custom chart annotations in Flex

Hunting around the ‘Net, I found a few good examples of creating chart annotations in Flex.

One example app which helped me greatly was from a “blog posting by Ely Greenfield”: If you’re interested, you can view it on his website: “chart annotation demo”:

Unfortunately, the code you can download from his site is a little old so it has problems compiling in Flex Builder 2+. I have updated the code, fixed some bugs in it and have it available here: download

Ely has other interesting demos on his site which are worth checking out. Some of my favorites are: the “variable radius pie chart demo”:, the “interactive bubble chart demo”:, and the “dashed lines demo”:

h3. Resources

annotation example by Ely Greenfield

  • “”:
  • demo: “”:

annotation example by Brendan Meutzner

  • “”:
  • demo: “”:
Code Sample Geek How-To Technology

How to build and install the Metakit DB for Python on MacOSX

Ever since I used it years ago on a geek-project for my Zaurus, the Metakit DB has always been a favorite of mine. I had the chance to use it again on another personal project and this time on MacOSX. Unfortunately, the prebuilt binaries on the Metakit site are for older versions of MacOSX, so I had to build it myself.

Normally one would simply follow the “Metakit installation instructions”:, but they are old and didn’t work correctly with 10.5 Leopard. I scraped enough information together from the Internet to get it working, but I had to do a lot of research. To save others the same hassle, I have put together all of the changes and put them here in their entirety:

Building Metakit

Make sure you have Xcode installed on your system before starting.

Get the latest source from the “Metakit downloads page”: At this time the latest version is @metakit-

Uncompress the archive in a work directory and run the following commands:

> cd builds
> ../unix/configure --with-python=/System/Library/Frameworks/Python.framework/Versions/2.5

Note: Your Python install might be in a different location. If so, give the @–with-python@ arg the proper value.

“Fat” binary setup

If you need this to run on the PPC architecture you will need to make a couple of modifications to @./builds/Makefile@ after running @configure@, otherwise you can skip this step and build the binaries with @make@.

Find @CXXFLAGS = $(CXX_FLAGS)@ and change to the following:

CXXFLAGS = $(CXX_FLAGS) -arch ppc -arch i386 -isysroot /Developer/SDKs/MacOSX10.5.sdk

Find @SHLIB_LD = g++ -dynamiclib -flat_namespace -undefined suppress@ and change to the following:

SHLIB_LD = g++ -dynamiclib -flat_namespace -undefined suppress -arch ppc -arch i386

Build the binaries

Run your typical @Makefile@ commands:

> make
> make test

Installing Metakit

Rename the shared library which is now in the @./builds@ directory:

> mv Mk4py.dylib

And copy the following files to @/System/Library/Frameworks/Python.framework/Versions/2.5/Extras/lib/python@ (be sure to adjust the path name for your version of Python):


Testing Metakit

At this point you should have a working system and ought to be able to run the following command in a Python shell without issue:

>>>from metakit import *

Enjoy !

h3. Resources

  • “Metakit for Python website”:

  • “helpful instructions from”: