Matthew Helmke (dot) Net

Random things that interest me.

Drupal 6 JavaScript and jQuery

March26

Anyone who has been paying attention knows that I have been doing a ton of reading lately on Drupal 6. I admit it, I have a tendency to get interested in something and then consume every bit of information about it that I can find. I recently read a book on pure JavaScript because I noticed that Drupal version 6 ships with a Drupal JavaScript library (drupal.js) as well as a fairly recent and powerful library that is gaining followers rapidly called jQuery.

I have been waiting for this book to come out for months, since I first heard that it was being written. Matt Butcher and Packt Publishing released Drupal 6 JavaScript and jQuery last month. Now that I have had a chance to read it, I must say that it does not fail to please.

What I wanted to learn was why Drupal chose to include JavaScript in the Drupal core, what it is used to accomplish and how. I am very familiar with HTML and CSS, and am reasonably adept at reading and modifying PHP when necessary, so all the other main parts of Drupal are built using tools I know and understand. I wanted to find out how and why I would want to take advantage of the stated and implied benefits of including the free and open source jQuery library in sites I administer and design using Drupal.

The books starts off with a very quick introduction to Drupal. It is obvious that the intended audience is not newcomers, and that this is not a basic introduction level text. It is assumed that anyone reading this is familiar with web site creation and administration, web hosting basics, and knows how to install a Drupal site that uses the default theme. You get a quick tour of the main core features of Drupal and some nice web browser tools for developers. Then we get to the meat of the book.

Starting in chapter two we learn how to work with JavaScript in Drupal by writing a short js program and discovering how to include it in a node by incorporating a link to the script in a theme. This is a clear and great beginning.

Chapter three is dedicated completely to the jQuery library, what it is capable of doing, and how to use it the Drupal way instead of reinventing the wheel. The basic point here is that it is a lot easier to use a library to perform complex tasks than it is to write a complete JavaScript function, which would then need to be adapted for different browsers, and it is easy to call those library functions within Drupal because the Drupal developers have chosen to create ways to do so that are even easier than calling those library functions would be in a standard flat HTML/CSS page or some other content management systems. There are useful examples throughout such as how to make a set of announcements display one at a time at the top of your page, fading in and out, so that you can give several tidbits of information to your site guests without requiring all of the space on your page. Cool stuff.

The book contains useful information on how to use the drupal.js library, written by the Drupal developer community, to do many tasks, such as the sample collapsing blocks project that lets guests choose whether to allow information to be displayed or to shrink boxes so that there is more space on a page. We learn how to use js to create beautiful effects and help with site theming, how it can be used to translate your site into other language for guests, and even how to build your own modules.

I have only scratched the surface of the book. As I admitted in my post on the JavaScript book, I am still learning the language. By intent, jQuery is a huge time saver and makes incorporating client side functions into your site easier than using the language alone, and the way the Drupal community has chosen to incorporate that library and write their own in addition makes it still easier. I am glad I picked up the book. Now, if you will excuse me, I need to go play.

Newspapers and an Analogy

March21

Over the last couple of weeks we have seen what we all knew was coming: lots of newspapers making the final decision to cease publication. There are lots of reasons for this, including things like content that doesn’t appeal to readers, the convenience of the internet, investigative journalism that has been made subservient of the desires of marketing and sales departments, and more.

My personal feeling is that the most important reason is simply that for the most part words printed on cheap paper with cheap ink is an archaic method of getting information to the masses. It is slow, it is expensive, and frankly, it’s messy and wasteful.

I think newspapers and even the television and magazine industries need to look at themselves as current day analogs to Vaudeville shows. Once a new method for getting their content to the masses became popular, the producers had to either adapt, retire, or go bankrupt. Many of the big names in Vaudeville became big names in the early days of cinema, radio, and television. That can still happen for today’s news media, but only once they stop fighting the change and learn to adapt themselves to the times.

Linux Identity’s Linux Starter Kit

March18

I contributed seven articles and cowrote another with Ryan Troy for the Linux Starter Kit edition of Linux Identity. The issue should be on newsstands now.

Python for Unix and Linux System Administration

March17

I have four Python books on my shelf. I like the language, at least in theory. It is easy to read, clear, and powerful. In practice, I really don’t program much. I was hoping that this book might push me over the edge from writing shell and PHP scripts for my simple needs into Python land. So many of my friends love the language.

I read the book this week. There are a lot of great ideas in there that would be useful for a sysadmin. The examples chosen are generally practical and useful. I was a bit disappointed by the occasional typographical or capitalization error, especially in code examples and discussion, which are not uncommon in first edition books, but are generally uncommon from O’Reilly books. I also found the early emphasis on iPython to be a bit excessive.

