Save the Internet; delete a Zwinky.

:: Next Page >>

A Bash script to force Image Magick to use zero-indexing when it converts GIF to JPG

Date/Time Permalink: 05/14/13 12:33:38 pm
Category: HOWTOs and Guides

I can't believe this hasn't been solved somewhere before, but I was converting a .gif to individual image frames for a project when I discovered this behavior.

UPDATE: Guess what??? image magick CAN output zero-padded files, just by doing:

% > convert mygif.gif mygif_%05d.jpg

no wonder I couldn't find it by Googling. I was looking for an option switch. But you'd still need to find out how many zero-spaces to use for individual gifs for each case. My thing is, I hate remembering fifty commands when I can name a script after what I want it to do and forget about it.

We now return you to my folly, which you can still adapt for programs which don't zero-pad:

The command:
%> convert mygif.gif mygif.jpg

What it does with the file names:


What it should do with the file names:


That's because not all programs that are going to handle these image frames know to ignore Bash-file-sorting order and substitute logical numeric file-sorting.

And I'm searching all over the place, but there doesn't seem to be an option in convert to force this file-naming convention, or else I'm not searching for it right. Anyway, this script whacks the file names into shape:


#  Apparently when you call image magick to convert gif to jpg
#    it doesn't use zero-indexing to ensure the files list
#    in order for each program.
#  So... ouch!

for FILE in $(ls *.gif)
    DIGITS=$(identify $FILE | wc -l | wc -c)
    convert $FILE ${FILE%gif}jpg
      for JFILE in $(ls *.jpg)
        NUM=$(echo $JFILE | cut -d- -f2 | cut -d. -f1)
        NEWNUM=$(printf $PSTRING $NUM)
        mv $JFILE $(echo $JFILE | sed $SEDLINE)

exit 0

You'll note the convoluted series of variable abuse. That's because of the various quirks of the individual text-mode tools.

First, $DIGITS finds out how many zeros to index for the file names. Since you want this to work on any gif with any number of frames, we have to use Image Magick's identify command on the gif, pipe it through wc -l to count the frames, then use wc -c to find out how many digits that number is. As you can see, we end up with one superfluous zero here, but the hell with it at this point, it does the job.

I also have to extract the number from the file name, and drop it into the $NUM variable.

In a perfect world, I could just expect to say something like:

% > mv $FILE $(echo $FILE | sed 's/-$NUM\./-printf "%0$DIGITSd" $1./g')

But no.

Second, sed won't take a mixed variable string like "s/$PATTERN1/$PATTERN2/g". So you have to put the sed argument in a variable.

But we're zero-indexing here, and the only tool I know of to do that is printf, and guess what? printf also won't take Bash variables in its argument string! So now you have to make $PSTRING to build the argument to printf so you can make $SEDSTRING to build the argument to sed...

So, is that done now? I'm crazy for doing it this way, aren't I?

It does work. If you use it, be sure to use it in its' own special little directory so it doesn't wantonly mess with other unrelated files...

Follow me on Twitter for an update every time this blog gets a post.
Stumble it Reddit this share on Facebook

Script of the Day: Random Wallpaper Setter

Date/Time Permalink: 10/08/12 02:44:56 pm
Category: HOWTOs and Guides

Y'know, I get tired sometimes of dealing with all the different screens. Between several cell phones, a laptop, and several desktop PCs, I have about eight different devices that want their default screen space filled with something and eight different methods to use for filling them. Bah, I said, and also there's still no default mechanism in my favorite desktop, Fluxbox, for setting the wallpaper from the menu. Furthermore, for those times when an image doesn't scale easily onto screen dimensions, there's also no easy way to set the surrounding fill color.

