Pragmattica

July 20, 2009

Caffeine for Linux 0.2 Released

Filed under: Linux — bnsmith @ 9:46 pm

Update: Caffeine 1.0 has been released. Read more about it here.

The pace of development has been frantic since the first release of Caffeine last month. Caffeine is an application that allows you to quickly and easily disable the screensaver and powersaving features of your computer, so that you can watch a long flash video or give a presentation without your display switching off. I feel some temptation to hold back the next release of Caffeine until the program is perfect, but that way madness lies. And so, with that in mind, I am pleased to announce the release of the 0.2 version of Caffeine for Linux!

What’s NewCaffeine_icon

This new version is a massive step forward, with loads of new features and improvements. In fact, so much has changed, it’s practically a new program. Specifically:

  • Incredible new icons (my own amateurish attempts have been thankfully retired)
  • Ability to select from a list of time intervals, and have Caffeine prevent powersaving for that amount of time
  • Ability to specify a custom time interval, and have Caffeine activate for that period
  • Official support for Kubuntu 9.04 and Xubuntu 9.04 (the previous release supported Ubuntu 9.04 only)
  • A new Launchpad project page
  • Fixed the bug that would cause Caffeine to quit if activated immediately after login

I’d like to thank all of the people who helped with developing or testing Caffeine. I’d also like to give a special “thank-you” to Tommy, who provided Caffeine with the new artwork, the new timed activation features and many other improvements too numerous to list here.

Installation Instructions

Caffeine is now available through a Personal Package Archive (PPA) provided by Launchpad. This means that once you install it, any subsequent updates will show up in your regular “Update Manager ” window.

To install Caffeine on Ubuntu 9.04:

  • Open a Terminal by clicking Applications -> Accessories -> Terminal
  • In the Terminal, execute the following commands, one at a time:
sudo bash -c "echo 'deb http://ppa.launchpad.net/bnsmith/ppa/ubuntu jaunty main' >> /etc/apt/sources.list"
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys B7DEAC3C
sudo apt-get update && sudo apt-get install caffeine
  • Go to System -> Preferences -> Startup Applications
  • Click Add
  • Set the “Name” field to Caffeine and the “Command” field to caffeine
  • Click Add and then Close
  • Log out and log back in; the Caffeine applet should appear in the top-right
Advertisements

June 27, 2009

Caffeine: Not Just for Beverages Anymore

Filed under: Linux — bnsmith @ 10:27 pm

Update: The new 1.0 version of Caffeine has been released.

The information in this post is now obsolete.

Please see this post for more information.

A few months ago, I attended a little get-together for software developers to share their projects and passions. One of the presenters that night faced the unfortunate situation of having his laptop repeatedly enter sleep mode as he discussed one of his slides. This caused the projector to blank out, interrupting his flow and forcing him to run over to his laptop to press a key.

After the presentation was over, one of the attendees demonstrated a handy utility that could have saved the presenter some embarrassment: Caffeine.

Another Example of Superbly-Designed Software for Mac OS

The idea is simple enough. The program consists of a little coffee-cup applet that sits on the right-hand side of the menu bar. The coffee-cup starts out empty, meaning that the applet is inactive.

01_mac_empty

When you click the empty cup, it fills up with coffee and begins preventing your computer from either activating the screensaver or entering sleep mode. Caffeine keeps your computer awake!

02_mac_full

And slideshow presentations is just the beginning. With Caffeine, you can watch long YouTube or Hulu videos without having to remember to lick the Cheeto-dust off your fingers and then hit a key every few minutes.

If you use a Mac, I suggest that you head over to Lighthead Software and download Caffeine right now. As soon as I saw it, I knew that I would have to track down whatever the Linux equivalent was and install it on my machine.

A Surprising Discovery

It took several hours of careful searching before I was finally forced to accept the shocking truth: there was no Linux equivalent. This is a highly unusual circumstance these days. There are some cases where the Linux equivalent of some piece of software is not as good as what’s available on the other platform, but there’s almost always… something.

My annoyance at the lack of an equivalent for this handy utility was quickly replaced by excitement, because I realized that this was an opportunity for me to make an important contribution. Which brings me to my next point. I am pleased to announce the immediate availability of the first public release of…