This is a bit shorter than my usual review, mainly because I can’t think of much else to say about the text. It isn’t bad, but it isn’t great. A sysadmin who is motivated to use Python will find it useful as a foundation. A veteran Python programmer who wants to use the language for systems administration will probably find the book filled with stuff they could have figured out anyway. I wanted to love the book, but I didn’t. I didn’t hate the book, either. I just feel a bit “meh” about it.

An interview with Rocket2DMn

March14

Today we have the opportunity to hear from one of our staff members in the Ubuntu Forums, Rocket2DMn, in the latest installment in our Ubuntu Community Interviews series. Rocket2DMn first came to our attention as a result of his help answering questions in the forums. It wasn’t long before he became a member of our Beginner’s Team, which is focused on helping newcomers to the world of Ubuntu and Linux in the forums. He’s a great guy, a patient helper, and a wonderful asset to our community.

1. Tell as much as you’re willing about your “real” life — name, age, gender, location, family, religion, profession, education, hobbies, etc.

My name is Connor Imes, I’m currently 22 and live outside of Philadelphia, though I am originally from California.  I’m a software & systems engineer by trade, but also enjoy other activities like running, skiing, mountain biking, and watching movies.  I hope to travel around the world for my job, meeting new people and experiencing new things.  I am also the only member of my immediate family to not choose a career in medicine, and the only one to not serve in the US Navy.

2. When and how did you become interested in computers? in Linux? in Ubuntu?

I’ve been using computers most of my life, starting with DOS and Windows 3.1.  My passion for computers began with playing games, then progressed to building and tweaking systems, and ultimately to programming and using Linux.  My first experience with *nix came in 2004 at my university where we used Sun Solaris.  My first Linux experience came in 2006 from putting Fedora Core 5 on a game server that I hosted with my roommate all through college.  I started dual booting my laptop with Ubuntu 7.04 Feisty Fawn in May 2007, once a stable ntfs-3g driver was available so that I could share data between the dual boot setup.

I did my first programming when I was in 6th grade, a buddy of mine started learning, so I got a pack of Visual Basic CDs with some books, and went to work!  It also lead me into constructing a few basic websites along the way.

3. When did you become involved in the forums (or the Ubuntu community)? What’s your role there?

I started on the Ubuntu Forums right when I first started using Ubuntu, and have been a regular from day 1.  I joined the Unanswered Posts Team and Beginners Team at the beginning of 2008 and have been heavily involved since then, esp. with the BT.  I sit on the BT Council and head up the Wiki Focus Group which works with the Ubuntu Documentation Team.  In July of 2008, I was invited to become part of the Ubuntu Forums staff.  I considered declining the offer, but felt I could contribute positively to the community in that role, as well as build some good relationships in the Ubuntu community.  I accepted, and am certain that both predictions have proven to be true!

4. Are you an Ubuntu member? If so, how do you contribute? If not, do you plan on becoming one?

Yes, I was approved for membership in early 2009 by the Americas regional board. I was going to apply during the summer of 2008 with a handful of other Beginners Team members, but delayed my application.  I saw a lot of members come to the BT, and many were interested in becoming Ubuntu members – I just wanted to show that you could be a strong and dedicated contributor without being an Ubuntu member.  I’ve never really been a fan of titles and badges because I hate to see them distract from what is really important, which is having fun and making a positive impact.

My contributions are mostly on the forums, launchpad bugs, development release testing, and to the documentation team.  I’m looking to contribute to official system documentation and to triaging (and troubleshooting) some of the common but tough bugs – kernel, X, and wireless problems!

5. What distros do you regularly use? What software? What’s your favorite application? Your least favorite?

Ubuntu is my primary distribution all around, I use it on my laptop (I’ve ditched the dual boot there), and I dual boot between Vista and Ubuntu on my desktop.  Nowadays, Vista is only really kept around for gaming some weekends, and any specific functions I might need it for in the future.  In the past few years, I have spent time with (in no particular order): Ubuntu, Fedora Core, Mandriva, Puppy Linux, Gentoo, Red Hat, CentOS, and OpenSolaris (not Linux!).

My favorite applications would have to be the ones I use every day – Firefox, Pidgin, Xchat, Amarok, VirtualBox, Thunderbird, the conky.  I don’t think I have a least favorite application.

6. What’s your fondest memory from the forums, or from Ubuntu overall? What’s your worst?

The forums can sometimes be a bit of a roller coaster, it is tough to decide a best and worst, but I’ll try.

The FOSS community can often be very vocal, and despite our best efforts, sometimes a little rude.  This became very apparent in summer 2008, shortly after I became a moderator on the forums, when a user posted about Foxconn supposedly sabotaging their BIOS to intentionally not work with Linux.  This was, of course, bogus, but it hit Digg, Slashdot, Reddit, blogs and other sites all over the world and created quite a mess.  When I jumped into the fray almost 12 hours after it started, I found people bashing Foxconn left and right, and in all the chaos, nobody had even bothered to attempt triage on the Launchpad bug.  I did it myself, and followed the case all the way through to the end.  Since all the forum threads ended up getting closed as flame bait, I wound up keeping the community up to date with developments, and was ultimately in contact with a Foxconn representative.  By the time it was all over, the original poster was banned from the forums, Foxconn worked with the poster to test new BIOSes, a fix was released, I was relaying information, and the community was singing Foxconn’s praises for taking us seriously.

