pwnt.be

Asunción

If you like a bit of uplifting trance music, then why not check out Asunción, the latest melodic venture by yours truly? You know you want to.

Asunción, Paraguay at Night
Asunción, Paraguay at Night by alex-s
Some rights reserved

If you like what you hear—or, hell, even if you don’t—, be sure to listen to some of my other tunes as well. They’re all still absolutely free, so you’d better grab ’em before they hit the charts. It could happen.

Simple Linear Regression with JFreeChart

I’m sure there are numerous ways you can graph a simple linear regression using JFreeChart. Wanting to do so, I turned to Google and came across a few implementations. However, as none of them seemed terribly well written, I took a stab at it myself.

Basically, what I wanted was a scatter plot with the regressed line on top of it. As a bonus, I set out to include support for multiple data sets in one graph. JFreeChart allows you to combine data sets and create overlaid charts, so the whole thing was surprisingly easy. After looking at a few examples, I came up with the following:

Simple linear regression example
Simple linear regression example

Pretty nifty, huh? So, here’s how it’s done …

  • We start by creating a scatter plot from one or more series of data. The ChartFactory.createScatterPlot() method does exactly that, so I won’t elaborate on it here.

  • Next, we add a second data set to the plot. It will be used to render the regressed line and in fact consists of only two points per series: the end points of the line segment that will be drawn.

  • Obviously, JFreeChart already contains the functionality to draw line charts. Hence, all we need to draw the lines is a simple StandardXYItemRenderer. Thus, we create an instance of that class and associate it with the second data set.

  • And finally, some cosmetic surgery. Since JFreeChart does not know the scatter plot and line chart are related, it will paint associated series in a different color. Using setSeriesPaint(), however, we can easily match both renderers’ color schemes.

  • The result is a standard JFreeChart, which can be customized and visualized like any other one.

And that really is all there is to it. The resulting code can be found in RegressionDemo, which I am releasing under a GPL license. Enjoy.

Update: You’ll probably want to get rid of superfluous legend items. To do that, just tell JFreeChart that you want to hide them:

regressionRenderer.setBaseSeriesVisibleInLegend(false);

I took the liberty of updating the screenshot and code to reflect this.

The HTML 5 <audio> Element and You

Since HTML 5 started to emerge, modern web browsers have gradually been adopting its features. One of HTML 5’s cornerstones is Open Web technology. Arguably the most apparent improvement is that you no longer need a plug-in to watch a video clip: the <video> element lets you play a Theora clip on any page, and treat it like any other element. Along with <video> comes the highly similar <audio> element, which this site has now embraced. What that means for your weekend, after the break!

Record
Record by Seán Venn
Some rights reserved

The idea here is to gradually move away from Last.fm. Currently, all DJ CT songs are hosted there. Yeah, you can listen to them and all, but the fact of the matter is, their MP3 encoder really does a number on the audio quality—especially in the highs. Hence, eventually, I’m going to be hosting all of my songs right here on pwnt.be, in everybody’s favorite open format, Ogg Vorbis. I’ve already re-encoded all of them using oggenc’s default quality setting, which is a vast improvement over Last.fm’s MP3s, at roughly the same size. The files can be found right here.

Of course, a boring old directory listing isn’t the best way to deliver my music. That’s where HTML 5 comes in. Using a bit of MooTools-based JavaScript, I’ve developed a minimalist audio player for modern web browsers. That is to say, it’s only compatible with Firefox 3.5 and development builds of Google Chrome for now, but I’m working on that. If your browser is supported, you’ll see my elitist player pop up at my Oscillation page; if not, you’ll be directed to the downloadable file.

That’s about it. Incidentally, if you like what you hear, don’t forget to become a DJ CT fan on Facebook. You know you want to.

Automating OpenVPN Connection on Windows XP

We’ve been using OpenVPN at work for a while now. The technology itself is decent enough, but if you’re a Windows XP user, you’ll quickly get annoyed by the shortcomings of the rather Spartan OpenVPN GUI.

Personally, I had two main gripes. The first was that the TAP adapter, i.e. the virtual network interface, Cable unplugged would generate a cable unplugged system tray notification unless the VPN connection had been established. My second, more debatable annoyance was that, for security purposes, there’s no way to store your credentials in the client. In this article, I propose a straightforward solution to both these issues.

OpenVPN GUI
OpenVPN GUI

Dynamically Enabling the TAP Adapter

Under Windows XP, when you know a network connection is unavailable, the easy way to get rid of the cable unplugged warning is to disable the connection. This also works for the TAP adapter. Hence, if you can be bothered, just right-click the tray icon, select Disable, and there goes the warning. However, you will have to re-enable the adapter every time you want to use your VPN connection.