Caffeine for Linux

Following the philosophy of “Release Early, Release Often”, the 0.1 release of Caffeine for Linux is very rudimentary and could well contain major bugs. The largest problem that I know of is its incomplete support for KDE. The applet will run under KDE, but activating it will only prevent the screensaver from starting; the activation of sleep mode is not prevented.

Instead of spending all sorts of time thinking about which new features I should implement, I’d like to put you in charge of determining the priorities for future development. If there are any features that you would like to see implemented, just leave a comment and I’ll get to work. Just to get things started, here are a couple of ideas that popped into my head:

  • proper KDE support
  • a DEB package for easier installation
  • uploading the source-code to a proper project-hosting web-site, like Launchpad, Sourceforge or Google Code (which would you prefer?)
  • keyboard shortcuts to control the program without using the mouse
  • ability to activate for a fixed amount of time before allowing regular powersaving to resume (a useful feature of the Mac OS version)
  • ability to activate automatically when a certain program runs (there are some full-screen games for Linux that unfortunately allow the screen-saver to activate while you play)

Of course, these are just ideas that sound good to me. You’re the ones that are running this operation.

Installation Instructions

The following step-by-step instructions are meant for Ubuntu 9.04; users of other distributions will likely need to adjust for small differences. Also, be sure to substitute your username whenever you see <<yourusername>>.

  • Download this file to your home directory
  • Open a Terminal by clicking Applications -> Accessories -> Terminal
  • In the Terminal, execute the following commands, one at a time:
mkdir -p opt/caffeine
tar -xvf caffeine-0.1.tar.gz -C opt/caffeine
rm caffeine-0.1.tar.gz
  • Go to System -> Preferences -> Startup Applications
  • Click Add
  • Set the “Name” field to Caffeine and the “Command” field to /home/<<yourusername>>/opt/caffeine/caffeine.py
  • Click Add and then Close
  • Log out and log back in; the Caffeine applet should appear in the top-right

03_linux_empty

  • Click the icon to activate it

04_linux_full

That’s it. You should now be able to sit back and take in a mind-blowing video like this one without power-saving getting in the way. As always, leave a comment if you have any problems.

May 10, 2009

Encrypting Your Dropbox Seamlessly and Automatically

Filed under: Linux,Security — bnsmith @ 8:37 pm

A Tutorial for Ubuntu 9.04

About a month ago, I wrote an introduction to using the Dropbox service to backup your important data. Any data that you backup with Dropbox is encrypted and uploaded to Amazon’s S3 service. Unfortunately, it is the people who run Dropbox that hold the keys used to perform this encryption. Regardless of how great the service is, storing your files with Dropbox involves placing your trust in the people who currently run the Dropbox service, as well as all of the people who will ever run Dropbox in the future. This is an unacceptable risk for many people and many kinds of data.

Thankfully, there is a strategy that can greatly reduce the risk. It is possible to automatically encrypt your files, and then use Dropbox to backup the encrypted versions. This means that you can have your cake and eat it too! Dropbox provides a convenient backup strategy so that your files can’t be lost due to the theft or destruction of your laptop. The encryption software ensures that your files can’t be accessed by anyone who works for Dropbox, or any hackers that might have infiltrated the servers that Dropbox uses.

If you’re using Ubuntu, the software that you need is free, and it isn’t especially difficult to set up. Please note that this tutorial will require you to use the command-line and edit some configuration files. Don’t be afraid! I will try to explain the process in a step-by-step fashion. If you’re just getting started with Linux, this project might help you get used to the command-line a little bit.

(Note: this has been tested on Ubuntu 9.04 only; I am not confident that these exact instructions will work on older versions of Ubuntu.)

Part 1: Set Up Dropbox

The rest of this tutorial will assume that you have the Dropbox client software installed on your computer. Detailed instructions can be found in the “Installing Dropbox” section of my previous post on the Dropbox service. When you have finished following those instructions, proceed with Part 2.

Part 2: Removing Unencrypted Data

This section only applies if you have already used Dropbox to store some data that you would now like to encrypt. If you have never stored any files in your Dropbox, skip ahead to Part 3.

