Thursday, 19 July 2012

Mounting an executable CD Drive in Linux

I ran into the below problem while installing Matlab onto a Linux machine. Hopefully this will help someone else!

On most modern Linux systems, CD drives are automatically mounted. The problem comes when they are mounted without any exec permissions - this means that any scripts, etc on the CD, or .iso, will be unable to run. To resolve this, follow the steps below:
  1. Find the name of your mounted CD drive by using:
     mount  
    
  2. Then remount the device with the exec bit set:
     mount -o remount,exec $DEVICE
Where $DEVICE is the name of the CD drive.

You'll then be able to run all executables on the drive - in my case, the Matlab executable was then launched using the below commands:
 $ su  
 $ /path/to/mounted/cdrom/./install  

Remember to logout as root when the installer has finished!
 logout  

Wednesday, 18 July 2012

Betty and George - an overview


This is the first in a series of posts detailing my latest hobby project. The bulk of the work was completed in under 10 hours, with minor styling tweaks taking a little longer to get right. The project is currently hosted here, and the source code is on Github here. As usual, please post any comments or opinions in the comments below, or tweet me directly @matalangilbert.

Introduction

Betty and George are Artificial Intelligence entities - they chat with each other in real time, and, somewhat incredibly in my opinion, make sense most of the time! They're sometimes witty, sometimes poignant, and sometimes inane, but they keep talking, no matter what!


Technical Overview

The application is split into two main parts. The backend is a Ruby program managing two Cleverbot instances (http://www.cleverbot.com), juggling responses between each instance. There's not too much to this, but I will go over the technical details in a future post.

Each conversational response is posted to a Rails application endpoint by the Ruby program, and then the front-end takes over. The frontend is backed by a Rails application, which receives data from the Ruby program, and displays it on the live site. There's a couple of neat techniques used on the main application page, which update the page in the background. The first is a background AJAX request, which hits the server every 5 seconds, retrieving new responses and adding them to the top of the scrolling conversation on the site. The second is an "Endless River of News" style endless scroll implementation. This invisibly loads more of the conversation as the user scrolls down the page, in much the same way as Twitter and other sites do. Individually, neither of these techniques are particularly new on their own, but combining them seamlessly was technically satisfying. I'll talk more about these techniques in a dedicated future post.


Hosting

At present, both the conversation program and the Rails application are hosted at Heroku. A future post will detail a few of the technical subtleties I discovered while deploying the live Betty and George website.

Now visit Betty and George!

OK, so this was just a brief overview of the Betty and George architecture - now go check them out, and let me know what you think in the comments below!


Monday, 16 July 2012

Thursday, 12 July 2012

Getting number of lines in all files in a directory - Unix

The bash command
 wc -l <file>
will print out the number of lines in <file>.

If you have a collection of files (.csv in the example below), and want to know how many rows are in each file, the command:
 for f in *.csv; do wc -l $f; done  
will print out a list of all the files ending in .csv, along with the number of lines in them.

To print the number of lines, without the filename, the cut command can be used, with the following parameters:
cut -d' ' -f1  

Combining them, we can use:
 for f in *.csv; do wc -l $f |cut -d' ' -f1; done  
to print out just the number of lines in each file ending in .csv in the directory.