How to grab mr Monopoly by the balls and change the world
Header image

Recently i decided to repurpose an old laptop as a server ( was still working fine and had a good processor (i5) ), as i didn’t need a gui i installed ArchLinux on it. Some of you who’ve used Arch before will know that it’s a very lightweight system.

After doing a basic install of lamp and vsftpd i decided to go ahead and also use it to play music. The reason i did it like this was because i wasn’t going to tuck the laptop away on some server rack, it’d just sit on my desk alongside my workstation. ( So why not save a couple percentages on cpu ^_^ ).

After doing some research i decided to install MOC which is the abbreviation for Music On Console. MOC is a lightweight cli music player with all the functionality that you’d find on a regular gui player installed out of the box ( except for visualization, but those are resource hogs anyway ).

So let’s get cracking and install this lovely player

Screenshot MOC

Step 1 : Installing an audio driver

There are several options when it comes to audio drivers, however the most robust package in my eyes is ALSA ( Advanced Linux Sound Architecture ), this is already installed by default but do check if you’ve got the latest version installed.

To check if alsa is installed
pacman -Q | grep alsa

To install alsa
sudo pacman -S alsa-lib

Afterwards issue the following command to install the alsa utils package ( contains a cli soundmixer )

sudo pacman -S alsa-utils

Step 2 : Adding our user to the correct group

On archlinux your user by default doesn’t have access to the audio devices, as such you will need to add him to the ‘audio’ group. Issue the following command to do so

sudo gpasswd -a username audio

Take note that this will only take effect until the next time the user logs in.

Step 3 : Installing MOC

sudo pacman -S moc

After the installation has finished you can start your player by issuing mocp

In the beginning it might look a tad annoying to use, but after a while you’ll realise that it’s actually really easy to use.

Extra 1 : Shortcuts MOC

Shortcut Description
a Add music files to the playlist
A Add selected folder to the playlist
C Clear the playlist
Right Arrow Seek Forward
Left Arrow Seek Backward
Spacebar ( or ) p Play/Pause
s Stop playing
S Shuffle Playlist
R Repeat Playlist
TAB Switch between Panels
l Switch between 1-panel or 2-panel view
N Next Song
B Previous Song
, increase volume by 5%
. Decreate volume by 5%
Q quit mocp
? Help

Extra 2 : Alsamixer

As i like to have my music playing in the background i usually just have mocp running under a different console ( switch between consoles by using alt + F[1-6] ) or just in the background ( use q to close mocp and have it running ).

As such i find it really useful to control my volume with alsamixer, you can compare alsamixer to a cli version of the gui sound control.

alsamixer

Alsamixer screenshot

I hope you enjoy your newly installed music player :D and remember happy coding !

Peter

The following is a step-by-step guide to install a LAMP on ubuntu, LAMP stands for Linux Apache MySQL and PHP.

This guide will be done manually inside a terminal, however should you not feel comfortable with doing it this way you can always install the full LAMP package from apachefriends, this package also includes a Perl installation.

So without further ado let’s get started ! :D

Step 1

The first step we’ll take is to install the mysql server and client on your ubuntu machine. So open up a terminal and run the following command

sudo apt-get install mysql-server mysql-client

During the installation you’ll be asked to enter a password for the root user, this can be changed later on but for now just input something you can easily remember.

Step 2

After the installation of our mysql client/server has finished we’ll be installing our apache server, do this by running the following command

sudo apt-get install apache2

Afterwards you can test your new server installation by running

firefox “http://localhost”

this should give you the following :

It Works !

Ip Addresses

localhost is a name that is linked to the ip 127.0.0.1, however you can also connect to your apache server by using your (not public) ip address, to get this ip you can run ip addr and use the ip address shown there in the following command (change your ip with the respective ip) firefox “http://1.2.3.4″.

Some specs on apache

document root
/var/www/
configuration file
/etc/apache2/apache2.conf
Aditional configuration files can be found under
/etc/apache2/

Step 3

The following step is to install php and the module that’ll link it up to our apache server

sudo apt-get install php5 libapache2-mod-php5

Now restart your apache server by running the following command

sudo /etc/init.d/apache2 restart

This has given us the ability to run php files on our apache server. To test this out you can create a php file under /var/www/ and add the following to it

<?php
phpinfo();
?>

Save the file as index.php and use the following url to view your newly created php file http://localhost/index.php

Step 4