The first step is to take all of the contents of your Dropbox folder and back them up somewhere else. The following command will copy everything in your Dropbox into a folder named “DropboxBackup” (open a Terminal by clicking Applications -> Accessories -> Terminal):

cp -r ~/Dropbox ~/DropboxBackup

Once everything has finished copying, it might even be a good idea to burn this folder to a CD, just to be safe. Now we can proceed to delete all of the files in the Dropbox folder. Open your Dropbox folder in the file manager by left-clicking on the Dropbox applet in the top-right. Click the “View” menu and ensure that “Show Hidden Files” is checked. Next, select all the files and hit the Delete key. Dropbox should begin synchronizing the changes. Unfortunately, once the synchronization completes, nothing will have been actually deleted yet; the files will simply be marked as deleted, but it will still be possible to recover them.

In order to actually get rid of the files, open your web browser, go to www.getdropbox.com and log in. Click the “Show deleted files” button.

01_show_deleted

For each deleted file, select the “Purge” option.

03_purge

Part 3: Reconfiguring the Dropbox Client

The encryption software that will allow you to secure your Dropbox is called “EncFS“. It works by creating a folder in which to store an encrypted version of each of your files and folders, and then making the unencrypted names and content available in a different folder. When we are finished with this tutorial, the folder containing the encrypted files will be stored within the Dropbox folder, and will therefore be automatically backed-up. Since we don’t want to accidentally store any non-encrypted files in the Dropbox folder, we will move the real Dropbox folder to a hidden location.

Right-click on the Dropbox applet and choose “Preferences…”; under the “Main” tab, click “Move…”:

05_move

Move to your Home Folder and click the “Create Folder” button. Give the new folder the name “.dropbox_encrypted” and click “Open”. Close the preferences window. On to Part 4!

Part 4: Configure an Encrypted Filesystem with EncFS
Now we’re ready to actually do some encrypting. In the commands that follow, you will need to substitute your username in place of <<yourusername>>. Open a terminal and enter these commands:

sudo apt-get install encfs libpam-mount
sudo adduser <<yourusername>> fuse

(As an example, if your username is “pragmattica”, then the command just above should be sudo adduser pragmattica fuse)

Now you need to log out and log back in again before continuing. Next, run this command:

encfs ~/.dropbox_encrypted/Dropbox/encrypted ~/Dropbox

06_terminal

The encryption software will ask you a series of questions. Enter the following responses:

  • Enter ‘y’ to create the encrypted directory
  • Enter ‘y’ to create the unencrypted directory
  • Enter ‘x’ to choose expert Mode (I experimented with the pre-configured paranoia mode, but encountered performance issues)
  • Enter ‘1’ to use the AES cipher algorithm
  • Enter ‘256’ for the key size
  • Enter ‘1024’ for the block size
  • Enter ‘1’ for block filename encoding
  • Enter ‘y’ for filename initialization vector chaining
  • Enter ‘n’ for per-file initialization vectors
  • Enter ‘n’ for block authentication code headers
  • Enter ‘y’ for file-hole pass-through
  • Enter and repeat the password for the new encrypted filesystem; in order for the next part of the tutorial to work, the password must be the exact same password that you use to log in to your computer after turning it on

I’m probably not telling you anything that you don’t already know, so I’ll be brief. A good password should consist of upper and lower-case letters, numbers and punctuation characters. It should be fairly random looking, and pretty long; more than 20 characters, preferably.

You can now begin copying files into your /home/<<yourusername>>/Dropbox directory. The files that you copy in should be encrypted and backed-up by Dropbox. If you log in to the Dropbox website, all of the saved files should have meaningless gibberish names and encrypted contents.

08_gibberish

Part 5: Use pam_mount to Automatically Mount Your Encrypted Filesystem

At this point, it would be possible to use the command-line to manually mount your encrypted filesystem every time you turn your computer on, but we can do better. A program named “pam_mount” can automatically mount the filesystem as soon as you log in. Open a terminal and enter this command:

sudo gedit /etc/security/pam_mount.conf.xml

Look for the line:

<!-- Volume definitions -->

Right beneath that line, add this new line:

