How to set up ipredator VPN, Ubuntu 9.10 (karmic)

First things first, ipredator (http://www.ipredator.se) is a VPN tunnel service that let’s you surf anonymously. It is also in Sweden, which makes a difference (since Sweden have very different laws regarding internet security than for example the UK) and this is A Good Thing if you are concerned about security.

Whatever your reasons you might find yourself signing up for a 3 month subscription with IPREDator, like I’ve done.

The instructions on their web site cover how to set up a VPN connection in Windows (XP+Vista, works for W7 too) and for OSX. Not for Linux though, which is what I have.

So, with your user name and password for your ipredator account at the ready getting it is pretty straight forward to get it going and without any further ado, here it goes:

Install the NetworkManager and the PPTP (Point To Point Tunneling Protocol) extensions:

sudo apt-get install network-manager-gnome network-manager-pptp

You probably have the network manager already, but perhaps not the pptp extension.

Now, restart your network manager:

sudo NetworkManager restart

Select the network manager (either from your launch panel or from System->Preferences->Network connections) and click the VPN tab.

Click “Add” and you should be presented with a form where you can fill in some fields:

Set “Gateway” to “vpn.ipredator.se”

Guess what you need to set “User name” and “Password” too…

Leave “NT Domain” blank.

Give the connection a name or leave it as-is (I called it “IPREDator”…)

Click the “Advanced…” button.

Select “Use Point-to-Point encryption (MPPE)” and leave all other options as-they-are.

You’re done, “ok” your way out of there.

Now you should be ready. In the network manager drop down list of available connections (from the launch panel) you have “VPN Connections” under which you will see your newly added ipredator connection.

Select it and see it think for a while…until it connects and you’re in!

Problems

I normally have to try a couple of times before it works. Perhaps it is down to the ipredator server being busy and if the service takes off I hope this will improve. For now I have to retry 2 perhaps 3 times on average before I get the connection.

Zend tip: disable all rendering in controller when serving AJAX request

NOTE: this assumes you already know a fair bit about how the Zend framework’s rendering and layout engine works.

I have a Zend Framework powered web site that I’m adding some AJAX to. Serving the AJAX request inside a controller by looking for requests with the isXmlHttpRequest flag set to TRUE is simple.
Inside the controller you then assemble whatever JSON or HTML response you have and return it, like this for example:

$this->getResponse()->setHeader('Content-Type', 'text/html')->setBody($response);

Ok, the point here is that when I did this and dutifully called setNoRender using the viewRender helper, my clean and simple response had a large chunk of HTML appended to it.
Now, I am using “response segments” in my Zend layout, i.e. I’ve got a controller action that automatically renders a part of every page, regardless of which controller is the active one. It was this controller’s rendered output that – still – was generated and appended to my neat AJAX response.

So, it turns out, that to prevent this to be rendered I had to disable all controller rendering and setNoRender doesn’t do that. It just disables rendering from within the current controller.
The code to include is instead
$viewRenderer->setNeverRender(true)

This works, and it is auto reset every time you reload the page.

Now my AJAX response is just what it should be.

Rule 30 – a 1D cellular automaton implemented using Processing

Processing is a simple but very powerful Java based scripting environment that allows one to quickly implement graphics (2D and 3D) prototypes. There are some pretty impressive visualization examples out there for you to feast your eyes on and mine is a simple contribution but hopefully interesting.

Cellular automaton are the basis for Stephen Wolfram’s theories in his book “A New Kind Of Science”. On the surface they are deceptively simple but, just like fractals, they can generate highly complex detail and seem to be able to replicate natural phenomena.

I’ve implemented a simple 1D cellular automaton in the script included here based on information on Wolfram’s Mathworld site.

The image this code generates is a pretty pyramid shape of generations of the bits generated by a rule (more on that below) called “Rule 30” which, according to Wolfram, generates a random sequence of bits. It’s actually used as the basis for Mathematica’s random number generator. It also looks quite pretty:
Rule 30

The algorithm is very simple, and I think (hope) it’s pretty well commented and should be easy to understand but let me just outline it for reference:

  • Start with a sequence of bits. It can be initialized to whatever you want but I’ve set it to all 0 except 1 bit in the “center” of the bit string (width of screen in pixels). This bit acts as a seed
  • Read each bit and select an output bit depending on it’s nearest neighbours (left,right) using a simple FSM rule. I’ve encoded the famous “Rule 30” but it could be any other rule…try it!
  • Render the line…and go to the next line

It really is that simple. The code does a little bit of fancy double buffering of the line rendered and the output line and the rest is basic use of Processing’s incredibly simple and powerful functionality.

Enjoy…


/*
Elementary Cellular Automaton (1-D) implementation
We render "generations" of the automaton, one per screen line, starting with at the top with a "seed".
Each generation (line) is rendered by testing each pixel's neighbours and selecting the appropriate rule.

*/

// the rule determining if a pixels is “on” or “off” depending on the state of its neighbours
int[] rule;
// the
int[] grid;
int WIDTH = 800;

void setup() {
size(WIDTH,WIDTH/2); //< half height to terminate nicely since we don’t deal with pixels at the borders
background(0);
noLoop(); //< only need to render one frame

rule = new int[2*2*2]; //< 8 rules
grid = new int[width*2]; //< double buffer; holds this and last generation

// initialize first generation with 1 pixel in the center
for ( int n=0; n < width; ++n ) {
grid[n] = (n == (width/2) ? 1 : 0);
}

// “rule 30”
// This rule is actually used to generate random numbers in Mathematica
rule[0] = 0;
rule[1] = 0;
rule[2] = 0;
rule[3] = 1;
rule[4] = 1;
rule[5] = 1;
rule[6] = 1;
rule[7] = 0;
}

void draw() {

loadPixels();

// double buffer selector
int sel = 1;
for( int generation = 1; generation < height; ++generation ) {

// double buffer selector: alternates between 1 and 0 (every other line)
sel ^= 1;
// read from last generation line
int read_offs = sel*width;
// write to this generation line
int write_offs = (sel^1)*width;

// offset into screen buffer of current line
int pixel_offs = generation*width;

// generate the image, line by line (generation by generation)
for ( int n = 1; n < (width-1); ++n ) {

// read out this and 2 neighbouring values
int n1 = grid[read_offs+(n-1)];
int n2 = grid[read_offs+n];
int n3 = grid[read_offs+(n+1)];
int value;

//simple state machine to select the appropriate rule
if ( n1==1 ) {
if ( n2==1 ) {
if ( n3==1 ) {
// 1,1,1
value = rule[0];
}
else {
// 1,1,0
value = rule[1];
}
}
else {
if ( n3==1 ) {
// 1,0,1
value = rule[2];
}
else {
// 1,0,0
value = rule[3];
}
}
}
else {
if ( n2==1 ) {
if ( n3==1 ) {
// 0,1,1
value = rule[4];
}
else {
// 0,1,0
value = rule[5];
}
}
else {
if ( n3==1 ) {
// 0,0,1
value = rule[6];
}
else {
// 0,0,0
value = rule[7];
}
}
}

// update the current “write buffer” for the next round
grid[write_offs+n] = value;
// draw and map so we get a fade out towards the bottom
pixels[pixel_offs+n] = color(value*map(generation, 1,height, 255,20));
}
}

updatePixels();

}