This is, Which I load into my menu system and launch with one click. It picks a random file out of my "graphics/Walls" directory, slaps it onto a full-screen background (automatically optimized for whatever screen it's running on) of a neutral color picked from the image itself (composing a new image in the process), and slaps it onto the screen. And then I get on with my life...


# Step 1 - grab random file
FILE=$(ls ~/graphics/Walls/ | shuf -n1)
convert ~/graphics/Walls/$FILE ~/.temp.png

# Step 2 - Determine fill color
FILLCOLOR=$(convert ~/.temp.png -scale 1x1\! -format '%[pixel:u]' info:-)

# Step 3 - Determine the geometry of the root window
GEOM=$(xwininfo -root | grep -A 1 Width)
GEOMX=$(echo $GEOM | awk '{print $2}')
GEOMY=$(echo $GEOM | awk '{print $4}')

# Step 4 - Make a new background image with the fill color and root window dimensions
convert -size $SIZE xc:$FILLCOLOR ~/.current_wallpaper.png
convert ~/.temp.png -resize $SIZE\> ~/.temp.png

# Step 5 - Combine wallpaper and background and display
composite -gravity center ~/.temp.png ~/.current_wallpaper.png ~/.current_wallpaper.png
rm ~/.temp.png
display -window root ~/.current_wallpaper.png

exit 0

Ugly as grandma Moses, isn't it? I expect the usual commenters pointing out that I do everything the hard way.

What we're doing in step 2, is we're taking the wallpaper image and making a new temporary file where we scale that wallpaper down to a single pixel - this will produce the average color from the image. Then use Image Magick's 'info' feature to read the RGB of that one-pixel image, and that becomes the background color. The rest is just a few 'combine' statements and use of the little-seen GNU 'shuf' command, handy for whenever you want a random file from a directory.

As long as a system has X11, Image Magick, and GNU standard utilities, it should work. Feel free to snarf bits and bobs for your own uses.

Follow me on Twitter for an update every time this blog gets a post.
Stumble it Reddit this share on Facebook

Using Bash To Solve A Brain Teaser

Date/Time Permalink: 02/21/12 11:01:57 am
Category: HOWTOs and Guides

So we have this puzzle, expressed as:


...where each letter stands for a digit. So in other words, "RUT" is the square root of "CAREER". But what are the digits?

Obviously, we need a three-digit number whose square is a six-digit number. "317" is the lowest number that is the square root of a six-digit number, and the three-digit number can go as high as 999. So far our Bash line looks like this:

for N in $(echo {317..999}); do S=$(($N*$N)) && echo $N, $S; done

Our answer is somewhere in that column. Now we see another clue, that the first digit of the multiplier is the same as the third and sixth digits of the product. We know we can take an index slice from a variable, such as getting the first digit with ${N:0:1} (remembering that variable indexing in Bash starts at zero). So now we can create a conditional filter which only prints the numbers if the first digit of the multiplier is the same as the third and sixth digits of the product. We'll have to break that down into two separate tests.

First let's filter it down to products whose third and sixth digit are the same:

for N in $(echo {317..999}); do S=$(($N*$N)) && if [ ${S:2:1} = ${S:5:1} ]; then echo $N, $S; fi; done

Piping that into wc -l says that only 94 lines printed, so we know we're narrowing it down. Now test if the first digit of the multiplier is the same as the third digit of the product:

for N in $(echo {317..999}); do S=$(($N*$N)) && if [ ${S:2:1} = ${S:5:1} ]; then if [ ${N:0:1} = ${S:2:1} ]; then echo $N, $S; fi; fi; done

So we had nested conditionals there. Don't pass out on me, we're almost there. The above command line pumps out this column:

418, 174724
452, 204304
505, 255025
515, 265225
525, 275625
614, 376996
676, 456976
927, 859329
943, 889249

From here, we can get it by eyeball. We also know from "RUT" and "CAREER" that the fourth and fifth digits of the product have to be the same digit. We could include a third nested test like so:

for N in $(echo {317..999}); do S=$(($N*$N)) && if [ ${S:2:1} = ${S:5:1} ]; then if [ ${N:0:1} = ${S:2:1} ]; then if [ ${S:3:1} = ${S:4:1} ]; then echo $N, $S; fi; fi; fi; done

Great Scott! We're down to two possible numbers:

515, 265225
614, 376996

We have one more clue, that the first and third digits of the multiplier must be different from each other. We can clearly see that that disqualifies 515, leaving "RUT" = 614 and CAREER = 376966, but we're here to do it in Bash:

for N in $(echo {317..999}); do S=$(($N*$N)) && if [ ${S:2:1} = ${S:5:1} ]; then if [ ${N:0:1} = ${S:2:1} ]; then if [ ${S:3:1} = ${S:4:1} ]; then if [ ${N:0:1} != ${N:2:1} ]; then echo $N, $S; fi; fi; fi; fi; done

That gave us the correct answer.

So, what have we learned in this example?

  • How to list a sequence of numbers. (echo {X..Y})
  • Shell math. (X=$(($Y*$Z)))
  • How to do a one-liner loop. (for X in $(command); do thing; done)
  • How to take a piece of a variable (${X:0:1})
  • How to do a one-liner conditional test. (if [ $X = $Y ]; then do thing; done)
  • How to do a negated one-liner conditional test. (if [ $X != $Y ]; then do thing; done)
  • That we can nest this all together!

Good thing this problem comes up all the time, isn't it?

Follow me on Twitter for an update every time this blog gets a post.
Stumble it Reddit this share on Facebook

Penguin Pete On Writing

Date/Time Permalink: 04/17/11 11:36:23 am
Category: HOWTOs and Guides

All over the web I see these forums for new writers. Websites for the writing trade, message boards, and so on. I see a lot of young authors trying out fiction, trying to be the next Stephenie Meyer (talk about setting your goals low), asking each other for advice, "critique my work," does anybody know where I can find a daily writing prompt? Oh, and playing these little blog comment games and what, oh what, shall we ever do about this awful angsty writer's block?

Ah, God. I see a lot of young kids struggling every which way to get out of that Writer's Workshop mentality.

Maybe I can help.

If you've checked out my 'about me' page (it's over there in the cobweb-infested sidebar), you'll know that my career includes a lot of manual, menial labor. I'm not kidding that I've worked construction, and I mean that that includes taking a shovel in hand and digging a few ditches, and furthermore that meant doing so in the Mohave Desert in Arizona in 120-degree August heat. I've done some real grunt labor in my time - one of my earliest jobs was moving appliances around in a warehouse. No, not with a forklift and pallet-jack, I mean by shoving them by hand. I was fourteen at the time.