<volume user="<<yourusername>>" fstype="fuse" path="encfs#/home/<<yourusername>>/.dropbox_encrypted/Dropbox/encrypted" mountpoint="/home/<<yourusername>>/Dropbox" />

To eliminate a harmless but annoying error message, use “sudo gedit” as above to edit the /etc/pam.d/common-pammount and /etc/pam.d/common-auth files and eliminate all occurrances of the word use_first_pass.

The next time you turn your computer on and log in, you should be able to go to your new /home/<<yourusername>>/Dropbox folder and see the unencrypted versions of your important files. Unfortunately, this new folder won’t display the little status icons on each file, so you’ll have to keep an eye on the Dropbox applet to know when the synchronization of your files is in progress or complete. I think that this is a very reasonable sacrifice for the additional security.

One last tip: the icon for your secure Dropbox folder is now the same as for every other folder. To give that folder some visual distinction, it’s possible to change its icon. Right-click on the folder and select “Properties”. Click on the little Folder icon in the top-left of the properties dialog box and set the icon to /usr/share/icons/hicolor/64×64/apps/dropbox.png.

07_new_icon

Security Considerations

As an added benefit, this strategy will also provide a little protection against your information being compromised by someone who steals your laptop. The reason this only provides a little protection is due to the tendency of modern operating systems and software to scatter bits of information about while working. The actual files themselves are encrypted, but unencrypted bits of the files might still end up lying around in temporary files or the swap partition. An attacker with enough skill and determination would be able to find those. Still, it’s better than nothing.

This is probably going to be my last security-related post for a while. I’ve been going through a security phase lately, but I’m feeling pretty good about the precautions that I now have in place. Next post, I will be back to my regularly scheduled programming topics. As always, if you have any problems with anything in the tutorial, just leave a comment. I’m always happy to help.

March 29, 2009

Protect Your Important Data with Dropbox

Filed under: Linux — bnsmith @ 9:47 am

An Easy Backup Solution for Ubuntu
I bet you think that you already know how to easily backup your files: just pop in a blank CD-R, pick the files to backup, burn it and you’re done. But suppose that I actually suggested that you try this backup method, would you do it? Maybe you would get around to it next week, or next month, or next year; just as soon as you got a bit of free time.

Sorry, folks, but that’s not good enough. In order to protect your important data, you need a strategy that’s automated. One that works no matter how busy you get–because the times when you’re busiest are the times that you need those backups the most.

I’ve given this problem some thought over the years, and the best solution that I know of is an online service called Dropbox. The basic idea is that the Dropbox program creates a folder on your hard drive, and anything that you copy into that folder is backed up online.

Why Dropbox?
The following five points were the main factors in my decision to select Dropbox as my primary backup solution.

  1. Dropbox is free. A Dropbox account won’t cost you a cent, and the founders have promised to keep the lowest tier of service free forever. Someday they may be bought out by a larger company and things could change, but for the foreseeable future, their service is totally free of cost, and even free of ads.
  2. Dropbox is fully automated. It runs in the background and constantly watches your Dropbox folder. Any time you copy a new file into that folder or modify an existing file, Dropbox will detect the change and upload the parts of the file that have changed. With text documents, it usually completes the backup operation within seconds of clicking the “Save” button.
  3. All your files are available through a convenient web-based interface. If you’re away from your main computer, you can still log in to the Dropbox web-site and download any of the files that you keep in your Dropbox folder.
  4. When you make changes to your files, Dropbox actually keeps the older versions. I imagine that most users probably won’t use this feature often, if at all. However, under the right circumstances, it could save you from a potentially costly mistake.
  5. Have Dropbox installed on multiple machines, and it will keep a fully synchronized copy on both! Given this fact, the right setup would reduce the amount that you would need to trust the people who run Dropbox. Suppose that you have a work computer and a home computer. If you have Dropbox installed on both computers, and save a file in your Dropbox folder on your work computer, it should be copied up to the Dropbox servers and then back down to your home computer in a few seconds. This means that you would always have a copy of your important files saved on a computer that you own and control.

