The New Gatehouse Gazette

Posted on September 1, 2010 at 11:16 am in


Well issue 14 of the Gatehouse Gazette is out. If you like Steampunk, or Diesel punk at all, you should go check it out here.

Mac OS X, It’s Not Linux, but It’s Close

Posted on August 11, 2010 at 9:43 am in

First published in Linux Journal

In the past, the Mac OS was a fairly unique entity, not having much in common with other OSes, such as Windows or UNIX, which made cross-platform work a bit convoluted. However, the advent of the latest incarnation of the Mac OS, called OS X or Darwin, provides a very comfortable alternative for Linux geeks. Because Darwin is based on BSD UNIX, it is possible to use POSIX-compliant applications on the Mac.

Apple provides a package called Xcode on its developer site. Xcode has the necessary tools for compiling programs on the Mac, and it includes a nice graphical IDE and lots of examples for developing applications for OS X. Xcode is based on the GNU toolset, providing tools like gcc, libtool, make and so on. That means, with Xcode, most command-line applications can be compiled and run on the Mac. So, a simple little hello world program:


#include <stdio.h>
#include <stdlib.h>
int main (int argc, char **argv) {
printf("Hello World\n");
}

compiles fine with gcc, giving you an executable that prints out “Hello World” on the command line. Basically, anything that is POSIX-compliant should compile and run with no issues.

Getting graphical programs to run can be a bit more involved. Mac OS X does provide an X server and all the standard development libraries you would need for a pure X11 application, like Xlib. However, none of the other standard libraries, like GTK or Qt, are available by default. You have to download, compile and install them yourself, which works fairly well, but you have to choose the correct configuration options and collect all the required dependencies. But, you shouldn’t need to go through so much pain. Two projects in active development provide some form of package management for GNU software: Fink and MacPorts. Using these, getting and installing GNU software is as easy to do as it is with most Linux distros.

The Fink Project started in 2001 and is based on the Debian package management system, so you can use the Debian package tools like dpkg, dselect and apt-get, making it familiar for Debian-based distro users. Once the base installation is done, you can start to install packages. If you like a text-based manager, use dselect (Figure 1). If you prefer a graphical manager instead, use the following command to get synaptic (Figure 2):

sudo apt-get install synaptic

Using these applications, you can install many of the packages you are familiar with in Linux. The package count, at the time of this writing, is 10,872.


Figure 1


Figure 2. synaptic Package Manager

However, not all packages are available as a binary install using these tools. For that class of packages, Fink installs them directly from source, compiling and installing on your Mac. So, for example, if you want to install gramps and do some genealogy work, execute the following:

sudo fink install gramps

Even installing from source, Fink deals well with dependency issues, because it still is based on the Debian package management system.

The MacPorts Project started in 2002 and models itself after the BSD port packaging system. Thus, you use the command to manage the packages on your system. Once you have done the base install, you can install other software packages simply by running the command:

sudo port install stellarium

Several graphical interfaces are available as well, such as Porticus. However, those typically are independent projects, as opposed to the Debian tools available in Fink. As such, their development cycle and behavior tend to be a bit more erratic and unstable than the older and more mature Debian tools. But still, they may be exactly what you’re looking for if you prefer a graphical interface. Like the Fink Project, both binary packages and source packages are available. There are 5,829 packages available in the MacPorts Project.

Both projects provide access to the full wealth of open-source applications that has been available to Linux users, and the number of packages provided by both projects continues to grow.

Once you have one, or both, of these projects installed (they will coexist on your system), you will have all the tools necessary to do your own code development. I have used anjuta (Figure 3) on my MacBook to develop some small GNOME applications. These compile and run equally well on my MacBook and my Netbook running Ubuntu. Although there isn’t binary compatibility between OS X and Linux, with source compatibility, it is (at least in theory) simply a matter of recompiling for the other system.


Figure 3. Anjuta IDE

Running Mac OS X code on Linux is not as easy as running Linux code on Mac OS X. The real stumbling block is the graphical interface called Quartz on the Mac OS. Although the kernel and most of the command-line tools have been released as open-source software, Quartz still is closed. At the time of this writing, I could not find any references to a reverse-engineered, open-source replacement for Quartz. So the only option available is running OS X inside a virtual machine. Although this is not technically running Mac applications on Linux, it does provide the ability to run OS X on a Linux box.

