Monday, February 28, 2011

openVPN, SliceHost, and OSX

Spent some time at the local coffee shop today, and got really paranoid about others sniffing my wireless bytes...  so I spent the whole visit setting up openVPN on my slicehost.

I found a good guide on the internet, but had to make some modifications to get it to work.

I am currently using the Viscosity openVPN client for osx: http://www.thesparklabs.com/viscosity/

Here is the guide that I used: http://ggin.com/blog/openvpn-setup-on-vps/

Modifications:

(I didn't build it from source)

cp -R /usr/share/doc/openvpn/examples/easy-rsa /etc/open/vpn

Should be:

cp -R /usr/share/doc/openvpn/examples/easy-rsa /etc/openvpn

When he says to do: ./vars I had to do source ./vars first.

Before doing:

sudo cp /usr/share/doc/openvpn/example/sample-config-files/server.conf /etc/openvpn/

I had to gunzip the server.conf.gz file and the path should actually be:
/usr/share/doc/openvpn/examples/sample-config-files/

For IPTables rules I used:


sudo vim /etc/iptables.test.rules
*nat
-A POSTROUTING -s 10.8.0.0/24 -o eth0 -j MASQUERADE
COMMIT
*filter
-A INPUT -i tun+ -j ACCEPT
-A FORWARD -i tun+ -j ACCEPT
-A FORWARD -o tun+ -j ACCEPT
-A INPUT -p udp --dport 1194 -j ACCEPT


.. and that was basically it! Just make sure to use the right files when setting up Viscosity:

CA ca.crt
Cert username.crt
Key username.key

(I don't have User/Pass authentication enabled in the client)

Wednesday, February 23, 2011

HDF5: Fixed length strings

For the sake of Google searches - here is a bit of code on how to create compound data types with fixed length strings in HDF5 H5 files.


/**
* Create the H5 file with the contents of the Data list.
*/
public Boolean create() {
try {
FileInfo h5 = new FileInfo(this.h5Path);

H5FileId fileId = null;
if (this.makeNew) {
fileId = H5F.create(h5.Name, H5F.CreateMode.ACC_TRUNC);
H5F.close(fileId);
}
fileId = H5F.open(h5.Name, H5F.OpenMode.ACC_RDWR);

H5DataTypeId stringMeasurand = H5T.copy(H5T.H5Type.C_S1);
H5T.setSize(stringMeasurand, (uint)MEASURAND_LENGTH);

H5DataTypeId stringChannel = H5T.copy(H5T.H5Type.C_S1);
H5T.setSize(stringChannel, (uint)CHANNEL_LENGTH);

H5DataTypeId tid1 = H5T.create(H5T.CreateClass.COMPOUND,(uint)System.Runtime.InteropServices.Marshal.SizeOf(typeof(dictStruct)));
H5T.insert(tid1, "Measurand", 0, stringMeasurand);
H5T.insert(tid1, "Rate", MEASURAND_LENGTH, H5T.H5Type.NATIVE_FLOAT);
H5T.insert(tid1, "Channel", MEASURAND_LENGTH+sizeof(float), stringChannel);

// Rank is the number of dimensions of the data array.
const int RANK = 1;
ulong[] attributeDims = new ulong[RANK];
attributeDims[0] = (ulong)data.Count;

H5DataSpaceId spaceId = H5S.create_simple(RANK, attributeDims);
H5DataSetId dataSetId = H5D.create(fileId, "/foo",
tid1, spaceId);

H5D.write(dataSetId, tid1, new H5Array(data.ToArray()));
H5T.close(tid1);

H5D.close(dataSetId);
H5F.close(fileId);

return true;
} catch(Exception ex) {
Console.WriteLine(ex.Message);
return false;
}

return true;
}



/**
* Create a new struct with the specified measurand information.
*/
private unsafe dictStruct addRow(string measurand, float rate, string channel) {
dictStruct retval = new dictStruct();

byte[] mBytes = System.Text.Encoding.ASCII.GetBytes(measurand);
byteCopy(mBytes, retval.measurand,MESSAGE_LENGTH);


retval.rate = rate;

byte[] channelBytes = System.Text.Encoding.ASCII.GetBytes(channel);
byteCopy(channelBytes, retval.channel, CHANNEL_LENGTH);


return retval;
}


And then how you define your struct:


public const int MEASURAND_LENGTH = 16;
public const int CHANNEL_LENGTH = 12;

[StructLayout(LayoutKind.Sequential, Pack=1)]
public unsafe struct dictStruct {

public fixed byte measurand[MEASURAND_LENGTH];
public float rate;
public fixed byte channel[CHANNEL_LENGTH];

}

Sunday, February 20, 2011

What a week for my poor poor Jeep

How many people get their vehicle broken into and rear-ended in the same day?  Well, there's at least one..

I know that I live in a sketchy area for work (Lancaster, CA).  Because of that I usually leave NOTHING inside the jeep, and even leave the doors unlocked.  (Thinking that if they see the doors are unlocked, they won't slash my soft top to gain access to the inside of my vehicle)

My jeep has an after market stereo - and I ALWAYS take the head unit inside with me every single night - except for this one time.  I had been driving the jeep for the last few days, and was really getting tired of bringing everything in at night (and bringing everything back out in the morning), so I decided to just leave the headunit in the (locking) center console of my jeep.  Mistake.

Woke up early on February 16th I saw that the center console of the jeep was wide open, and a few of my random car/electronic manuals were sitting on the passenger seat.  They did it.  They had pried open the center console with a screwdriver (I assume).  I don't imagine it was difficult, the center console is pretty cheap, but still it had to take some effort.

I did not do a complete inventory, but it looks like they walked away with:

  • Stereo head unit

  • Car charger

  • Car dock

  • mini stereo cable

  • caffeinated mintes.  (really? you took my mints??)


Didn't bother calling the police, since it was likely < $100 worth of theft and they took so god damn long to show up the last time one of my cars got broken into.

So the day is off to a great start... and naturally I have a horrible day at work, where nothing works, and nothing works in my favor.

This day also happens to be the last day of work for one of my coworkers. (Who is working at another location)  I had planned to meet him and my other coworkers at a restaurant for a going-away dinner.  It was rainy, the roads were slickish, and I was stopped in traffic at a stop light.  I heard the tires screeching, I heard a metal on metal bang behind me, and then I felt my Jeep being pushed from behind.  I moved a grand total of a foot, threw the e-brake and the hazards, and got out.



Behind me was a rather destroyed looking black Jetta (attached to my rear bumper), and behind her was an old lady driving a CrownVic.

Just when I didn't think the day could get any better, I became the lead car in a three car pile up.

As you can see in the picture to the right, not much damage occurred to the jeep, just a dent under the license plate.  (You can also see a bit of her car still embedded in my bumper!)  I called 911 and they promptly had firetrucks, ambulances, and a CHP officer at my location within 10 minutes.

Have you ever dialed 911 on an Android phone (or even a smart phone) before?  I certainly haven't.  I was surprised to see that Android locks out all data connections for 5 minutes after an "Emergency Call" has taken place, to allow 911 to call you back.  Pretty neat.

The CHP officer collected all of our information, and eventually let me go while he dealt with the severely damaged vehicles.

What a day.

I think I will gladly fork over that additional $80 a month for a garage in my Lancaster apartment now... at least it will give me peace of mind while sleeping at night.

I want to say thanks to TrailGear for their excellent bumper - I can only dream of what sort of damage would have occurred to the rear of my jeep otherwise (still have to bring the jeep to a mechanic to see if the frame has been compromised in anyway).