It Sounds Too Good to be True!
Dropbox is not without its faults, so I suggest that you read the following carefully before making a decision.

  1. The free service only allows you to keep 2 GB of data backed up on the Dropbox servers. If you are willing to spend US$99 per year, then you can increase this limit to 50 GB. Still, if your passion is making movies, for example, even this might not be enough.
  2. Using this service requires trusting the employees of Dropbox. When you copy a file into your Dropbox, you are trusting that they will keep the file safe, secure and private, not just now, but forever after. Who knows what might change in 50 years? Perhaps the future owners of Dropbox will change to a blackmail-oriented business model and threaten to publicly release your files unless you pay them an exorbitant yearly fee. For this reason, I don’t recommend using Dropbox to backup anything that is so sensitive that its release would be life-destroying (at least, not without additional protection). This means that Dropbox is absolutely not the right place to keep the passwords for your bank accounts. I’m not trying to say that you can never keep anything even remotely private in your Dropbox, just that you need to consider the risks. Imagine, for a moment, that you’re writing a novel. If you manually backup your novel once per week, then a hard-drive crash could lead to the loss of several days worth of work. This would then necessitate the motivation-destroying process of rewriting thousands of words over again, which might easily doom the entire novel. On the other hand, if you keep automatic backups of the novel with Dropbox, you face the slight possibility of your novel’s incomplete draft being published on the Internet, likely through some undetected security flaw being exploited by a hacker. As you can see, both options have risks associated with them. For each file that you consider putting into your Dropbox, you must weigh the risk of losing that file due to the lack of an adequate backup solution verses the risk of that file being exposed. Unfortunately, this is a difficult choice to make, and there is nothing more that I can say to help you choose. It’s possible to decrease the likelihood of your data being exposed by encrypting it before placing it in your Dropbox, but this is less convenient.
  3. The Dropbox service is entirely Internet-based. Files are only backed-up when you are connected to the Internet. If you are planning on travelling to a country where Internet access will be sporadic or unavailable, you will need to come up with an alternate backup strategy.
  4. Dropbox includes a feature that allows files to be shared publicly and made accessible to anyone on the Internet via a special web-site address. To share a file, simply place it into the “public” folder within your Dropbox. A feature like this could indeed be helpful, but I recommend staying away from it. The Dropbox “Terms and Conditions” describe the licensing implications of placing any file into the “public” folder, and their chosen licensing conditions may not meet your needs. If you wish to share your photographs, for example, it is probably better to do it through some other venue where you are in control of the exact license that your photographs are shared under.
  5. Dropbox doesn’t currently include a feature allowing the synchronization of any files or folders outside of the main Dropbox folder. Actually, there is a way to do this, but it requires some technical knowledge. I will explore this topic in a later post.

Installing Dropbox
Now that you know the pros and cons of this backup strategy, if you still wish to try it, just follow these instructions:

01_website2

  • Click the big “Download Dropbox” button

02_download1

  • It should take you to the download page for Linux; click the link for your version of Ubuntu and your processor architecture (either regular x86 or 64-bit x86)
  • Save the file to your Desktop
  • Double-click the file on your Desktop; the “Package Installer” program should open
  • Click the “Install Package” button; enter your password
  • Log out and then log back in
  • You should now see the Dropbox icon in the top-right

03_desktop1

  • Left-click the Dropbox icon to start the setup wizard

04_setup1

  • Go through the wizard to set up a new Dropbox account
  • Once the wizard is complete, you should be able to go to Places -> Home Folder and see your new Dropbox folder

05_folder1

Now, just keep the files that you want to backup in your Dropbox folder. You can edit them and move them around as much as you want. Dropbox won’t miss a beat. If you have any questions about Dropbox or suggestions for a better backup solution, please leave a comment.

March 31, 2008

Convert iTunes M4A Files to MP3, With an Easy-To-Use GUI

Filed under: Linux — bnsmith @ 9:29 pm

A few months ago, I described the steps needed to convert DRM-free iTunes M4A files into MP3 files using Ubuntu Linux. The procedure worked, but was more difficult than it should be, so now I’ve built a GUI front-end. No command-line typing is required!

How to Convert M4A Files to MP3 Files

Step 1: Enable Additional Software Repositories

  • Click on System -> Administration -> Software Sources (You may need to enter your administration password)

