So it seems I finally got my filthy hands on a Raspberry Pi. So far so good, although the software stack is a bit lacking still. I’m sure it will catch up. Anyway, I immediately loaded the debian distro to an sd card, which, for the record, consists in doing
dd bs=1m if=~/Downloads/debian6-19-04-2012/debian6-19-04-2012.img of=/dev/rdisk1
and I was good to go. The next essential step was to setup a decent remote ssh session. This is pretty trivial stuff, the only reason I’m posting this is I found a very simple way to give the Raspberry Pi access to the internet, while accessing it through ssh. Sounds interesting? Let’s bring it!
1. Set up ssh on the PI
It’s a matter of starting it
sudo service ssh start
and adding it to the list of startup services
sudo insserv ssh
2. Configure main machine
In network manager, just configure a wired connection like so
It goes without saying that at this point you should restart the Raspberry Pi or its networking system. Right? Right?? I mean JESUS CHRIST this is some pretty basic SHIT I mean WHATLKDASlkNSDf THIS IS WHAT HAPPENS WHEN YOU FUCK A STRANGER IN THE A- –
3. Grab Pi’s IP
At some point your main machine is going to attribute an IP to the Pi. You can monitor syslog like so
tail -f /var/log/syslog | grep dnsmasq
For the record, it should look something like this
May 19 18:57:05 ubuntu NetworkManager: <info> Starting dnsmasq... May 19 18:57:05 ubuntu dnsmasq: started, version 2.59 cachesize 150 May 19 18:57:05 ubuntu dnsmasq: compile time options: IPv6 GNU-getopt DBus i18n DHCP TFTP conntrack IDN May 19 18:57:05 ubuntu dnsmasq-dhcp: DHCP, IP range 10.42.0.10 -- 10.42.0.100, lease time 1h May 19 18:57:05 ubuntu dnsmasq: reading /etc/resolv.conf May 19 18:57:05 ubuntu dnsmasq: using nameserver 127.0.0.1#53 May 19 18:57:05 ubuntu dnsmasq: cleared cache May 19 18:57:52 ubuntu dnsmasq-dhcp: DHCPDISCOVER(eth0) 10.42.0.19 b8:27:eb:84:ea:79 May 19 18:57:52 ubuntu dnsmasq-dhcp: DHCPOFFER(eth0) 10.42.0.19 b8:27:eb:84:ea:79 May 19 18:57:52 ubuntu dnsmasq-dhcp: DHCPREQUEST(eth0) 10.42.0.19 b8:27:eb:84:ea:79 May 19 18:57:52 ubuntu dnsmasq-dhcp: DHCPACK(eth0) 10.42.0.19 b8:27:eb:84:ea:79
Usually the IP attributed to the Pi is always 10.42.0.19.
You can go old school
Or with X support for GUI applications
ssh -X firstname.lastname@example.org
Remembering that the default username is pi with password raspberry.
If you want to go for a static ip solution, you need to edit the proper config file
# Used by ifup(8) and ifdown(8). See the interfaces(5) manpage or # /usr/share/doc/ifupdown/examples for more information. auto lo iface lo inet loopback # iface eth0 inet dhcp auto eth0 iface eth0 inet static address 192.168.0.69 netmask 255.255.255.0 network 192.168.0.0 broadcast 192.168.0.255 gateway 192.168.0.1
At this point the VM is all set up and ready to go. All we need is an application.
Linux has several toolkits and frameworks to program graphical applications. Some are bad, some are beyond shit, but at least one of them is top notch – Qt.
Qt is a C++ framework created by vikings from the grim and frostbitten lands of Norway, so you know that shit is for real. It is the only Linux GUI framework that packs an IDE, and a fantastic one for that matter. If you’re interested in python, java or any other garbage collected non-sense I advise you to skip this step and jump to packaging. C++ is for high-octane engineers with a firm grasp of memory management and pure virtual classes. Consider yourself warned.
Now, developing applications isn’t just about frameworks and programming languages. Oh no. There’s source control, source documentation, debugging, unit testing, memory debugging, etc. Yeah, and I mean it: etc! Hopefully we’ll cover most of these concepts till the end of the series. For starters we’ll cover creating a basic project in Qt, using Git for source control, publishing code to Github and licensing.
With me steering the ship, what’s to worry? On with it!
1. Set Up Git
Alright, VM ready to go, all is good but we ain’t going anywhere without Git installed. Don’t know what Git is? Take the crash course and you’ll be up to speed within the hour. If you don’t feel like it don’t worry, I’ll cover the basics.
Git is in the officials reps, so installing is just a matter of:
sudo apt-get install git-core
Git has some basic configurations you need to setup before you start source controlling like a pro. Still at the terminal, this is my preferred configuration
git config --global user.name "Anonymous Bloke" git config --global user.email email@example.com git config --global core.editor vim git config --global merge.tool vimdiff #List these configurations git config --list
Git is now officially ready to go.
2. Start a new Qt Project
Qt’s IDE is called Qt Creator, and it’s also in the official reps:
sudo apt-get install qtcreator
This should install QtCreator 2.4.0 and pull Qt 4.7.4 as a dependency. Start it and you should see a window much like the one in the screenshot.
What are we looking at?
Well, there’s the sidebar on the left. This is the major anchor in the interface. From here we can access the code in Edit, we can design a UI by dragging and dropping elements in Design, GDB can be used in debug, projects list recent projects, Analyze is new so I’m not sure what it does to be honest, and finally, Help is for other people.
On the lower left, we have a couple of icons. First one is to configure the current build, the play button runs the program, bellow it is the button to debug a program, and the hammer thing is to just build and not run.
Humpf, all done. Got that? Ok, now let’s create a new project in fil…
Oh no you don’t! Decide on licensing first!
Nope, not kidding! The first thing we do when creating a new project is think about licensing. Each source file should have a header with the copyright declaration, where you, the copyright holder, inform the reader about the deadly consequences of stealing your code. I recommend you use the GPL V3 because although I find Richard Stallman to be quite a weird character, I do not doubt for a single second that he’s doing his best to protect our freedoms.
All code released under the GPLV3 should have a short notice on every source file. My template notice is available here, and I’d like to call your attention to the first 3 lines:
/* * %FILENAME% - Math Machine * Copyright (C) %YEAR% Anonymous Bloke
So, the project is gonna be called Math Machine and the copyright is for Anonymous Bloke, which you should change to your own name. Qt Creator will do all the work and automatically append this notice to your source files. The %FILENAME% and %YEAR% keywords will be interpreted by Creator and changed accordingly (you can see some more of these here if you need a more elaborate copyright notice).
To make use of this notice, define the file as the license template in Tools/Options/C++/File Naming/License template.
With the license template in place, we can finally create our project by hitting File/New File or Project. There, select Qt Widget Project/Qt Gui Application.
In the wizard there’s a couple of things you need to check.
First off, our project is gonna be called “MathMachine” and I suggest you put it in a new folder called developer in Documents. Just to keep shit organized.
Second, we’re gonna be brutal and uncheck Generate form in Class Information. In this example we won’t need it.
Lastly, in Project Management be sure to add this project to git instead of the default <None>.
Boom! We have a project. Standard Qt boilerplate, nothing fancy. You can even run it by pressing Ctrl-R. The result looks something like the picture to the right – an empty window called MainWindow. Sweet.
Your first commit
First things first, we commit! In Tools/Git/Commit. you should do something like in the screenshot.
Now, there’s a couple of things we need to do to push our source control all the way up to 11. First, right-click in main.cpp and choose “Open Terminal Here”. Then run
Which should say
# On branch master # Untracked files: # (use "git add <file>..." to include in what will be committed) # # MathMachine.pro.user nothing added to commit but untracked files present (use "git add" to track)
There’s a leftover file. Could be better. These .user files are Qt Creator instance specific – we should flat out ignore them. Let’s create and source control a .gitignore file – we don’t want anybody dealing with this .user business.
echo "*.user" > .gitignore git add .gitignore git commit
Your default editor will show up. There’s an unwritten rule that commits should have a short title and a brief description of the commit separated by a blank line. Like this.
Ignore *.user Added .gitignore with QtCreator *.user files.
Save and exit. Now, if we run git status we’ll see
# On branch master nothing to commit (working directory clean)
Which is much nicer. No MOM I don’t have OCD, don’t embarrass me in front of my friends!, I HATE IT when you do that, I just like things need und tidy, what’s wrong wit-
3. Prepare for public debut
Oh my! Who said anything about going public?! Don’t you just love surprises?! We’re gonna release the software as is!
According to the GNU standard, free software releases should come with a bunch of all caps files.
All GPL code should have, in addition to the copyright header, a COPYING file with a transcript of the GPL. It says so right here. So, open a terminal in the project root folder once more (right click on main.cpp, open terminal here) and
wget http://www.gnu.org/licenses/gpl.txt mv gpl.txt COPYING
Now, this is just a personal preference of mine, but I like to see this file in the project tree. You can right click on your project (the top level of the tree) and choose Add existing file to add the COPYING file and say Yes to add it to git. You know, just to keep shit organized.
A classic. Instead of add existing file, this time select ADD NEW and then General/Text file. Qt will insist upon the .txt, and you shall insist in renaming it by right-click on the file and selecting rename.
There’s a good standard for writing README files. It’s called AsciiDoc and it’s a good idea to use it. By following the syntax, we can convert our README to a webpage, a pdf, etc. Here’s a nice README for our program
Math Machine README =================== Anonymous Bloke <firstname.lastname@example.org> :website: https://linuxd.wordpress.com Math Machine ------------ Math Machine is part of "The Odyssey", a series of guides on how to properly distribute a free software application. It does two things and two things only: - Start. - Exit. I know. === Installation Please refer to the INSTALL file
We’ll do exactly the same thing with the INSTALL file. Just to keep shit organized.
Math Machine INSTALL =================== Anonymous Bloke <email@example.com> :website: https://linuxd.wordpress.com Math Machine cannot be installed. Yet. However, it can compile to a binary by doing qmake make :-)
Done. Now commit like before, and we’re golden!
4. Set up GitHub
That’s right, we’re gonna go with the latest trend. GitHub is DOPE.
Head over to www.github.com and register an account. Do remember to register with the same e-mail from your git configuration (“firstname.lastname@example.org” in this example)
Create an SSH Key
GitHub forces you to use a sweet SSH setup. In order to have write access to the repo, and hence be able to push, a local ssh key has to be created and registered with the website. Each machine should have a different ssh key, so you might want to repeat this process from the Ubuntu 10.04 VM.
Head over to the terminal. Again, mind the e-mail address.
ssh-keygen -t rsa -C "email@example.com"
Add your SSH Key to GitHub
On the GitHub site click Account Settings>SSH Public Keys>Add another public key. The public key is
ssh -T firstname.lastname@example.org
Which should reply
The authenticity of host 'github.com (188.8.131.52)' can't be established. RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added 'github.com,184.108.40.206' (RSA) to the list of known hosts. Hi bloke! You've successfully authenticated, but GitHub does not provide shell access.
Create a new repository
For our example, create a new repository called MATH MACHINE. GitHub will present instructions on how to add this new repo.
5. Now, Push!
You could add the repo to the local git like in the GitHub instructions
git remote add origin email@example.com:bloke/Math-Machine.git
Or use QtCreator’s GUI Tools/Git/Remotes
Name: origin URL: firstname.lastname@example.org:bloke/Math-Machine.git
Choose one, but you have to go to the terminal anyway for the FINAL PUSH.
git push origin master
Really! It’s done! Click continue on the instructions page on GitHub. And see your baby.
Notice that now, everytime we hit Tools/Git/Push in Qt Creator it will push the master to origin (meaning our code changes to GitHub). Do it in the terminal, via menus, you decide.
You probably noticed the README doesn’t look too good on the GitHub repo page. If you rename it to README.asciidoc it will render great. If you’ve reached this far, you probably know how to do this right? In QtCreator
- Rename README to README.ascii by right clicking on the file and selecting RENAME
Alright, first change! Pretty sweet, hum?
Dude, what a ride! Next up:
- Find out what Math Machine is actually supposed to do! Is it a calculator? Does it do math? Is it even a machine? Who knows! not me!
- Source documentation with Doxygen
- Unit Testing with QtTest
- Memory debugging with valgrind
- … And more!
If you’re considering serious software development, you should consider doing your development in a virtualized environment. When dealing with Linux, this is by far the best approach. Agility with virtualization will allow you to test your code in a multitude of different distros and scenarios, easily check for package dependencies, etc etc. The source code of your programmatic ramblings should be stored in a public server, instead of being kept local, trapped inside the virtual machine. This is why using version control software such as git or svn is crucial. But that’s for another talk, this one is about virtualization.
1. Get VirtualBox
VirtualBox is a full-feature free software virtualization suite that runs Linux like a charm. Download it from www.virtualbox.org or hit
sudo apt-get install virtualbox
on your console if you’re pro and are already running Linux. Super!
2. Get Ubuntu
Let’s talk about Ubuntu versions. As you may or may not know, Ubuntu releases a new version every 6 months. Every 2 years, in April, a long-term support version is released which is usually referred to as the LTS. LTS versions are supported for 3 years (5 years for servers) instead of the usual 1.5 years. The latest LTS versions are 8.04, 10.04 and the upcoming 12.04.
That’s a lot of versions. How do users choose what version to install? Well, regular users just stick with the latest version. We’ll call them general population or gen pop for short. This is to allude to the fact that they live in a sort of computing prison, constantly reinstalling their OS. So gen pop always upgrades to the latest version and doesn’t give a shit about the LTSs. Who uses the LTS? We’ll call them the saners, since they don’t live in a self-inflicted prison. They normally only upgrade from an LTS to an LTS.
Here’s a quick overview of the last 2 years of Ubuntu versions:
- 10.04 called the Lucid Lynx is the pinacle of a generation. It runs Gnome 2 and is taken seriously by professionals in computing-related fields. This where the saners are.
- 10.10-11.10 are a series of beta-level editions whose main objective is to develop and test the new Unity desktop. Only Gen pop and Ubuntu developers ride this wave.
- 12.04 called the Precise Pangolin is the first generation LTS running Unity. Everyone is a bit suspicious of what’s gonna happen. It’s due in 3 months. People in the professional area are especially suspicious of what the hell is gonna happen.
So, what’s the deal? As soon as 12.04 is released gen pop will adopt it immediately, so the 10.10-11.10 versions are irrelevant. Saners will only upgrade if Unity isn’t a disaster. Either way, what makes sense today if we intend our software to reach a high number of people is to support both Ubuntu 10.04 and 12.04. You can get the latest daily build of 12.04 here.
3. Create the machine
This is dead simple. Some basic configurations on the new machine:
- 1536MB RAM is a good base.
- 8GB dynamically allocated is enough for light development, adapt accordingly. Remember that dynamically allocated means the size of the disk file is proportional to the amount of disk used. So you can setup a 32GB disk, and the file that supports it is only 1GB in size, and as you use Ubuntu, the disk will start to grow.
4. Install Ubuntu
Start your VM and choose the Ubuntu iso you downloaded when the First Run Wizard asks you for an installation media.
Heads up! Boot into the live session first and install by double clicking the shortcut in the desktop. Choosing install Ubuntu from the boot menu will fail!
The rest of the installation is just a matter of clicking next next next as fast as you can.
VirtualBox provides a custom set of kernel modules to make Ubuntu run super-smooth. To install them go to Devices->Install Guest Additions in the VM’s menu. This will mount a CD with the required software. Now it’s just a matter of running the executable in the terminal. Open a terminal and hit
cd /media/VBOXADDITIONS/* sudo ./VBoxLinuxAdditions.run
Restart and boom, all done.
Here’s a couple of tricks and tips that will make your life easier as a developer.
Open terminal nautilus plugin-in
sudo apt-get install nautilus-open-terminal
Opens a terminal in the current nautilus folder. Super convenient. Just logout and log back in to see the new option in the context menu.
Go down you lousy paragraph! Down I say! DOWN!
sudo apt-get install terminator
Terminator ia a terminal that opens several windows and this way you can either control several machines through ssh, or be at several folders at the same time.
Useful for programs that have makefiles all over the place.
Have some tips of your own? Please leave a comment and I’ll add it to the post, we’re trying to look like a team here : -)
Alright, ready for development! At the end of this step you should have both versions running inside their own little VMs like in the pretty picture – PreciseVirgin and LucidVirgin. You’re ready to proceed to step two in this series.
Ladies and gentleman, boys and girls, reports of this blog’s death have been greatly exaggerated. Towards clearing this blog’s bad name, this is the first post and anchor point in what shall henceforth be know as the Odyssey – going from absolutely nothing, to an application rolling in Ubuntu Software Center. And by nothing, I mean nothing, not even Ubuntu itself. The main purpose of this undertaking will be to serve as a guide to anyone, young or old, n00b or pro, interested in developing software for Ubuntu.
People say Linux is fast. People say Ubuntu is fast. What are these people talking about exactly?
Well, it’s not the browser performance. Have a look at the performance results from Peacekeeper.
I ran these on a 6 year old laptop, an old centrino 1.7Ghz with a shitty ATI. Just for completeness sake, since it doesn’t really matter. I’m willing to assert that you will have similar results on any machine.
Add to this the shitty graphics drivers to slow the rendering down, and the ubber-shitty flash for the ultimate cherry on top of the cake.
So you see gentlemen, when you say linux is “faster” … well, it’s really not that simple. On the server? sure. On the desktop, on the applications that matter to the desktop user… it’s not faster. At all.
No wonder Ubuntu drains my battery much faster. Not only isn’t powersaving optimal for all my hardware because of inexistent manufacturer support, but the applications themselves burn much more cpu.
BONUS POINTS: Notice the font rendering in XP. Now Ubuntu. Now XP. Holy shit.
PS – A real post in what? Over a year? Holy shitz!
Here’s a question. You know what happens when you try to push a release 20 days earlier just to be released on a date with some special geek significance?
Allow me to answer in the form of screenshots.
More lulz to be added as they show up, stay tuned! Excitment! Exclamation points!
I use keyboard shortcuts in Firefox a lot. Ctrl+t for new tab. Ctrl+l to enter an address. Ctr+k for the quick search box. F11 for fullscreen.
I noticed that none of these work when I was watching a video on youtube. Which sucked. A lot. Turns out that’s bug 78414 in bugzilla, and it was reported back when I was in primary school and thought girls were gross. But things have come a long way, indeed there is a $1000 dollar “bounty” on the thing and still nothing has happened. brilliant.
See what I did there?