I'm telling you this so you know, I've since retired from the world of jobs to start my second life having a career. That mostly consists of writing.

And I feel no different when writing an article than I do when digging a ditch.

If people ask me what I do, I say "I write" and I use the exact same tone as when I had to answer that I dug ditches. I can write in my office, or in bed, or watching TV, or riding in the car, or with one hand while feeding a baby or brushing a cat with the other. I can do it alone or in a crowd. It's no special trick to me.

I don't attach honor to it, or prestige, or wonder, or the allure of being an artiste. I don't gaze in my navel and agonize over the cruelty of my muse. I don't need a special writer's hat or a magic pencil or a bunch of cherubs scattering rose petals in my path. I don't say a prayer and do a ritual and genuflect before the altar of Homer or anybody. Oh, sure, if somebody wants to hear me wax eloquent with a whole pile of that scholarly horsecrap, yeah, I can pontificate on ze arte along with every other pretentious Ivy League monkey out there.

But really, writing to me is, and always will be, an activity as mundane as wiping my ass.

Am I great? No.

Will I ever be famous? Meh, doubtful.

Will I ever be rich? Meh, probably not, maybe I'll get lucky.

Will I have immortality through my work and be read by future generations... Oh please! I'm one ant in a hill.

It's a living though.

When somebody praises my work, I grin, glad you liked it. When somebody criticizes my work, I don't grin, that's a shame, I'll try it different next time. I've never met the thing that anybody had to say about my work that didn't wear off of me in about a minute.

I'm not feeling about it any way or the other, you see? That way I don't overthink it; I'm not paralyzed with indecision because the decisions I make aren't that important anyway. If I write crap, my life isn't over. If I write solid gold, I still can't retire.

So there's this detachment, this drone-like aloofness, as I approach the blank page just like a blank patch of ground that needs a sewer line buried in it. Writing, what, this is hard for people? Ha ha ha! I'm sitting indoors on this comfortable chair pushing these little buttons on a box! What's hard about this?

I dunno, I have the feeling that that perspective would help a lot more young aspiring writers just get going and, you know... go!

is Penguin Pete a wizard?

Follow me on Twitter for an update every time this blog gets a post.
Stumble it Reddit this share on Facebook

A Quick Guide to Lynx

Date/Time Permalink: 03/29/10 07:12:14 pm
Category: HOWTOs and Guides