*Apple Developer Connection: developer.apple.com
*Open-Source Apple: www.opensource.apple.com
*Fink Project: www.finkproject.org
*MacPorts Project: www.macports.org

Aunt Jemima Buckwheat Pancakes

Posted on July 5, 2010 at 10:11 am in

Well, they seem to be gone. I remember having these pancakes as a kid. But I haven’t been able to find them anywhere for the longest time. I did finally find what purports to be the authentic recipe from Aunt Jemima.

3/4 cup of Aunt Jemima Original Recipe
1/3 cup of dark buckwheat flour
1/2 tsp of baking powder
Stir dry ingredients and add milk and egg as per package instructions.

I’ll try this as soon as I get some buckwheat flour and report back what it actually tastes like.

EDIT – This recipe turns out to taste exactly the way I remember the buckwheat pancakes. Ah, childhood memories. Give it a try.

Tags:

A Skeptical Tarot

Posted on June 25, 2010 at 3:13 pm in

I am a hard and fast materialist and skeptic. I don’t for a second believe in the supernatural. But, I am very interested in the occult. In my studies, I have looked at the Tarot in great detail and I actually use them. Before you think I’ve gone off the deep end, let me explain.

Any divination tool can be used in two ways. The first is for fortune telling. This is what you get at the carnival sideshow, when you are told that a tall and dark stranger will meet you next week. This use, in my experience, is complete bullshit and no different from the cold readers who talk to your dear departed relatives. The other use for these tools is for divination. Divination is an attempt to get at currently unknown information. Most Tarot card users claim that this information is gleaned through a paranormal source or method. Of course, I don’t believe this. But, I do believe that Tarot cards can help in divining.

Imagine you have some issue in your life that you are troubled by. You try and you try to find a solution, but for whatever reason, you can’t find one immediately. When this happens to me, I find that I get trapped in a very deep mental rut. Every time I think through the issue, my thoughts end up following the exact same thread. When this happens, I take out one of my decks of Tarot cards and do a reading. Usually, with one reading, I come to a different and more satisfying solution. But, if it isn’t magick, how does it work?

When you get stuck in a mental rut, what you need most is a way to generate new ideas. A system of divination does this by giving you a series of symbols with somewhat generic, yet still somewhat specific, meanings. You then need to take these symbols and their meanings and try to fit them into your life and the issue you are thinking about. This process forces you to make new connections between the various thoughts in your head. Any symbol system that has a set of symbols with generic meanings can be used in this way. Simply making a random selection of symbols and trying to fit them into the problem you are contemplating can open up many other possible solutions.

So, if you have a stubborn issue, give divination a try. You might be able to find a solution that comes completely out of left-field.

Evan’s Soccer Pictures

Posted on June 20, 2010 at 3:21 pm in

I just created a photo set on flickr where I’ll be posting pictures of Evan’s soccer practice and games this summer. The link is

http://www.flickr.com/photos/10731352@N05/sets/72157624317688720

I have the permissions pretty tight, so you’ll need to get a flickr account and friend me in order to see them. I’ll keep them updated each week.

EDIT: I created a new photo set. Follow this one instead

http://www.flickr.com/photos/10731352@N05/sets/72157624336400680/

Tags:

Firefly Paper Props

Posted on June 19, 2010 at 8:18 am in

Firefly is one of my all-time favourite shows. I still don’t understand why it was ever cancelled. Anyway, this flickr set was made up for Dropzone 2010. It includes thinks like liquor labels, certificates, even some newspaper pages. Very cool.




at, batch and cron

Posted on June 17, 2010 at 10:00 pm in

This was first published in Linux Journal, issue 184.

at,batch,cron – The ABC’s of doing work when nobody’s home

People have always been interested in doing more work with less effort. This drive kind of reaches its peak when work is being done, even though you aren’t actually doing anything. With Linux, you can effectively do this with the trio of programs at, batch and cron. So now your computer can be busy getting productive work done, even long after you’ve gone home. Most people have heard of cron, fewer people have heard of at, and even fewer have heard of batch. Here you’ll find out what they can do for you, and the most common options to get the most out of them.