This is all going fine, but we still need to connect some of the dots. For instance we do have mysql, php and apache installed, but we still don’t have mysql support in php, to do this we need to install a php module that’ll give us this functionality.

sudo apt-get install php5-mysql

Now restart your apache server and the new module will be installed (you can also check this on the phpinfo page you created earlier)

PHP Modules

There are a lot of additional php modules that can be installed, to take a look at these you can search the repositories using the following command.

sudo apt-cache search php5

Step 5

[Optional] Even though we already have a fully functional LAMP install it is in my eyes recommended to install an administration system to manage our mysql databases, i prefer using phpmyadmin because you can access it through a webbrowser ( and as such with some extra configuration make it accessible from the outside ). To install phpmyadmin you need to run the following command

sudo apt-get install phpmyadmin

During the installation you’ll be asked 2 questions, the first considers the webserver you’d like to use, we installed an apache so tick the apache2 and hit enter. The second question asks if you’d like to configure a database for phpmyadmin, tick no and hit enter.

Even though the installation usually configures your phpmyadmin/apache2 correctly, it has been known that sometimes the apache2 doesn’t recognize phpmyadmin, if this is the case you need to do the following

sudo gedit /etc/apache2/apache2.conf

Then add the following to the end of the file

Include /etc/phpmyadmin/apache.conf

This will make sure that apache loads up phpmyadmin when it is started, now restart your apache and you’re all set. To access your phpmyadmin suite just use the following url http://localhost/phpmyadmin/

This is the end of this guide and i hope that after all this you’ve got a fully functional lamp suite :) .

An extra tip that i might give you is to make sure that the /var/www/ directory is under your ownership (usually this is root). to do this just use the following command

sudo chown -hR myusername /var/www/

Fill in your username where it says myusername, this command will give you ownership over the /var/www/ folder and the extra -hR option will also give you ownership over any files/subdirectories in the /var/www/ folder.

See you next time ^ ^ and remember, happy coding !

Peter

There are several ways through which you can manage and maintain your startup servicec. This little tip will show you the most common way of doing this.

The Command

The command that i’ll be showing you is the chkconfig command. chkconfig is used to maintain the /etc/rc[0-6].d directory without having to mess around with the symbolic links in those directories ( clean and easy, the way we like it ).

Usage

This command has five specific functions, those five together make a solid management tool. If chkconfig is run without any of the following options it will display usage information.

Take Note

  • most services are automatically added after they’re installed on your system, so before using the –add option check if they aren’t already in the table.
  • the –levels option specifies the run levels an operation should pertain to. These run levels range from 0 to 6 ( so 7 runlevels in total ) and are added as a string of numbers ( no whitespace in between ! )
–list [name]
lists the current startup information for services
–add name
Adds the new service for management ( this will add an entry to every runlevel )
–del name
Removes the specific service from the list
[--levels levels] name
Changes the startup information for the specific service
[--level levels] name
Returns information on the current configuration for this specific service
* take note that — is in fact two ‘-’ characters

Some Examples

In the following examples i will make use of a fictional service called “lionheart”.

Checking if the service already exists

chkconfig –list lionheart

if the result contains a row of data the service already exists.

Adding a service

chkconfig –add lionheart

Please take note that when adding a service it will add an entry for this service in all of the runlevels, this entry will by default be set to not start at runtime.

Removing a service

chkconfig –del lionheart

This will remove the service and all of the service-specific entries per runlevel.

Managing the service per runlevel

Consider we would like to set our lionheart service to start up in runlevels 2,3 and 5. The command to do this would be the following :

chkconfig –level 235 lionheart on

After a week we decide that we don’t want our service to run in level 5 anymore, the command we could use to do this would be :

chkconfig –level 5 lionheart off

As the –level separately ( in my eyes doesn’t really have any useful functionality i will not place an example for this here, or in other words i personally haven’t had any use for it ^ ^ if you however have had to use this, then do enlighten me ^ ^ ).

Some post sccriptum notes

  • The on/off option only affects runlevels 2,3,4 and 5, the reset option affects all runlevels
  • When switching runlevels the services with the same values as in the previous runlevel ( for instance a service that was on in level 2 and on in level 3 ) will not be restarted or stopped
  • See ya next time and happy coding ! :D

    Peter

The client.data.underflow error is caused by a nasty bug in amfphp. This bug can be encountered when sending nested arrays between amfphp & as3.