Who on Earth would bother to use a text-only web browser in 2010? Actually, it's one of the important tools in the accessibility toolkit for the disabled, being easily coupled with a screen reader. And OK, for those times when you have graphics-card problems. But when else? I could go on all day about the times when Lynx comes in handy:

  • Best for viewing hyperactive websites. No Flash, no Javascript, no blinking, flashing ads, no bother.
  • Best for fast browsing. Sometimes its important to get in, get the key piece of data you need, and get out.
  • Browsing a guide when you're playing a game. The game runs fullscreen, but you're stuck, can't save, and need to look up the game guide? Just Ctrl-Alt-F2 to the console and look it up in Lynx.
  • Can be scripted. For instance, to search for the term "bash script", "lynx -dump ''" will dump the results page right to the command line. Use this power only for good and not evil.
  • Best to check for web page errors. What counts for search engine spiders is how they see the text. Viewing your site in Lynx tells you exactly what the search engine sees.

Now then, Lynx out of the box is somewhat annoying. You can change its default behavior in "lynx.cfg", a file found lurking in places like /etc/lynx-cur/lynx.cfg. You can either copy this to your home directory for just one user's preferences, or go root and edit it for the whole system.

lynx.cfg is huge, but well-documented. Here's the changes I find most useful; these are a matter of preference, so alter them to taste:

(This is your 'home page', what Lynx goes to automatically on start-up.)

(This can be your alternate home page, the page you go to when you hit 'I' for index.)

(This sets the directory to save all downloaded files to.)

(Having the cursor blinking and visible helps with navigating through a document.)