at is actually a collection of utilities. The basic idea is that you can create queues of jobs to run on your machine at specified times. The time at runs your job is specified on the command line, and almost every time format known to man is accepted. The usual formats, like HH:MM or MM/DD/YY, are supported. The standard POSIX time format of [[CC]YY]MMDDhhmm[.SS] is also supported. You can even use words for special times, like now, noon, midnight, teatime, today or tomorrow, among others. You can also do relative dates and times. For example, you could tell at to run your job at 7PM in 3 days time by using “7PM + 3 days”.

at will listen to the standard input for the commands to run, which you finish off with a ctrl-D. You can also place all of the commands to run in a text file and tell at where to find it by using the command line option “-f filename”. at will use the current directory at the point of invocation as the working directory.

By default, at will dump all of your jobs into one queue named “a”. But you don’t need to stay in that one little bucket. You can group your jobs into a number of queues quite easily. All you need to do is add the option “-q x” to the at command, where “x” is a letter. This means that you can group your jobs into 52 queues (a-z and A-Z). This lets you use some organization in managing all of this after hours work. Queues with higher letters will run with a higher niceness. The special queue “=” is reserved for jobs currently running.

So once you’ve submitted a bunch of jobs, how do you manage them? The command atq will print out the list of your upcoming jobs. The output of the list is: job ID, date, hour, queue and username. If you’ve broken up your jobs into multiple queues, you can get the list of each queue individually by using the option “-q x” again. If you change your mind, you can delete a job from the queue by using the command “atrm x”, where x is the job ID.

Now, what happens if you don’t want to overload your box? Using at, your scheduled job will run at the assigned time regardless of what else may be happening. Ideally, you would want your scheduled jobs to run only when they won’t interfere with other work. This is where the command batch comes in. batch behaves the same way at does, but will only run the job once the system load drops below a certain value (usually 1.5). You can change this value when atd starts up. By using the command line option “-l xx”, you can tell batch not to run unless the load is below the value “xx”. Also, batch defaults to putting your jobs into the queue “b”.

These tools are great for single runs of jobs, but what happens if you have a recurring job which needs to run on some sort of schedule? This is where our last command, cron, comes in. As a user, you actually don’t run cron. You instead run the command crontab, which lets you edit the list of jobs that cron will run for you. Your crontab entries are lines containing a time specification, and a command to execute. For example, you might have a backup program running at 1AM each evening:

0 1 * * * backup_prog

cron will accept a wide variety of time specifications. The fields available for your crontab entries include

field allowed values
minute 0-59
hour 0-23
day of month 1-31
month 1-12
day of week 0-7

Using these fields and values, we can use them directly, use groups of values separated by commas, use ranges of values, or use an asterix to represent any value. You can also use special values

string meaning
@reboot run once, at startup
@yearly run once a year (0 0 1 1 *)
@annually same as @yearly
@monthly run once a month (0 0 1 * *)
@weekly run once a week (0 0 * * 0)
@daily run once a day (0 0 * * *)
@midnight same as @daily
@hourly run once an hour (0 * * * *)

Now that you have these three utilities under your belt, you can schedule those backups to run automatically, or get a long compile to start after you’ve gone home, or get your machine to keep using up any idle cycles. So go out and get lots of work done, even when nobody is home.

No book deal

Posted on June 16, 2010 at 9:46 pm in

I just got a call from an editor with O’Reilly. I suggested a book idea. Unfortunately, they don’t think that there is a big enough market to make the cost of a production run worth it. And I have to agree with them. But I still think that this is an idea that is needed. So this is what I’m proposing. I’m going to start writing up the chapters and posting them here. After that, I think I’ll just go ahead and publish it myself through Lulu.com. We’ll see if people actually find it and get any use out of these postings.

Using bc for math at the command line

Posted on June 3, 2010 at 4:00 pm in

This first appeared in Linux Journal, some time ago.

bc – When integers aren’t enough

