Feb 22 2008

Crazy One-Liners

Tag: hack, linux, ubuntuScott Wegner @ 7:42 pm

Command TerminalSo I wrote a pretty interesting one-line command for a specific task today. Here it is– can you guess what it does?

awk '1 {system("lwp-request -Sm HEAD " $0)}' \
input.txt | awk '/200 OK/ {print $2}' > output.txt

Yeah, me either if I were just looking at it. But let’s break it apart, piece-by-piece. You’ll notice that’s its essentially two commands, strung together through some piping and redirection (the “\” character is just to break the command up in two lines). It’s broken up like so:

{command1} | {command2} > {file}

This says to execute command1 first. Then pipe it’s output into command2 as input. Finally take the output of command2, and throw it all into a file. So we start with the first command:

awk '1 {system("lwp-request -Sm HEAD " $0)}' input.txt

So what the heck does awk do? Well, it’s basically a utility to read in input text, do some filtering on it, and then execute a specific task (or tasks) based on the results. In this case, it has the form:

awk 'filter {command}' input

Skipping first to input, we see that the text we want to process comes from a simple text file– in this case, input.txt. filter is what decides which lines of the input actually get used. Generally it’s in the form of a regular expression, and the matching lines are processed. In our case, we just use 1, which means everything matches, and we will process all lines. Next to the command:

system("lwp-request -Sm HEAD " $0)

In awk, the system command actually specifies that the parameter command should be executed in a sub-shell. The parameter is a quoted string, and using $0 means that we should use the first token of the matching line each time. So the function we really want to look at is:

lwp-request -Sm HEAD {token}

The lwp-request command, as seen here, is a command-line utility to send HTTP requests to a server, and observe there response. It has one required argument, which is the URL to query. Since we don’t see that explicitly here, that must be coming from the token we parsed from our input. We also specify two other parameters. -S tells the program to “print the response chain,” meaning that it will show any redirection or authorization handled automatically. Also, we use -m HEAD, which specifies that we are interested in the header data from the HTTP response. So far, pretty confusing, right? Well, let’s see what a sample query looks like:

$ lwp-request -Sm HEAD http://google.com
HEAD http://google.com --> 301 Moved Permanently
HEAD http://www.google.com/ --> 200 OK
Cache-Control: private
Connection: Close
Date: Sat, 23 Feb 2008 01:27:27 GMT
Server: gws
Content-Length: 0
Content-Type: text/html; charset=ISO-8859-1
Client-Date: Sat, 23 Feb 2008 01:27:36 GMT
Client-Peer: 64.233.167.104:80
Client-Response-Num: 1
Set-Cookie: PREF=ID=4b507d757f70e13b:TM=1203730047: (...)

Interesting, sort of. Anyway, let’s move on. So that little piece of code is getting executed for the first token of every line in our input file. Then, the output is getting “piped” into our next command:

awk '/200 OK/ {print $2}'

We’ve seen awk before! This time, though, we don’t specify an input file, because the input comes directly from the previous command. Our other parameters have changed as well. The filter is no longer 1, but rather /200 OK/. This is a true (albeit simple) regular expression, and matches any line that contains the string “200 OK”. Only lines with this string will be processed. Which brings us to our command, or action: print $2. print means to simply output what follows. In this case, $2, which represents the second parsed token. awk is going to consider everything that is piped in from command1, filter out lines it doesn’t care about, and execute the action on the filtered set. Looking at our sample output above, the only matching line is:

HEAD http://www.google.com/ --> 200 OK

This line will be used in the command, print $2. The command simply prints the second token (separated by a space) on the line, so it outputs:

http://www.google.com/

The final piece of our code redirects command2’s output into a file, output.txt. And that’s it! So putting the pieces together, let’s look at what is really happening here:

  • We read in data from an input file for parsing. We can infer that each line contains a URL, which is needed later
  • Each URL is passed to the lwp-request command, which outputs header information from the server
  • We filter the response information down to only the bits we care about. In this case, a new URL
  • Finally, we output each of these “new” URL’s to an output file.

So, that’s the whole one-liner. A little more compactly, it’s a piece of code that takes a list of input URL’s, and outputs the URL’s that each one redirects to. It’s a pretty specific snippet, and has absolutely no error-checking, so is definitely prone to bugs. But, it worked for me the one time I needed it, and it was enough to show off.

