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