Friday 27 September 2013

Changing keyboard layout in Ubuntu Server (Linux, How to)

So I recently installed Ubuntu Server in a virtual machine and I had problems with my keyboard layout. I use UK layout while the default that comes with Ubuntu Server is US layout. As you can imagine, this caused problems and I had to go hunt for a solution. Finally, I found one and here it is:

You need to reconfigure keyboard configuration. Type the following:
sudo dpkg-reconfigure keyboard-configuration

If that doesn't work, you might need to install console-data package. Install it by typing:
sudo apt-get install console-data

and then try first step again.

If everything was fine, you should see this:
Using this you can select brand of your keyboard. I am running this virtual machine on my Acer laptop and as you can see it is listed there. You can use up/down/page up/page down keys to navigate through the list. When you have picked one, press enter to go to next screen.

You should now see this:
This is the language selection screen. Navigate through the list, select your language and as you did in previous one, press enter to move on to next screen.

This is the screen where you select your keyboard type:
Assuming you're using a qwerty keyboard for PC, you should just leave the first one selected and press enter. However, if you are running this on a mac or your keyboard is of different kind, you are free to choose whatever applies to you from the list and continue by pressing enter.

The next screen allows you to map a key on your keyboard to alternate grammar key (Alt Gr).
I have never used this key in my life for alternate grammar, however, hoping that I may use it at some point, I would map it to right-alt key (which actually is Alt Gr key). As usual, select one from the list and press enter.

Next one is compose key. Same drill. Pick one and press enter:
Compose key, if I remember correctly, allows you to type ASCII for certain characters when you press and hold it. This key on windows is left alt key however, here you can choose whatever you want for ubuntu server.

When you press enter, the wizard will quit. So that was the keyboard configuration screen which allows you to configure your keyboard pretty neatly. Have fun!

Saturday 14 September 2013

Assigning static IP address to your Raspberry Pi (WiFi)

When I first bought my Raspberry Pi, I had this problem. My router and TV are in different rooms and I don't have a ethernet cable. This restricts networking ability of my Pi which is quite annoying. I searched for articles on assigning static IP addresses to Raspberry Pi but most of them were talking about assigning it for eth0. I, on the other hand wanted wlan0 static IP.

Now, I could have just got a long ethernet cable and solve this whole problem but I was just annoyed and was constantly asking myself "Why isn't this working over wifi". So finally, after significant digging around, I found the solution. Here it goes:

First of all, take a backup of /etc/network/interfaces file:
pi@raspberrypi ~ $ sudo su -
root@raspberrypi:~# cp /etc/network/interfaces .


Now, in order to make this work, we need some information first. We need to find out the new static ip address that you want, gateway, mask, network and broadcast address. Assuming that you have a working wifi connection on your Raspberry Pi, type:
root@raspberrypi:~# ifconfig

From the output, the bit that we are interested in is:
wlan0     Link encap:Ethernet  HWaddr 00:00:00:00:00:00
          inet addr:192.168.1.99  Bcast:192.168.1.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:19153 errors:0 dropped:24512 overruns:0 frame:0
          TX packets:25553 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:3724822 (3.5 MiB)  TX bytes:31437802 (29.9 MiB)


The highlighted line will give you information about your current IP, broadcast and mask address. Take a note of the last two. So, in my case:
address: (this is the IP address you wish to reserve as static eg. 192.168.1.69)
mask: 255.255.255.0
broadcast: 192.168.1.255

To find out information about the last two bits, type:
root@raspberrypi:~# netstat -nr
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
0.0.0.0         192.168.1.1     0.0.0.0         UG        0 0          0 wlan0
192.168.1.0     0.0.0.0         255.255.255.0   U         0 0          0 wlan0


In my case:
gateway: 192.168.1.1
network (a.k.a destination): 192.168.1.0

Now that we have all the information that we need, edit the /etc/network/interfaces file using nano. Putting all the bits and pieces together, it should look like:

Press Ctrl + O to save.
Now, since I was doing this whole process over SSH, I had to write a script to restart wifi because if I didn't, as soon as I turn it off, it would also take away my SSH access rendering me powerless. You can do the following in either case. Create a new file called restartwifi.sh using nano in root home directory:
root@raspberrypi:~# nano restartwifi.sh

Now, I am aware that this script can be improved but this is what I had before and it has worked without any problems. Press Ctrl + O to save the script. Then press Ctrl + X to exit.

Make sure you edit permissions to make the script executable. Run:
root@raspberrypi:~# chmod +x restartwifi.sh

If you're not root, you'll have to prefix above command with "sudo". 

Now comes the moment of truth. Run the script to reset your wifi by typing following command:
root@raspberrypi:~# nohup ./restartwifi.sh &

If you're in putty session, you'll immediately go offline. If you've done everything correctly, you should be able to ssh into your Pi, after couple of minutes, on your chosen IP address.

Wednesday 4 September 2013

How to fix the display issue where edges of your screen are cut off every time you connect your PC to a HDTV

So I have this problem every time I connect my laptop to my Samsung HDTV. I thought this was an issue with driver/video card but I wasn't convinced because I wanted a solution. Finally, today, I managed to find a solution for this. Here's how you can solve it:

Go to display driver settings. In my case, since my laptop has two graphics cards - Nvidia 640m and Intel HD 4000 and since the primary display driver is Intel, I went to Intel HD Graphics Control Panel.

Click on Display to view display settings.

Ensure that you have connected your computer to TV using a HDMI cable. If you have, you should see something like "Digital television SAMSUNG" in the combo box under Select Display. 

Make sure that you have selected "Display Settings" tab and "Basic" twisty has been expanded. Under "Scaling", select "Customize Aspect Ratio". In the preview section, you will see two bars (horizontal and vertical) appear. You can adjust the aspect ratio using those. As you can see from the screenshot below, 63 vertical and 65 horizontal works perfect for me. Once you're done experimenting, hit apply.

Additionally, you might want to save those settings under a different profile. You can click on save profile button to do that. Give it a meaningful name and you're done. That way, you can keep different profiles for different monitors/TVs.

Tuesday 3 September 2013

Google Now shows you bus times!

So today I learnt that Google Now can show you bus times. I think this is cool as a student using public transport.

Although, you have to be at or near the bus stop to view its times. It can pick that up from a calendar entry/email/search as well. It would've been  nice if I could search for a bus stop to view its times but as it turns out, you can't.

So I guess this isn't convincing enough to make me uninstall my bus checker app but it's a start.