Luckily, you can also do so from the command line. Moreover, OpenVPN GUI can execute a batch script upon establishing as well as disengaging the VPN connection. Combining the two, you can fully automate the enabling-disabling process as follows.

  1. Install Microsoft’s DevCon utility for managing devices from the command line—if you thought the built-in Netsh would help you here, guess again. For convenience, be sure to add the containing folder to your PATH, or just place DevCon in system32, for instance.

  2. Run the following command to obtain the TAP interface’s ID:

    devcon find TAP*

    On my machine, it was simply ROOT\NET\0000.

  3. Open your OpenVPN configuration folder. Usually, it’s

    C:\Program Files\OpenVPN\config

    For the connection you wish to automate, there will be a .ovpn file sitting there. We will now create two small batch scripts, one for connection and one for disconnection.

  4. Still in the configuration folder, create a text file called profile_pre.bat. For instance, if your configuration file were called work.ovpn, you’d create work_pre.bat. Be sure to follow this naming scheme, as it’s required by OpenVPN GUI.

    The batch file should contain the following text:

    @echo off
    echo Bringing up TAP interface ...
    devcon enable @ROOT\NET\0000

    The first two lines aren’t required, but they clean stuff up a bit. The main thing is of course the last line, which you may need to modify if you got a different device ID earlier.

  5. Similarly, create another file called profile_down.bat, responsible for disabling the adapter when you disconnect:

    @echo off
    echo Taking down TAP interface ...
    devcon disable @ROOT\NET\0000

And that’s it. When you establish a VPN connection, a command prompt window should briefly pop up, enabling the adapter. When the connection is terminated, the same thing should happen, disabling the adapter.

Maybe you don’t want those windows to pop up. That can be arranged: just pass the option --show_script_window 0 to OpenVPN GUI.

Automatically Entering Credentials

As I mentioned, this second part is a bit more questionable. You may have strong feelings against automatically filling in logon dialogs, as do I. At the end of this article, I will discuss reducing the security risk a bit. However, if you are truly concerned about security, just memorize your password and enter it manually, or, better yet, use certificates instead. The latter wasn’t an option for me, which is the only reason why I explored automatically entering credentials—apart from laziness.

Before we begin, you should look at unofficial OpenVPN GUI builds that do allow storing your password. Just Google for the enable-password-save option and you’ll probably find a couple. Personally, I prefer using the official build and hacking my way around that.

… Although hacking is such a strong word, isn’t it? All we need to do is automate filling in the logon dialog. Several tools exist for this purpose, such as AutoHotkey. I went with AutoIt, since I already had it installed.

  1. So, if you don’t have AutoIt already, grab it and install it.

  2. Fire up AutoIt’s script editor and paste the following code:

    ; Close OpenVPN GUI if it’s already running.
    ; You may be using a different version.
    ProcessClose("openvpn-gui-1.0.3.exe")
    ; Start OpenVPN GUI.
    ; Change version, profile, and path if necessary.
    Run("openvpn-gui-1.0.3.exe --connect work.ovpn", _
        "C:\Program Files\OpenVPN\bin")
    ; Wait until the authentication dialog pops up.
    WinWaitActive("OpenVPN - User Authentication")
    ; Fill in your username.
    Send("username")
    ; Tab to the password field.
    Send("{TAB}")
    ; Fill in your password.
    Send("password")
    ; Confirm dialog input.
    Send("{ENTER}")
  3. Save the file as openvpn-work.au3 or whatever you like.

If you double-click the file, OpenVPN GUI will be fired up, AutoIt will automagically fill in your credentials and when it’s finished, you’ll have your VPN connection up. Note that the batch scripts from the first part of this article will not be affected by this at all.

Now to address that security concern expressed earlier. You can obscure your logon information a little by turning the plain-text AutoIt script into an executable. For this purpose, AutoIt comes with a utility called Aut2Exe. To build the executable, just right-click the .au3 file and select Compile Script. A .exe file of the same name will be generated. An additional benefit of this is that you can easily distribute this file instead of installing AutoIt on all your computers. Note, however, that it will still be easy to extract your credentials from the binary code.

Room for Improvement

So far, I’ve only found one shortcoming to this technique. Sometimes, the OpenVPN GUI logon dialog won’t get focus, blocking the AutoIt script until you click on the taskbar button. It still beats typing in the whole lot.

So, personally, I’ve attained my goal. I no longer have to burden myself with enabling and disabling the TAP adapter or entering my credentials. Hopefully, I won’t be the only one benefiting from this short tutorial. If nothing else, it’ll probably spark some comments about how much easier this stuff is on Linux or OS X. To which I say, “Meh.”

Disorientation
Continuity
Retributions
Automating OpenVPN Connection on Windows XP
blanky, sky, Tim, Geb, 12vpn, Tim, neecom
Simple Linear Regression with JFreeChart
Nicolas Machado, Sascha, Tim, Sascha, Tim, Sascha
De Canvascrack: een epiloog
Tim, Steven Noels
Lplayer for the Rest of Us
jesus2099, Tim, jesus2099, Tim, jesus2099, Tim, PixelPirate
Proximus, Universiteit Gent, Kafka: schrappen wat niet past
Tim, Bart Coppens, Tim, Steven, Tim, Femke
Colophonics