Most people have the need to do some kind of math when they are using a computer. In shell scripts, you can make integer calculations by using functionality in the shell itself. But what if this isn’t enough? Luckily the POSIX standard includes a very useful command line utility called bc. With this you can do arbitrary precision arithmetic. Actually, it is a complete, C-like, language that can do some pretty sophisticated programming, supporting variables and functions.

In bc, numbers are all represented internally as a decimal number. They have a length which is the total number of digits, and a scale which is the number of decimal spaces. You can find these values by using the builtin functions length() and scale(). For example, the number 10.23 would have a length of 4 and a scale of 2. The variable “scale” holds the number of decimal places to keep when internal functions are executed. The default value is 0. bc supports all number bases from 2 to 16, with base-10 being the default. The input and output base of numbers can be set by using the variables ibase and obase. All of the basic mathematical operations are supported in bc. You can multiply, divide, add, subtract, do mod and exponentiation. There are all of the standard comparison operations, too. Less than, less than or equal to, greater than, greater than or equal to, equal to and not equal to all give results of 0 for false and 1 for true. This is very useful in the conditional statements available in bc.

bc can be used this in shell scripts or on the command line as a very effective calculator. It will read from a list of files given on the command line, or read from standard input. On the command line, expressions can simply echoed through a pipe to bc.

echo “1+1″ | bc

will give the answer of 2. As a more complex example, the sine of 5 can be assigned to a shell variable with the following

RESULT=`echo s(5) | bc -l`

The “-l” command line option tells bc to load the math library, giving access to the trigonometric functions.

As a bit of a contrived example, say that there are two values and we need to find out which one has a larger sine. With the math library and the builtin comparison operations, this can be determined by typing

echo “s(5) < s(10)" | bc -l

The result 1 gets printed out on standard output, verifying that the sine of 5 is less then the sine of 10. bc can be made to print out a text string telling the user whether the result is true or false with the following

echo 'if (s(5) < s(10)) print "true\n" else print "false\n"' | bc -l

This prints out the word true. If this string is to be stored in a variable, the newline characters would be removed from the executable line. This value can then be used later on in a shell script by saving it to a shell variable.

What if we have a data file of input values and we want to apply some function to them? Say we need to calculate the logarithm base 10 of each value and dump it into another file? The following example take a list of the first 10 numbers, calculates the logarithm base 10 of each number and writes the value into the file output.lst

LIST="0 1 2 3 4 5 6 7 8 9"
for INPUT in $LIST
do
echo "l($INPUT)/l(10)" | bc -l >>output.lst
done

These examples have already done some useful work, but what if the requirements are more robust? Does this necessitate a move to a heavy weight math program, like Mathematica or Maple? Not necessarily. With bc, there is the possibility of creating and using functions to make more complicated calculations. Even recursive functions can be written, like in this example to calculate a factorial

define f (x) {
if (x <= 1) return (1);
return (f(x-1) * x);
}
print “Factorial:”; factorial = read();
print f(factorial); print “\n”;
quit

This can be dumped into a file called “fact.bc” and run through bc to get the factorial of some number by executing

bc fact.bc

This script will ask the user for a number and then will find the factorial. This can be used without interaction by simply feeding the number in to standard input with a pipe

echo 10 | bc fact.bc

This will print out the factorial of 10 (3628800) to standard output. But how fast can such a program be? For a variety of values run on a generic laptop, the following times were measured:

10 0.004s
100 0.004s
1000 0.028s
10000 3.099s

These times were averaged over three runs to account for varying system load. This seems more than fast enough to be useful for a lot of heavy work.

For a more science-y example, the following bc script can be used to find how long it takes for an object to fall for a series of heights.

define t(h) {
g = 9.81;
return (sqrt(2 * h / g));
}

Now there is no excuse for abandoning a shell script simply because it can’t handle some mathematical problem. With bc, a lot of really useful work can be done straight from the command line. Go forth and enumerate.

New video blog

Posted on May 17, 2010 at 9:32 pm in

I’ve been listening to the Skeptoid podcast for a long time now, and I’ve been a big fan. Well now you can get your skeptical video fix, too. A sibling vodcast called inFactVideo is available. I’ve watched the first few and it is now in my regular list of downloads. Have a look and see what you think.

Top