Archive for the ‘Tech’ Category

SSH tunnel command just logs you in

Friday, April 26th, 2013 | Tech

If you’re trying to create an SSH tunnel, you may find that running the command just logs you into the remote server.

ssh -L 27017:somehost:27017 user@examplehost.net

To solve this, you need to use the -N flag.

ssh -L 27017:somehost:27017 -N user@examplehost.net

This will then just set up the forwarding, and not run the command.

Error resolving hostname on SSH tunnels

Saturday, April 20th, 2013 | Tech

Lets say you are trying to create an SSH tunnel.

ssh -L 27017:somehost:27017 you@examplehost.net

You may get the following error message.

ssh: Error resolving hostname \342\200\223L: nodename nor servname provided, or not known

This is caused by using the wrong kind of minus symbol. If you have copied and pasted the command from somewhere, this is probably the case. This is easy to fix – simply paste the command into your terminal, then go through it, remove the existing minus symbol and put a new – in.

Synergy disappeared from Ubuntu desktop

Sunday, April 14th, 2013 | Tech

If you’re using Synergy for mouse and keyboard sharing, you may find that it suddenly disappears from Ubuntu. It will show up as installed in the Software Centre, but you won’t be able to remove or reinstall it, and there will be no icon on the unity bar.

If you try running it from the command line using the following command.

synergys

You may get an error similar to the following.

no configuration file found

The easiest way to solve this is to download the .deb package from the Synergy website, then open up a terminal and install it from there.

cd /home/your-name/Downloads
sudo dpkg -i synergy-1.4.10-Linux-x86_64.deb

This will then reinstall it and you should then be able to find the programme listed in the dash home.

Speed up really slow SSH connections

Monday, April 8th, 2013 | Tech

Sometimes, you might find that when you try and SSH into another server, it seems to hang, but then after around 30 seconds or so, will suddenly start working again. You can diagnose where it is stopping by using verbose mode.

ssh -vv user@example-server

If you find it is to do with GSS API, you can disable this in your SSH configuration.

cd ~/.ssh/
vim config

Add the following to it.

GSSAPIAuthentication no

This should then speed the login up.

Guest network on Linksys E1000 router

Tuesday, April 2nd, 2013 | Tech

If you’re using a Cisco Linksys E1000 router, you may have noticed that it creates a guest network – but there is no sign of how to control it or change it through the web interface!

Strangely, that is how it is – Linksys seem to have omitted any kind of control over it from the web interface. The only way you can modify it is to run the Cisco Connect software on your computer.

Launching this will bring up a control panel, of which the bottom left option will be “guest network” and from here, you can make changes.

It also appears, from the list of available wifi networks, that the guest network is not password protected. This isn’t the case if you have set a password, but it does not use the standard WPA or WEP encryption. Instead, it allows clients to connect, but them prompts them for a password before allowing them internet access.

Screen resolution drop on Ubuntu

Wednesday, March 27th, 2013 | Life, Tech

If you find your screen resolution suddenly drops too 800×600 on Ubuntu 12.04, the following set of commands may help you resolve it. First, stop the graphical environment.

sudo service lightdm stop

Now remove all the Nvidia packages and reboot the system.

sudo apt-get purge nvidia*
sudo reboot

This will reset you to the default video driver. You now need to reinstall the Nvidia driver, which you can do by going to System settings > Additional Drivers and selecting the top option with the following name.

NVIDIA binary Xorg driver, kernal module and VPDAU library

Select this and click activate. Now reboot your system again and the Nvidia drivers will be re-installed and hopefully working again.

Gnome fails to start after switching Nvidia drivers on Ubuntu

Thursday, March 21st, 2013 | Life, Tech

If you’ve tried to switch to a different Nvidia graphics driver on Ubuntu and suddenly found that X / Gnome will no longer load and all you have is a command line, you can fix it by switching back to the original driver.

jockey-text -l
jockey-text -e xorg:nvidia_current

These commands will show you a list of drivers available, and then activate the standard Nvidia driver.

Selenium Cannot assign requested address

Friday, March 15th, 2013 | Life, Tech

If you’re using BDD (Cucumber or Behat for example) with Selenium, you may find you occasionally get an error where the framework is unable to communicate with the Selenium server.

Failed to connect to 127.0.0.1: Cannot assign requested address

This seems to occur when there are two many requests going to Selenium. This can be alleviated be rewriting your tests to ensure you are now sending too many requests at once.

For example, if you’re using Behat/Mink, then avoid using the wait() function on the Session object, as this can cause excessive requests to be sent to Selenium.

Class constraints in Symfony2

Saturday, March 9th, 2013 | Programming, Tech

Sometimes you need to put a constraint on a whole class, rather than a single value. Duplicate usernames are a good example of this – you don’t want to be able to set a username to one that is already in use – but if it is in use with the user you are currently working on, you don’t want to flag it up as an error!

Lets use that as an example. You have a Username constraint and a UsernameValidator object to do the actual validation. We need to supply the validator an object, so we need to put the following method inside the Username object.

public function getTargets()
{
    return self::CLASS_CONSTRAINT;
}

This will turn the first parameter in our isValid function in the UsernameValidator class to an object.

public function isValid($user, Constraint $constraint)

Finally, you can call the constraint from your YAML validation file.

User:
    constraints:
        - nocs:UniqueUsername: ~

Normally, under user you would have getters and properties – but here we’re adding a new section named “constraints” which lists all the class constraints.

Validation in Symfony2 unit tests

Sunday, March 3rd, 2013 | Programming, Tech

Want to use the Validation module in your Symfony2 unit tests? No problem, thanks to the ValidatorFactory, it’s relatively straight forward.

use Symfony\Component\Validator\ValidatorFactory;

class ExampleTest extends \PHPUnit_Framework_TestCase
{
    public function testSomething()
    {
        $validator = ValidatorFactory::buildDefault()->getValidator();
    }
}

Simply include the ValidatorFactory namespace and then use the class and it’s default values method to deliver you a validator, which you can then validate your objects against just as if it was in a controller.