(Interesting mouse usage and scrolling options, for the keyboard-averse. A curses-drawn scrollbar and arrow set appears to the right; if you have enabled console-mouse support, this will work just like a GUI. Although it's still slower than just using the keyboard.)

(This will make it quit bothering you with all those micromanaging cookie details!)

(See what I did there? I put a dot in front of the file so it's hidden. No need to look at it in my home directory.)

(This will make it work more like a normal browser, eliminating the two lines of help, and showing the current page or link URL in the status bar.)

By the way, you use the cursor-arrow keys to move the pointer around (the cursor will hop from hyperlink to hyperlink). The number-pad's 'Ins' and 'del' scrolls the whole page up and down.

Ancient Chinee Secret!

Follow me on Twitter for an update every time this blog gets a post.
Stumble it Reddit this share on Facebook

What Programming Language Should You Learn?

Date/Time Permalink: 01/06/10 11:04:51 am
Category: HOWTOs and Guides

I'm going to attempt to answer the number-one most common technology question on the web, and hopefully do it so I can just link people here. Wish me luck, I'll need it!

The answer is different for everyone!

For me, I learn for learning's sake. Literally, I have never encountered a language or computing technology that I did not want to learn. I just started with my first computer, a Commodore VIC-20 in my teens, and was thrilled to find that it had BASIC and a BASIC manual. That was day one. Since then I've just snarfed up whatever I could find. So far that's: C, C++, assembly, Lisp, Tcl/Tk, Bash, Awk, Python, Javascript, Actionscript, PHP, SQL, POVRay (used for rendering 3D graphics), and I'm losing track from there.

Being pro-learning is the only skill you really need!

That's the most important thing. Knowing one language just isn't any good. Knowing five is a little better. They get easier as you go along; I'm at a point where I can go from a cold start to coding a simple application in just one week on virtually any language. I just have a passion for technology and soak up everything I can get my hands on, and worry how to turn it into money later!

There's no such thing as "bad learning."

In 20 years watching the field, I've become convinced that every skill eventually becomes marketable. I never thought that somebody could make money being a Wordpress theme designer, a Twitter background theme artist, making ringtones for mobile phones, or setting up eBay storefronts, but there are all thriving cottage industries right now. Who knows what five years from now will bring? Professional Digg commenters? RSS publishing services? Mobile phone address book organizers? I've learned to never say never.

OK, but what do I learn for a job?

Well, I'll take a stab at it; here's the languages that currently seem to be going somewhere jobwise:

Javascript and AJAX: Big, big, big right now. I don't know if there's a new Web 2.0 bubble lurking or not, but it seems like there's jobs flying around for anybody who can build an AJAX site. It's made out of Javascript and XML, with a side helping of HTML and CSS. All you need is a text editor and a web browser.

PHP: Especially on the OS-Commerce backend. Shopping cart apps, game sites (the kind with subscribers), all kinds of web-based commerce. PHP is one cruddy language - it's ugly and clunky - and it's a smash hit. On Linux, I install PHP and run scripts right from the command line, saving the output as HTML. Or you can get a cheap web host and test server apps live. Job search keyword is LAMP, for "Linux Apache MySQL PHP"

C/C++: Still the application standard. It is simply never going away. On Linux, gcc comes with the distro, and on Windows there's a nice free IDE called Bloodshed Software Dev C++, if my memory serves.

Flash: Still big. Get a good Flash game online, and the world will drown you in ad revenue. Webmasters are always out to hire a Flash webmonkey. Requires some understanding of graphic design work as well. On my site, I stump a lot for SWFTools and the swfc compiler, with a lot of demos in the Flash category. I also hear good things about HaXe, but haven't tried it.

Python/ Ruby/ Lisp: Not much on the job front, but it's so fun to learn and use for yourself, that any work you get out of it is a bonus. The high-end Silicon Valley start-up type places will be more likely to hire in this category.

What about specific jobs?

Video games on the computer usually revolve around C, C++, and the whole C family. If not C, then assembly. Web server-side development is mostly PHP, some Perl. Web browser-side development is Javascript, AJAX, and Flash, with a lot of markup languages (HTML, XHTML, CSS, XML). Desktop applications are a crap-shoot; maybe Python, maybe Ruby, maybe Java, who knows? System administrators need shell scripting skills, in Bash and Perl. Big business mainframes are still crunching along with COBOL, God help us all.

Why should you learn multiple languages?

Here's what I mean about all learning is good learning: Flash's Actionscript is basically Ecmascript, which is also what Javascript comes from. Once you learn Javascript, you already know most of Actionscript. Javascript is related to Java, which is derived from C, so there's a link there. PHP has a very C-like syntax, so once you learn C or C++, PHP will be almost subconsciously easy to learn. Python and Ruby both are related, in a round-about way, to Lisp. When you come to Lisp from the C-side of programming, your mind will be blown. Get a free Emacs install and a manual and lose your head for a couple of weeks on the built-in ELisp interpreter inside Emacs. Now when you come to Python, Ruby, and other languages related to them, they'll make more sense.

A language can help you even if you don't get hired to program in it.

Now I, myself, make most of my freelance living from writing and graphics, so I'm really not the one to ask about making a living purely from writing code. The best work I've gotten in code is Flash stuff. If you're familiar with my Flash category on this blog, you know that I have a whole Flash toolchain built out of open source, with POVRay for 3D graphics, Bash scripting (Linux command line) to assemble animations, and SWFTools to compile the Flash. And now I'm writing my own POVRay frontend in Python out of frustration with the other POVRay frontends out there - this is an example of how knowing a language helps me.

I have yet to this day get paid one penny for Python code - directly! But my own tools tend to be either Bash or Python, which helps me do the other things I get paid money for. For another example, I have a lot of Bash scripts I've written over the years to convert or handle different document formats, so that saves me time on my writing work.

What is the easiest to learn?

This question is wrong. If you're asking it, I'm sorry, but my advice is to forget about programming. There is no "easy." You learn or you do not learn.

Well, which one is the most fun?

That's pretty subjective. Answers will vary, but if you just want a toy to play with for your own uses, Python and Ruby are both widely considered "fun". BASIC used to be, but it's outdated now.

You seem to lean heavy towards open source systems. What about Windows and Mac?

Sorry, check the site - it's "Penguin Pete's" as in "Tux, the Linux penguin, the mascot of Linux!" Call me biased, but for learning programming you can't beat Linux. The system's free, the tutorials are free, the documentation is free. Linux is built for learning.

I don't like your answer!

Remember, I said this is the number-one most common technology question on the web! Really, I swear on my grandmother's grave, you are not the very first person to have asked! Here are some search links for the other 348 million answers:

Keep the change

Follow me on Twitter for an update every time this blog gets a post.
Stumble it Reddit this share on Facebook

I For One Welcome Our New Google Overlords

Date/Time Permalink: 07/08/09 03:36:29 am
Category: HOWTOs and Guides

OK, Google, it's about time you stepped up to the pinata and took a swing. You're finally launching your own operating system.

Maybe at last the proprietary monopoly will be shattered.

  • I had hopes when Apple went with a BSD core. Apple let me down.
  • I had hopes for the ReactOS project. They crawled off and died somewhere.
  • I had hopes for Ubuntu. It doesn't want to play ball.
  • I had hopes for Sun Open Solaris. They wimped out.
  • I had hopes for Oracle when they adopted their own Linux. They're asleep.
  • I had bigger hopes when Oracle bought Sun. Nope, they're still asleep.

So it's Google's turn. I'm 0.1% happier than I was a minute ago. Now, Google, here is what you can do:


Here is my guide to Not Screwing It Up:


Plaster it! Saturate it! Find a new Billy Mays and scream it in late-night infomercials! As pitiful and pathetic as Microsoft's sorry excuse for marketing is, I expect the 26th and 27th richest people on the planet to be able to show them how it's done.

Do not mention Linux!

Normally, this is the kind of heresy that I would cut out my tongue for, but this time it's the right thing to do. This has nothing to do with technology; this is about what is in people's heads. Average consumers, if they've heard of Linux at all, have been force-fed 20 years of brainwashing FUD by Microsoft to the point where Linux = evil. Keep your brand name (Even John McCain praised "the Google"!) and "Chrome", that's enough. Wait until you've conquered the market, then wait ten more years, then if you want you can go "Surprise! You've been using Linux!" That's fine.

(And to my beloved brethren and sistren in the Linux community: put your ego away. This isn't about Linux getting desktop recognition, this is about breaking the global dictatorship. Details can come later, if ever.)

Expect trouble in the US!

You will be thwarted. Microsoft owns too much of the US government for you not to be harassed. So don't worry about the US market. Remember, the Metric system caught on everywhere else but the US, too. The US will be your toughest market, even without bought-off senators and officials throwing themselves in your way like salmon.

Ignore the siren song of asstroturfers!

Don't be stupid like a few other open source projects and listen to the thousand flaming trolls in a comment page - they are paid to derail you. Google, you have done very little wrong so far; what market share you've acquired, you've earned fair and square. Don't start doubting yourself now.

Fight for OEM!

On the shelf, installed systems. For sale. In stores. Commercial stores. Chain stores. Big Name Retailers.

Gooood luck, Google! No company in the history of business has had the battle on its hands that you have on your hands today.

If all goes well, within my lifetime I should be able to tell people on the street that I use something besides Microsoft and not have them look at me like I just beamed down from Mars sporting two heads.

That's all I really ask in life.

PS Yeah, I know, some of the assertions and assumptions I made here don't stand without citations, and they're not getting them. Being pedantic right now is a big waste of time.

FOSS is Freedom!

Follow me on Twitter for an update every time this blog gets a post.
Stumble it Reddit this share on Facebook

How to Talk About FOSS Without Sounding Like a Total Dweeb

Date/Time Permalink: 12/09/08 11:55:13 am
Category: HOWTOs and Guides

If you run Linux, BSD, or any other Free and Open Source system, you know that every time you open your mouth about it in day-to-day life, you usually have to stop and explain what it means. Outside your office or school, there's everyday-type folks who have no idea that such a thing exists, and they'll all have to be taught, one person at a time.

Through the years, I've sought to balance my desire to spread technology freedom everywhere I go with the urge not to make a roaring bore out of myself. For those of you who ask things like, "How do I tell my boss about Linux?" or "How do I recommend a Linux solution to my kid's school?", here's some rough rules of thumb I've carved out over the years which allow the maximum teaching with the minimum amount of pain - for both listener and speaker.

#1. Eliminate computer jargon. I've tried every other way, and it doesn't work. No matter how simply you talk, there will be terms that somebody, somewhere, doesn't understand. Even basic concepts like the CPU, RAM, and the difference between a CD-ROM and a DVD will leave some people far behind. So practice removing as much computer jargon from your discussion of computers as possible. This is a goal to be striven for, without ever being reached. Every computer-specific term you have to use, stop and ask if the listener knows what that means. Make it obvious that you're doing so out of consideration.

#2. Use everyday analogies. We're all familiar with car analogies applied to computer concepts - they're a stand-alone meme on places like Slashdot. To explain why open source is important, I'll say that you wouldn't buy a car with the hood welded shut. To explain the importance of technology freedom, I'll point out that the TV manufacturer doesn't try to control what programs you can watch. To explain the community development model, I'll compare it to a food co-op, a worker's union, or a democratic government.

#3. Appeal to human rights. This never fails to catch the ear of the listener, but I never see anybody online mentioning it. Point it out to the listener: YOU own Linux! Right now! It belongs to you as much as it does anyone else. The same goes for all of GNU-licensed software. You have an inalienable right to control the technology in your life. You have a right to use the hardware that you paid your hard-earned money for, in whatever way you see fit. You have just as much say over what lines of code run on your computer as you do over what ingredients go into your food.

#4. Be even-handed. Lest we stray into "wake up, sheeple!" territory, we should be careful not to be radicals about it. There are other important issues in the world, too. And I don't - and never will - say that FOSS is for everyone. I think healthy eating is good for everyone, too, but I know there are some people who will live on junk food regardless of how many nutritional surveys you read out loud to them.

#5. Demonstrate it. By all means, let people look over your shoulder while you work on your laptop. The most interest I've ever gotten from people is when they see actual FOSS software in action. Just quietly go about your business, and answer the inevitable "Cool! How'd you do that?" questions.

#6. Mention who uses it. There's a dangerous idea floating around out there that Free Software is populated by a community of hippies and flakes, and the hippies and flakes who claim to speak for us will never shut up, so that misconception just has to be tirelessly fought against. Point out places like IBM, Wall Street, Google, Hollywood production studios, and of course the backbone of the Internet. Yes, people in suits and ties with jobs use it; it is part of capitalism! Not outside of it!

#7. Unix-like systems have a heritage to brag about - so brag! The first world-wide web server was a Unix-based system, the first web browser ran on Unix, supercomputers run Unix and often FOSS Unix at that, Linux is embedded in smartphones and PDAs and GPSs. Not just some - but all of the innovation in computers comes from Free and Open-Source Software. And yes, I stand ready to defend that bold pronouncement.

#8. If they're still listening, now you can list the benefits. Here we can cut in the usual spiel delivered online: it's more secure, it's more stable, it's often free-of-charge, etc.

#9. Know when to shut up. Sure, you're passionate about FOSS, but don't let it make you a boring drone. Don't take yourself too seriously, and if the listener shows signs of closing their minds to the concepts you're explaining or seems to not be following it, just let the conversation meander elsewhere, with the assurance that if they want to know more about it later, you'll be happy to explain more. It helps to have your own website to point people to! My average pitch for Linux is down to maybe ten minutes, not allowing for questions and conversational tangents.

Drive-thru Blogging

Follow me on Twitter for an update every time this blog gets a post.
Stumble it Reddit this share on Facebook

Argh! Microsoft Notepad CRLF! Argh!

Date/Time Permalink: 08/25/08 08:27:53 pm
Category: HOWTOs and Guides

GNU/Linux/Unix users, and even Mac users, hate Microsoft Notepad. If you must use Windows, could you at least replace Notepad with - I don't know - anything else at all? Because Microsoft Notepad is to text what Internet Explorer is to HTML.

See, Notepad has the line-break formatting bug. If you write a text file on anything but Windows and send it to a Microsoft user and they open it in Notepad, all your paragraph line breaks (where you hit the 'return/enter' key) will not show up, resulting in a great big blob of text, or, if they're viewing with word-wrap turned off, a single loooooong line of text where you have to keep scrolling sideways.

Microsoft Wordpad? Doesn't have that bug. It's fine with Mac/Unix standard line breaks. Microsoft Word? Also doesn't have that bug. It can handle standard line breaks, too. The dozens of FOSS or proprietary third-party text editors out there for Windows? Also don't have that bug. Even DOS-bloody-EDIT doesn't have that bug, and it has more features and is faster than Notepad, too. So of course, every Microsoft user wants to use Notepad, and only Notepad.

When you receive a text file from a Microsoft user who wrote it in Notepad, and open it in most plain text editors, the line breaks will have an extra character interpreted as '^M'. And don't get me started on when somebody cuts and pastes Internet content into Notepad to save 'n' send. You get kind of an ASCII salad that isn't quite text and isn't quite binary. Again, these kinds of problems just don't show up with any other editors on the Windows platform that I've seen.

Let's try to understand what's going on here, setting down once and for all the tedious historical details of why this happens. This is going to hurt me as much as it hurts you. Here's some prerequisite reading.

Once upon a time, there were these things called typewriters. You know that prerequisite reading I just sent you off to do? You didn't do it, did you? Well, the "CR" (hex: 0x000D) character stands for "carriage return" and the "LF" (hex: 0x000A) stands for "line feed". That maps to a manual typewriter. They worked like this:

manual typewriter

You'd start a new paragraph by feeding in the paper and then - with your left hand - shoving the carriage (the part on top that has the paper) all the way to the right so the keys will be hitting the spot on the far left first. Then as you typed, the carriage would advance one space at a time. When it got all the way to the right (usually it went "ding!"), you'd have to push that carriage back again, and if you didn't also hit the line-feed lever, you'd start typing over the same line. So the line-feed lever is right there, mounted in the same spot you'd use to push the carriage back anyway, and you could combine both motions.

Sometimes, you'd want the actions to be separate. You'd want to skip down several lines, for instance. Sometimes you'd want to return the carriage without advancing the line, such as when you had to retype a place where you made a mistake and had to use Wite-Out, and then when it dried you had to type back over it. This was how we deleted.

Don't even ask how we did spreadsheets. The last remains of your sanity would swirl down the drain.

Anyway, the modern computer character system has all these left-over concepts from the manual typewriter (and later teletypes and printers), despite the fact that they're all appendices that we'd be better off evolving out of. That "CAPS LOCK" key, for instance, is next to the shift key because on the manual typewriter it was a "SHIFT LOCK", a physical lever lock which kept the shift key pressed down.

That's also why the backspace key is at the top of the keyboard, because it was hooked up to the carriage and physically moved it back to the right. Theoretically, you could do a carriage return by hitting the backspace key a bunch of times, if you were really mad at your finger and wanted to make it suffer.

The CR/LF ASCII characters are the modern control characters for these 'carriage return' and 'line feed' actions. Only we don't need to separate them any more, because we use the arrow keys/cursor keys to navigate within the document. And the rest of the world said, "Thank God! We have computers now, so we can just make the 'enter' key send a single, all-purpose character that advances to the next line of the virtual document and returns to the far left at the same time!"

And the people at Microsoft looked up from their desks and said, "What's that sound? Somebody's happy about something! Red alert! Battle stations! We must mess this up!" So they decided to make their DOS text-file standard insist on both a CR and a LF or no 'enter' happens. They didn't get another chance to have that much fun until they screwed up CSS box models.

Here, see for yourself, for a text document which says:

I like traffic lights.

But only when they're green.

here it is in binary view, Unix format:

Unix newlines

and in DOS format:

DOS newlines

There's the 0x0D0A right there!

Now, most any and every text-handling utility these days can handle either one. And it's no big deal to convert from one to the other. I actually have the classic sed solution saved in a shell script. Yeah, sure, it's no problem to filter your CSS to check for Internet Explorer before you start slinging div boxes around, too. What's a few more minutes off your life each day?

But invariably, if I assume the user I'm sending the file to is using Notepad, they'll came to me later going "I opened this in Emacs and it's full of '^M's!" If I assume the user is not using Notepad, they'll bounce it back going, "What the heck is wrong with you! Can't you find the 'enter' key?" I have to ask every single time. Like a fast food cook saying, "You want fries with that?" "Will that be with CRs or without?"

And it's been this way for 23 years!!! They still haven't fixed it, and we've spent an accumulated year off of all of our lives by now shuffling documents around because of one stupid program.

This blog post isn't going to change anything, is it?

Disclaimer This post isn't just a rant; it serves a purpose. This problem comes up all the time with my work. Invariably, someone will ask "Why?" Now, instead of having to drop everything to teach an impromptu seminar on the history of typographic technology, I can just point them here.

Update: A year and a half later, Jeff Atwood kind of unintentionally repeats almost everything I say here. Plus adds some new characters, for two Unicode line breaks. Oh, and he also completely flubs identifying what a daisy wheel is, despite linking to a Wikipedia article that shows a photo of something which clearly isn't what he's talking about. And then comments are turned off, for some mysterious reason. So, uh, somebody let him know? I'm busy.

Follow me on Twitter for an update every time this blog gets a post.
Stumble it Reddit this share on Facebook

:: Next Page >>
suddenly the moon