Friday, July 17, 2015

Building Ruby on Raspbian

Building Ruby on Raspbian using rbenv & ruby-build will fail:
$rbenv install 2.2.2
The Ruby openssl extension was not compiled. Missing the OpenSSL lib?

You need the package libssl-dev to resolve the above error and also package libreadline-dev to fix issues with irb.

Monday, April 06, 2015

Playing music using omxplayer on the terminal

On my Raspberry Pi I use something called omxplayer on the command line to play MP3 & MP4 files. omxplayer by default should be installed on Raspbian. To play music using the hdmi monitor speaker issue the following command:
omxplayer -p -o hdmi my_music_track.mp3

Useful key bindings to control omxplayer while playing:
q exit omxplayer
p / space pause/resume
- decrease volume
+ / = increase volume

I use the following command in the terminal to play all my music in the directory ~/music in shuffle mode:
for f in $(ls ~/music/*.mp3 | shuf); do echo "Playing: $f";omxplayer -p --vol -1800 -o hdmi $f; done

Enabling firewall on Raspbian

One of the first lines of defence in securing your Pi or Linux is a functioning firewall. In the past, this was often done through complicated and arcane utilities. There is a lot of functionality built into these utilities, iptables being the most popular nowadays, but they require a decent effort on behalf of the user to learn and understand them. Firewall rules are not something you want yourself second-guessing.

To this end, UFW is a considerably easier-to-use alternative. UFW, or Uncomplicated Firewall, is a front-end to iptables. Its main goal is to make managing your firewall drop-dead simple and to provide an easy-to-use interface.

First you will need to install it on Raspbian:
sudo apt-get install ufw

Then enable it by:
sudo ufw enable

UFW’s defaults are to deny all incoming connections and allow all outgoing connections, once you need to change the defaults rule, then you can use man page for UFW. The defaults are in most cases all you need.

You can check the status of your firewal rules by typing:
sudo ufw status verbose

Raspbian has overscan enabled by default

When I first started up Raspbain on my new Raspberry Pi 2, the picture didn't fill the entire size of the screen. I could see black borders on all sides on my 24 inch BENQ monitor. The reason for this was that Raspbain by default adding overscan to the signal. Modern TVs and monitors don't need overscan and hence disabling overscan altogether can make the Pi graphics fill the entire screen.

Check the settings on TV or monitor first. If this donsn't remove the black borders, then try disabling overscan on the Pi. This can be done by setting the parameter disabe_overscan to 1 in /boot/config.txt and commenting other parameters related to overscan.
  1. Take a backup of /boot/config.txt
    sudo cp /boot/config.txt /boot/config.txt.backup
  2. Open config.txt for editing
    sudo vi /boot/config.txt
  3. Uncomment the #disable_overscan=1 (Remove the #)
  4. Comment all other overscan parameters
  5. Save and exit
  6. Reboot
    sudo reboot

Saturday, April 04, 2015

Installing Source Code Pro true type fonts for Raspbian

As programmer you need good fonts, and I highly recommend Source Code Pro. To install Source Code Pro font for single user account do the following:
  • Download latest release of Source Code Pro fonts
  • Unzip the fonts into the directory: ~/.fonts
  • Update the font cache: fc-cache -vf

I was having problem working out what the semi bold font name was, the following one liner was useful:
fc-list :fontformat=TrueType -f "%{family}\n" | sort -u | less

Add the folllowing in ~/.Xresources to use Size 11 of Source Code Pro semi bold font for xterm:
XTerm*faceName: Source Code Pro,Source Code Pro Semibold
XTerm*faceSize: 11

For the changes in ~/.Xresources to take effect without restarting X, you can do the following:
xrdb -merge ~/.Xresources

And to verify that the changes have took effect, you can do the following:
xrdb -query -all

Saturday, March 07, 2015

Burning RASPBIAN Linux image onto micro sd card

Recently I got Raspberry PI 2 and I got around to burning RASPBIAN image onto micro SD card.

Here is a step by step guide what I did:

Please note that the use of the dd tool can overwrite any partition of your machine. If you specify the wrong device in the instructions below you could delete your primary Linux partition. Please be careful.
  • Run df -h to see what devices are currently mounted.
  • Insert the micro sd card into your computer
  • Run df -h again. The new device that has appeared is your SD card. The left column gives the device name of your SD card.On my machine it was listed as /dev/sdb1 . The last part (i.e. 1) is the partition number.
  • Run umount /dev/sdb1 
  • In the terminal, write the image to the card with the command:
sudo dd bs=4M if=2015-02-16-raspbian-wheezy.img of=/dev/sdb
  • Run sync to ensure the write cache is flushed and that it is safe to unmount your SD card.
  • Remove the SD card from the card reader.

I did this all in Virtualbox VM, therefore did not have hard disk space in the VM to dd-ing from the micro SD card back to another image on my hard disk.If I had the hard disk space in the VM I would have done the following to check what had be writtten to the SD card:
sudo dd bs=4M if=/dev/sdb of=from-sd-card.img
sudo truncate --reference 2015-02-16-raspbian-wheezy.img from-sd-card.img
diff -s from-sd-card.img 2015-02-16-raspbian-wheezy.img

diff should report that the files are identical.