post9_1.jpg

  • Check the “Community-maintained Open Source software (universe)” and “Software restricted by copyright or legal issues (multiverse)” repositories

post9_2.jpg

  • Click Close
  • Click Reload on the pop-up window

Step 2: Download and Install the Conversion Program

post9_3.jpg

  • Ensure that the Open with option is selected; click OK (You may need to enter your administration password)
  • Click the Install Package button
  • When the install process is complete, close the pop-up and the installer program

Step 3: Convert Some Music Files

  • Click on Applications -> Sound & Video -> Convert To MP3
  • Click the Browse… button in the Directory to Convert box
  • Find the directory containing your M4A files and click Open; the program should now look something like this:

post9_4.jpg

  • Click on the Begin Converting button

It will likely take about thirty seconds to convert each file. If you find a bug, please either post a comment here or report it on the Google Code Project page. I’m also happy to implement new features, if you have any ideas.

Technical Details

It seems to me that making the GUI took just as long as making the actual conversion script, if not longer. I spent a lot of time experimenting with different GUI systems. I tried out Dabo, and was leaning heavily towards using it for this project. Unfortunately, as I worked with the IDE, I encountered a few frustrating usability issues that kept me from embracing it fully. Notice that I said “usability issues” instead of “bugs”. The software wasn’t buggy at all, and I think that the Dabo people should really be proud of what they’ve accomplished. It just needs to be a bit… simpler. Simple is better than complex.

I discarded QT for the same reason. Perhaps if I need a more powerful GUI system in the future, I’ll consider looking at it again.

In the end, I decided to go for wxPython with wxGlade to graphically design the layout. I really appreciate both the simplicity of this system, as well as the attractiveness of the result. It isn’t perfect, of course. I wish that the wxWidgets toolkit had an available control that was like a tabbed notebook, but without any tabs and controlled programatically. I know that there are several workarounds, but I would still like to see one of the workarounds integrated into the toolkit.

This is also the first time that I’ve created a Debian package. The process was more difficult than I’d hoped but easier than I’d feared. It was very time-consuming to boot my computer with the Ubuntu 7.10 live CD, try to install the package, find that I’d missed a dependency or something, go back and fix it and then repeat the whole process again. Still, it could have been a lot worse. I probably would have given up my packaging effort if not for this video.

Anyway, if you have any questions about creating GUIs or Debian packages for Ubuntu, leave a comment and I’ll help if I can.

January 17, 2008

Convert iTunes M4A files to MP3 on Linux

Filed under: Linux — bnsmith @ 3:00 am

And Keep Some of the Tags!

Update: I have just finished creating a GUI front-end for the conversion program described below. This new program can be installed easily through a package and should be easier to use, so I suggest you follow this link and try the directions there first.

I love iTunes. It was the first web retailer to sell music from the major labels with no DRM. On the night that iTunes Plus first became available, I stayed up late, trying to find some albums that I wanted, just because I wanted to see the folks at iTunes and EMI rewarded monetarily, and wanted to do my bit. Of course, iTunes Plus music comes in non-DRM-encumbered M4A format, which doesn’t play on many portable MP3 players, and doesn’t play very well on others.

There are plenty of posts describing how to convert M4A files to MP3, but most of them completely ignore the information about the artist, album, and so on embedded in the file as tags. I don’t know about you, but I think tags are important. I don’t want to sift through 500 tracks named “unknown” on my MP3 player.

The program that I’ve created will convert a directory full of M4A files to MP3, preserving the artist, album, song name and track number tags. Hopefully this should be enough to play a whole album, in its proper order, with no confusion.

These instructions are specifically for Ubuntu 7.10, but should work on other distros with some modifications.

The first step is to install some required libraries. Open a terminal and type:

 sudo apt-get install id3v2 mplayer lame python-mutagen

Next download my program here, and extract it. Suppose that your iTunes music is in “/home/youruser/itunes”. In your terminal, go to the directory where you extracted the program and enter this command:

./ConvertToMP3.py /home/youruser/itunes

The original files will be left untouched, and new MP3s should be put into a new directory called “/home/youruser/itunes_mp3”. If you have any problems, don’t feel bad about leaving a comment asking for help. In fact, even if you don’t need help, maybe you could just leave a comment anyway. It would be the first comment I’ve ever gotten. 😉