I think it was the worst and best of my experiences on the Ubuntu Forums to date.

7. What luck have you had introducing new computer users to Ubuntu?

Since it’s a rare occasion that I run across new computer users, I haven’t had much success in this department.  I have shown off Ubuntu to a number of people, and introduced some of them to the great world of Linux and FOSS for the first time.

8. What would you like to see happen with Linux in the future? with Ubuntu?

I would like to see Linux become more available in off-the-shelf computer systems for home users, and for the general user population to know about Linux as a viable alternative.  I also have very high expectations for Linux overseas, esp. in developing countries.  However, I hope that neither Linux nor Ubuntu become victims of their own success.  To clarify that statement, I would love for everybody to know about and have the ability to use Ubuntu (or another flavor of Linux), but I don’t want either to lose aspects that make them so great or gain baggage that will spoil their appeal.

9. If there was one thing you could tell all new Ubuntu users, what would it be?

If you are thinking of switching, I would highly suggest using some FOSS in your current setup before you make the switch.  Get comfortable with programs like Firefox, Pidgin, OpenOffice.org, and VLC – these will ease your transition so that when you get here, everything won’t be totally foreign.

After you install, you are very likely to sit face to face with the system and have a moment of “OH MAH GAWD what was I thinking?!”  Breathe.  Remember that the Ubuntu Forums are always just a few clicks away, with knowledgeable users ready and willing to help you out!

Learning JavaScript

March10

I recently became the maintainer for a site that uses a bit of JavaScript. Surprisingly, I have no previous experience writing or maintaining anything in JavaScript, so I needed to get up to speed, if only to know what is going on. To help me out, I picked up a copy of Shelley Powers’ new book, Learning JavaScript.

I am familiar with Shelley Powers’ work, having read Unix Power Tools, a book that holds a special place on my shelf for its usefulness and depth. She is obviously someone who knows what she is doing.

This book states in the preface that

Readers of this book should be familiar with web page technology, including Cascading Style Sheets (CSS) and HTML/XHTML. Previous programming experience isn’t required, though some sections may require extra review if you have no previous exposure to programming.

That sums up the only negative thing I might be tempted to say about the book. Usually, O’Reilly’s “Learning” series books are excellent resources for complete newcomers and are the sort of books that I might point a novice toward. While this book is designed for the JavaScript novice, it is not the best resource for a programming/web creation novice. If you can’t follow or understand the following quoted sentences, this book isn’t for you. If you can, this book does an excellent job of covering the basics of JavaScript in depth and may end up being the only text you need on the topic.

JavaScript has just three primitive data types: string, numeric, and boolean. Each is differentiated from the others by the type of value it contains: string, numeric, and boolean, respectively.

My first exposure to programming was in 1981, using BASIC on a Radio Shack TRS-80 Color Computer. Over the years, I have studied (and often forgotten, but can certainly read a bit and understand the concepts of) LISP, C, Bash scripting, Perl, Python, and more. Lately I have spent more time using PHP and enjoying it, since that is the language of things like WordPress, Drupal, vBulletin and other commonly used CMS and interactive web site software. The two sentences quoted above seem perfectly clear to me, but I can imagine what they must seem like to someone with no experience with programming languages. So, now you have been warned. Let’s get to the good stuff for those who understand the jargon.

This book is clear, with enough detail to help you understand what is happening without bogging you down in the minutiae. The reader is expected to see how and why each facet of the language would be useful, so the examples given are simple and seem to be designed to help her get the feel for usage without pretending to be a cookbook of programming recipes, although some seem quite useful as they are such as Chapter 6′s code for browser detection, which allows you to modify content and/or how it is displayed based on the web browser being used to view your site.

The text covers everything you are likely to need while using JavaScript, and more importantly for me, most everything a person is likely to stumble across when reading existing code. You get a solid introduction to data types and variables, operators, statements, objects, and functions. This is built upon with chapters on debugging and cross-browser compatibility. This new second edition (just released earlier in 2009) has several updates and changes from the previous version including a wonderful comparison of the benefits of generating and processing XML data using Ajax versus using JSON.

If you are considering using JavaScript on a website that includes the dynamic creation of web pages, or if you have inherited one that you are now responsible for maintaining, this book would be a good resource to help you start to understand one of the more common languages used for doing so. This is especially true if you have any prior experience with any other programming language. If you want a cookbook, scripted-style, “do this, now do that” sort of beginner’s guide to making a site that holds your hand through the whole process, this is not the book you want.