On a side-note, this little piece of code made the difference between hours of mindless data-entry, and automated awesomeness.

If you're new here, you can subscribe to automaticable's RSS feed by clicking here. Or, you can get post updates through your email. Thanks for visiting!


Feb 21 2008

Synfig - The Linux replacement for Flash

Tag: linux, software, technology, ubuntu, windowsJoe Wegner @ 5:54 pm

Synfig LogoMy recent changeover to Ubuntu Linux has had me searching for easy replacements for all of my Windows programs. The Linux community has made this a pretty easy task, especially with Ubuntu. Ubuntu provides you with Gimp (Photoshop), Firefox (Internet Explorer), Thunderbird (Outlook Express), and the OpenOffice Suite (Microsoft Office Suite). One thing they do not provide you with, however, is an easy replacement for Adobe Flash. Adobe Flash was one of my commonly used programs on Windows, because I do a lot of intro movies for my youth group. Not having a replacement for it was a major downfall for Linux.

Seeing this problem, for about two weeks I searched around for a good replacement for it. I ran across programs such as Flash-4-Linux and OpenLazlo. I heard good things about both of these programs, but found that the install was a bit difficult for a Linux newbie. Then I ran across a program called Synfig. It looked like it had good documentation, and a pretty easy install. All you had to do to install was open up a terminal and put in:

sudo aptitude install synfigstudio

After installing Synfig and opening it (Applications > Graphics > Synfig Studio), I found that I really liked the interface. The synfig interface is broken up into multiple windows, much like that of GIMP. This makes it very easy for me to customize it to my specific needs and project. I also noticed that it had a very easy tool selection menu. Choosing a brush, color, and all the other properties of the brush is very simple.

One of the main features I found in synfig that I have come to love is the different keyframe setup from Adobe Flash. Instead of having the keyframes, time, motion tweens, and everything else all bunched up onto a single window like Adobe Flash, synfig seperates all of these components. This means that creating keyframes is a much simpler process, and is much easier to get them at the precise moment you want.

The only downfall, however, is that Synfig is not made to do intense visual editing. Synfig only allows you to go about as complex as creating a simple gradient. Anything greater than that, such as opacity, blending, or even just adding text is not implemented. This means that if you want to make a very nice looking flash movie, you’ve got to couple Synfig with GIMP.

I would say that, if you are a fan of Adobe Flash, you should definately give Synfig a try. It is a great alternative for Linux, it’s got plenty of documentation, and the interface is very simple. Check out the website to get started, or use the terminal command above.


Feb 17 2008

Build a Photo Mosaic: Wosaic 0.1 beta1

Tag: linux, mac, software, windowsScott Wegner @ 5:24 pm

Seurat MosaicEver wondered what you could do with all the hundreds of digital pictures that you’ve accumulated? Why not make a mosaic?

Wosaic is a software project that I started working on as part of a programming class. My partner and I enjoyed making it so much, that we continued working on it, and today we had our first “public” release. From the project webpage:

Wosaic is an open source project that allows you to recreate an existing image by using many smaller images, as shown above. It was started as a project for CS 242 - Programming Studio at UIUC, and will be continuing on to Engineering Open House in the Spring of 2008.

Wosaic is not the only program of its kind. Several other solutions already exist, however Wosaic aims to be free, easy to use, fast, and accessible. These qualities are yet to be found in any single existing solution. We’re also aiming to make use of interesting sources for images. Currently, we support Flickr, Facebook, and local sources, but we hope to expand this to possibly include images from Picassa, and hopefully other sources as well.

Features

  • Easily create a mosaic out of an image on your disk
  • Utilizes Flickr, Facebook, and local directories for images
  • Supports concurrency to provide fast results
  • Shows progress by constructing the mosaic right before your eyes!
  • Programmed in Java
  • It is FREE and released under the GNU GPL v2.

We’re really excited about the release. It’s a beta version, so it’s not quite as polished as we expect future releases to be. But, give it a try– we’d love to hear your feedback. Binaries for Windows, Mac OS X, and Linux can be found on the downloads page, and documentation for installing and using Wosaic is available in the wiki.


Feb 15 2008