November 25, 2007

Getting Started with Scheme on Ubuntu — Part 2

Filed under: Linux,Scheme — bnsmith @ 11:59 pm

Installing and Using SLIB

Scheme is a very minimalistic language. This is Scheme’s great strength, but this trait can also make the language seem a little bit barren. There is a collection of excellent libraries that can help allieviate this, though using them requires some set-up. First, follow the directions from Part 1, if you haven’t already. As with Gambit Scheme itself, the version of SLIB in the Ubuntu repositories is not the latest, so we will install from source.

Go to the SLIB website and download slib3a5.zip to your home directory. The download link is under the “Quick Start” heading.
pic0.png

Next, open a terminal (Applications -> Accessories -> Terminal) and enter the following commands:

unzip slib3a5.zip
cd slib
sudo make install

Then, edit the SLIB configuration file with the command:

sudo gedit /usr/local/lib/slib/gambit.init

Find the line:

  ((unix)    (lambda () "/usr/local/share/gambc/"))

pic12.png

and change it to:

  ((unix)    (lambda () "/usr/local/Gambit-C/current/"))

pic22.png

Now start the interactive interpreter with root permissions:

sudo gsi -:s /usr/local/lib/slib/gambit.init -

In the interpreter, enter the command:

(require 'new-catalog)

Exit the interpreter by pressing CTRL-D twice. Finally, copy and paste this command into your terminal:

echo "(include \"/usr/local/lib/slib/gambit.init\")" > ~/.gambcini

SLIB is now fully installed and can be used by the Gambit Scheme interpreter. To test the installation, run the interpreter by typing gsi and paste in the following code:

(require 'random)
(random 10)

This should display a random number from zero to nine. It is similarly possible to use SLIB with programs saved in files. Copy the following code into a text file named slibtest.scm:

(require 'printf)
(require 'srfi-1)
(define userlist '((45607 "Ted Randalph" 34.90 5)
                   (91238 "Rob Smith" 32.45 3)))
(for-each
  (lambda (userinfo)
    (printf "Employee %s (%d) has %d years experience and makes $%.2f per hour.\n"
      (second userinfo) (first userinfo) (fourth userinfo) (third userinfo))) userlist)

This program can be run by entering gsi slibtest.scm and should display the following output:
pic5.png
Check out the SLIB documentation for a complete list of what is available.

November 23, 2007

Getting Started with Scheme on Ubuntu — Part 1

Filed under: Linux,Scheme — bnsmith @ 3:44 am

Installing Gambit Scheme

As I described in my previous post, I am a fan of the Gambit implementation of Scheme. While following these instructions, try to keep in mind that the Scheme community is smaller than the communities of the more major languages like Python or Ruby, so there are still rough edges that get in the way. I hope that my experiences can speed things up for other fledgling Schemers.

It is possible to install Gambit Scheme from the Ubuntu repositories. However, the repositories contain an older version, so I recommend building Gambit Scheme from source instead. First, go to the Gambit Scheme website.

pic11.png

Click on the “Sources” link and save the gambc-v4_1_0.tgz file to your home directory. Next, open up a terminal (Applications -> Accessories -> Terminal), and enter these commands:

tar -xzvf gambc-v4_1_0.tgz
cd gambc-v4_1_0
./configure && make
make check
sudo make install
sudo make bootstrap
cd /usr/bin
sudo ln -s /usr/local/Gambit-C/current/bin/gsi gsi
cd ~

Once the installation is complete, conduct a few tests. From your terminal, enter the command:

gsi

You should then see Gambit’s interactive interpreter prompt. Enter the following code:

(define numlist '(2 10 6))
(map (lambda (x) (* x x)) numlist)

You should receive these results:

pic21.png

Exit the interpreter, by pressing CTRL-D twice. You can also use the Gambit Scheme interpreter to run Scheme programs stored in files. As an example, put the following text into a file named hello.scm:

(display "Hello World!\n")

Run the file with the command:

gsi hello.scm

That should be enough to start experimenting with Scheme. Part 2 will describe the installation and use of the SLIB libraries.

Create a free website or blog at WordPress.com.