The existence of this bug has been reported to the developers of amfphp and has already been resolved in zendamf. However, the best course of action to undertake is to make sure that
you don’t return any nested arrays from amfphp to as3. A good way to do this is to change your arrays with objects :) .

cheers

peter

As most of you know the amf message format is heaven-sent when it comes to sending data between php and as3. It’s easy to use and relatively fast.

However, every once in a while you hear about developers encountering encoding issues. Today i too encountered this. After about an hour of poking around our system i found out that this was being caused by the fact that amfphp used ISO-8859-1 as default encoding.

As such when trying to pass special characters to a database the encoding will actually cut these out or change them in such a way that your data changes. Luckily for you there’s an easy fix to this :) .

Open up your gateway.php file (which should be located in the root directory of your amfphp folder) and change the following line :

$gateway->setCharsetHandler(“utf8_decode”, “ISO-8859-1″, “ISO-8859-1″);

to

$gateway->setCharsetHandler(“utf8_decode”, “UTF-8″, “UTF-8″);

take note

In case this didn’t solve your problem you might want to try to completely comment out the section where the character encoding is being done in your gateway.php

The reason why I’m saying this is due to the fact that if you’re working with a database system there is a high chance that the database system itself Is already encoding your data ( or at least this is the case for most mysql systems ). This would mean that a double encoding is causing your problem, as we only want our data to be encoded once ( optimisation reasons … ) I’d actually go so far as to recommend this from the start. To summarise, amfphp acts like a gateway between php and as3, if however the target system is different ( for example mysql ) we should let the target system do the character encoding and let amfphp just act as a bridge between our target and our source

Cheers and happy coding

Peter

For the guys who haven’t seem em yet :D ! the fotb 2011 pics group from flickr

Clickety click

Hey all ^^, another quick tip that’ll really speed up your flex rendering. In any programming course they always tell you that writing understandable code is a must-have.

Well sometimes spaghetti code is a lot faster in execution than your understandable solution.

A good example is the way “components” work in flex, for instance i’m working on an application with quite an advanced search and it has 6 different lists of checkboxes each linking to their own arraylist and with a label above it. It would be nice to have this in a component implementation. However consider the following. Most component implementations start with a group in which you place your items ( unless you’re writing as3 components ! ). Thus on top of the 6 lists/labels you’ve also got 6 extra groups hogging up memory. This would mean that having your 6 lists/labels defined inside of your app ( instead of in a comp ) would take up less memory and thus execute faster !

There are exceptions to this, components written in as3 :) !

cheers & keep on coding !

peter

Ever been in a situation where you want to transform/rotate an image around its center and for some reason the rotations seem to start living their own life ?

Well, most flex/flash developers know that this is happening due to the fact that components have their “registration point” set on (0,0) by default. This has lead to many developers using the overly used fix of positioning their objects inside a container class and using the container class for the rotations/scaling, … However this leads to extra elements on the stage and in some cases spaghetti code. And oh do we hate spaghetti code.

As such here is a quick fix to change the registration point at runtime :) ! The trick lies in combining the transform property with the PerspectiveProjection class found inside flash.geom ^^

var projection:PerpsectiveProjection = new PerspectiveProjection();
projection.projectionCenter = new Point(your_x,your_y);
myObject.transform.perspectiveProjection = projection;

And that’s all you need to do ! (in this snippet myObject is the object you need to change, the your_x and your_y is the new position of your registration point)

happy coding !

cheers

Peter

Even though the flex framework has grown to become very robust over the past few years there are still some
problems when it comes to optimization.

This first tip is about xml loading in flex.

Temptation may point you towards using tags due to them being easy to use. However, don’t be fooled when using the HTTPService tag.

The original way of loading an xml file by using URLLoaders is a lot faster, the only performance gain you might get with HTTPService tags is when reusing them.

So if you only need to load a single xml file (for instance when loading a settings.xml file) be advised that URLLoaders will do a better/faster job.

cheers

Peter

For those who can’t wait :) ! The adobe air 3 beta has been released and available for download from adobe labs :) !

A quick overview of the new features :

  • Stage Video Hardware Acceleration (AIR for mobile)
  • Captive Runtime Support (AIR for desktop and Android)
  • iOS Background Audio Playback Support
  • Android Licensing Service Support
  • Android Front-facing Camera Support
  • Encrypted Local Storage for Mobile
  • H.264/AVC Software Encoding for Cameras (desktop)