Customize Your Dual-boot: GUI Frontend to GRUB

Tag: linux, software, ubuntuScott Wegner @ 11:47 am

I recently discovered via the Ubuntu Geek blog, a simple tool for customizing your GRUB boot menu. If you’re not familiar, the GRUB menu is the screen you see shortly before your Linux OS starts up. In a dual-boot setup, it is particularly important, because this is where you choose which operating system to boot to. Generally the setup is done via editing the file /boot/grub/menu.lst, but using the program makes it much easier. Continue reading “Customize Your Dual-boot: GUI Frontend to GRUB”


Feb 08 2008

Rockbox

Tag: ipod, linux, softwareJoe Wegner @ 10:17 pm

I’m sure that you have noticed that now-a-days almost everything can be found in an open-source version. Everything from software for your computer, to textbooks for school can be found free and open source. Now you can even get the awesome perks of open source on your very own iPod!

Rockbox is open source firmware for your iPod, or many other types of mp3 players. This means that everything is free, new, and extremely customizable. Rockbox has everything from awesome themes, to an iPod version of Doom. With Rockbox the limits of your pocket music player are endless!

Installing Rockbox on your mp3 player is fairly simple. You can either go the automated route, or the manual route. Personally, I went the automated route, even though it is not guaranteed safe. In most cases, it is still probably safer than digging around in your iPod’s file system. To get the automated installer go here. Then installing is as simple as running the file, choosing your player, and pressing go!

Upon starting up my iPod (4th Gen Grayscale, and uber old) I found that the Rockbox display was pretty bland. This was a pretty quick fix, though. Simply go to the settings menu and choose one of the many pre-made themes for your player. You can also choose from different sizes and different fonts in your settings menu.

The interface while playing music with Rockbox, although odd when first starting with it, is actually pretty great. It displays all of your track info, including artist name, song name, album name, next song, and other information about your kbps on the current song. By holding down the Menu button it takes you to an easy to use interface for choosing your shuffle, repeat, and other listening settings.

For all of you people that are not just contented by just listening to music wherever you go, Rockbox also comes with tons of games. You can play everything from dice, to chess, to Doom! Simply go to Plugins > Games and choose your favorite game. For most games, your music will continue to play while you play the games.

Open source things, although usually pretty good, are not entirely without flaws. Twice in my three days of using Rockbox, I found that it was saying I had run out of battery. After getting this message I would have to do a manual restart (menu + select for 6 seconds) and it would restart just fine. If you find that you can’t get Rockbox working, it is fairly simple to get back to the original firmware. Turn off your player, and turn it on. As soon as it turns on switch on the hold button and it should restart to the original firmware.

The Breakdown:

Pros:
- Open Source goodness ensures easy customization.
- Themes, fonts, and sounds for every personality out there
- Easy installation, and just as easy uninstallation
- Plenty of documentation on the website, if you get stuck


Cons:

- Having two seperate firmwares will use extra space
- Seems to have bugs telling how much battery is remaining
- Many themes have an odd number-based volume display
- Although it won’t break your warranty, you will not be able to get any support while you are running Rockbox


All in all, Rockbox is definately worthwhile if you want to get away from the crowd, and make your mp3 player very personalized. Easy installation, easy customization, and easy interface makes it a win win win decision. Check out http://www.rockbox.org/ to get started.




Feb 08 2008

Backup DVDs with dvd::rip

Tag: linux, software, ubuntuScott Wegner @ 5:22 pm

(screenshot source)
I’ve always been a little unorganized with my DVDs– some are in their original cases, some live in a case amongst some other software CDs, some are just completely lost. I’ve been meaning to get organized with my DVDs, but I just never got around to it.

Instead, I decided to back them up on my computer. This is convenient because I generally watch them on my computer anyway. Also, I’ll never have to worry about them getting scratched or lost.

Which brings me to dvd::rip, the DVD ripper of choice on Linux. I started using it earlier this week, and am very happy with it. It’s a little rough around the edges, because it’s so feature-rich. The program itself is basically a GUI wrapper for a number of command-line utilities, and each option refers to a command-line flag you can set. As a result, you can very carefully fine-tune the results of your rip– from target size, to resolution, to subtitles.

