Setting up a self signed SSL certificate with Apache

I’m assuming you have Apache installed.

Enable the SSL mod for apache:

sudo a2enmod ssl

Create a directory for the certificates:

sudo mkdir /etc/apache2/ssl

Generate the certificate:

sudo openssl req -x509 -nodes -days 365000 -newkey rsa:2048 -keyout /etc/apache2/ssl/apache.key -out /etc/apache2/ssl/apache.crt

Openssl will ask for some information, make sure you set the FQDN properly, the rest don’t matter.

Now edit your virtualhost to point to port 443:

<VirtualHost *:443>

Add the port to the server name directive:

ServerName example.com:443

Then enable SSL and point the virtualhost at the certificates:

SSLEngine on
SSLCertificateFile /etc/apache2/ssl/apache.crt
SSLCertificateKeyFile /etc/apache2/ssl/apache.key

Save the file and restart Apache

sudo service apache2 restart

Now if you want to redirect non-SSL requests to the SSL port add another virtualhost that looks like the following:

NameVirtualHost *:80
<VirtualHost *:80>
   ServerName example.com
   Redirect permanent / https://example.com/
</VirtualHost>

Then a2ensite the new virtualhost and restart Apache once more.

Spotify in Ubuntu 12.10

Spotify is a cool streaming music service – $12 a month for high quality music streams on mobile and desktop. They have a decent Linux client too:

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 4E9CFF4E
sudo sh -c 'echo "deb http://repository.spotify.com stable non-free" >> /etc/apt/sources.list'
sudo apt-get update && sudo apt-get install spotify-client-qt

Sounds like Spotify is being added to the Software Center soon anyway.

Optional extras:

http://www.webupd8.org/2013/01/download-ambiance-theme-for-spotify.html

http://code.google.com/p/spotify-notify/

Mucking About with Voxel.js

voxel_forest

Installing Voxel.js

I just discovered voxel.js, which is a web-based voxel engine that can be used to build block-based games like Minecraft. It’s written in node.js, so lets get that set up. Voxel.js requires node.js 0.8.0 or better, and Ubuntu’s repositories supply 0.6.19, so we need to set up a PPA to get the latest version.

sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs npm

Under Ubuntu 12.10 the node.js executable is name ‘nodejs’, I believe its ‘node’ on some other systems.

Grab the voxel hello world repo from github:

git clone https://github.com/maxogden/voxel-hello-world.git
cd voxel-hello-world
npm install
npm start

Now you should be able to check out voxel at localhost:8080. You will have be inside a crater with a couple of minecrafty types in front of you. They would be Maxogden and Substack, the voxel.js devs.

“npm install” downloads all the dependencies for voxel-hello-world. ‘npm start’ makes npm run a node js webserver, and rebuild index.js on each request using browservefy.

Note: I can only get this working in Firefox – according to Google Chrome doesn’t support WebGL with my laptop’s Nvidia FX Go5200 🙁

Switch to Perlin Noise Terrain Generation

Instead of using the predefined ‘Valley’ terrain, we can switch out to a module, such as the Perlin Noise Terrain Generator.

npm install voxel-perlin-terrain

Add the following at the top of index.js as below:

var createTree = require('voxel-forest')

Then update createGame:

var chunkSize = 32
var chunkDistance = 2

var generate = perlin({
  chunkDistance: chunkDistance,
  chunkSize: chunkSize,
  scaleFactor: chunkDistance * chunkSize / 4
})

var game = createGame({
  generateVoxelChunk: generate,
  cubeSize: 25, 
  chunkSize: chunkSize,
  chunkDistance: chunkDistance,
  startingPosition: [185, 100, 0], 
  texturePath: texturePath,
  worldOrigin: [0,0,0],
  controlOptions: {jump: 6}
})

You can muck around with the value of scaleFactor to make mountains, hills or relatively flat terrain.

Plant Some Trees

In order to generate some trees we need to include voxel-forest then add a few lines of code..

npm install voxel-forest
var createTree = require('voxel-forest')
....
// Create some trees.
for (var i = 0; i < 25; i++) {
createTree(game, {bark: 2, leaves: 3});
}

From here..

That’s probably enough for one post but jeez there’s a lot more here to play with so watch out for a followup.

BumbleBee drivers on Ubuntu 12.10

My ASUS laptop has 2 graphics cards, one Nvidia and the other Intel. Ubuntu uses the Intel one by default, but that leads to poor performance for gaming. So I need to install the Bumblebee drivers.

  1. sudo add-apt-repository ppa:bumblebee/stable
  2. sudo add-apt-repository ppa:ubuntu-x-swat/x-updates
  3. sudo apt-get update
  4. sudo apt-get install linux-headers-generic
  5. sudo apt-get install bumblebee bumblebee-nvidia bbswitch-dkms
  6. Reboot or re-login

Swat PPA has the latest Nvidia drivers.

Except that I log back in and ‘optirun glxspheres’ returns:

[ 118.398232] [ERROR]Cannot access secondary GPU - error: Could not load GPU driver
[ 118.398323] [ERROR]Aborting because fallback start is disabled.

Luckily this can be fixed by editing /etc/bumblebee/bumblebee.conf. Look for the line that says ‘Driver=’ and add ‘nvidia’ at the end. Then reboot, and test with ‘optirun glxspheres’. The graphics card light should switch from blue to white, and the output should look something like the following:

Polygons in scene: 62464
Visual ID of window: 0x21
Context is Direct
OpenGL Renderer: GeForce GT 540M/PCIe/SSE2
111.175734 frames/sec - 124.072120 Mpixels/sec
112.450230 frames/sec - 125.494456 Mpixels/sec
125.164298 frames/sec - 139.683357 Mpixels/sec

The fix comes from here.

If its still not working try reinstalling using the advice at http://www.ivegotavirus.com/how-to-fix-bumblebee-on-ubuntu-12-10/

Hopefully this is a bit cleaner in 13.04.