One of it’s best features, in my opinion, is it’s “Cluster” daemon. Basically, you are able to distribute the job of transcoding the video amongst as many machines as are available. The job is broken up into parts, and many computers can get the job done together much quicker. Furthermore, you can schedule many jobs on the cluster, which will all be pooled together and processed by the cluster. Once again, it’s an advanced setup, but I was able to backup 10 DVDs overnight.


Feb 06 2008

Crazy Shift-Drag

Tag: linux, ubuntuScott Wegner @ 9:15 pm

Ok, so I found another interesting little feature in Ubuntu by accident today. I was trying to drag a window across the room, and it would jump sporadically, moving only to the edge of another window. It was really weird, until I realized that my shift-key was stuck down. Apparently, if you hold down shift and drag a window, it’ll only move to the edges of other windows– cool for tiling a lot of programs on your screen.


Jan 30 2008

Call to Action: gDesklets

Tag: linux, software, ubuntuScott Wegner @ 10:00 pm


Ok, so I know when I say “Call to Action” I realize that my blog readership really consists of about, 3 people. So, this could really be rephrased “Hey guys, got any ideas?” Anyway, back to the post…

So one aspect that I find lacking on the Gnome desktop is widgets– Windows has them with Google Desktop or the sidebar in Vista, and Macs have them natively. But on Gnome, all we have is a program called gDesklets. Now, the problem with gDesklets, is that its inventory of widgets is so robust, it’s unusable. Because it’s open source and it’s been around forever, the repository of widgets is dated, most of them don’t work, and there’s no way to rank them based on popularity or usefulness.

Even after a few searches online, it’s hard to find any resource that has details on what the “best” gDesklet widgets are.

So here’s my “call to action”– can anyone find a list of the best gDesklet widgets available, or even a different program to replace it? I’m looking for something that’s open-source, integrates well with Ubuntu, and is easy to use. The winner will get a prize of my choosing…


Jan 18 2008

How-to: Mount a Network drive in Ubuntu

Tag: linux, ubuntuScott Wegner @ 3:16 am


Recently, one of my roommates bought an external network drive, so everyone in the house can upload their music and movies. It’s hooked right into the network through the router so it’s easy for anyone to access– pretty cool stuff. It was pretty simple to setup in Windows, but it took a little bit of research for Ubuntu. Specifically, we have Maxtor “Shared Storage II” hard-drive, and I wanted it to auto-mount each time I reboot my computer. I figured it out using the tutorial here, but the basics are below.

  1. First you will need to install the “smbfs” package. This is what we will use to mount the drive.

    sudo aptitude install smbfs

  2. We will also need a folder to mount the drive in. I used /media/public.

    sudo mkdir /media/public

  3. Then, we need to edit /etc/fstab. This is where we add all the information needed to find and mount the drive. Open /etc/fstab using the command:

    gksudo gedit /etc/fstab

    At the end of the file add the following lines:

    # Mount our network drive
    //SERVER/SHARE /MOUNT-POINT smbfs guest 0 0

    Where “SERVER” is the name of your drive on the network. This can be either a name or IP address. For example, mine was “MAXTOR”. Replace “SHARE” with the folder in the drive you’d like to mount– mine was “Public”. “MOUNT-POINT” is the directory we created earlier, such as “/media/public”. The rest of the parameters have to do with permissions, and also where you can add advanced options. For more information on the advanced preferences, see

    man mount.smbfs

  4. The final step is to tell the system to reload /etc/fstab and mount our drive. Do this with the command:

    sudo mount -a

    Then, you’re done! At this point you should be able to see the files in your drive with the command

    ls /MOUNT-POINT


Jan 07 2008

Ubuntu Tutorial of the Week

Tag: linux, ubuntuScott Wegner @ 7:00 am

In my opinion, the best part of the open source community, is that it really is a community. There is all sorts of knowledge to be gained through the many freely-available resources for Ubuntu, and all open-source alike.

This evening, I found another little gem, called the “Tutorial of the Week,” hosted on the Ubuntu forums. Each week a new tutorial is posted. Some more useful than others, but they are all high-quality. You can subscribe to the weekly tutorials by subscribing to the RSS feed for this forum topic. This week’s tutorial is about Magic SysReq keys, which are helpful when your Linux computer freezes up.


« Previous PageNext Page »