21.07.2015 Views

Linux Journal | February 2012 | Issue 214 - ACM Digital Library

Linux Journal | February 2012 | Issue 214 - ACM Digital Library

Linux Journal | February 2012 | Issue 214 - ACM Digital Library

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

FREE TOSUBSCRIBERSEPUB, Kindle, Android, iPhone & iPad editionsSinatra | HTML5 | Catalyst | Drupal 7 | MoodleINTRO TO THESINATRA MICRO-FRAMEWORKTHE BEST WAYTO CLIENTCONCURRENCYSince 1994: The Original Magazine of the <strong>Linux</strong> CommunityFEBRUARY <strong>2012</strong> | ISSUE <strong>214</strong> | www.linuxjournal.comWEB DEVELOPMENTCREATEWeb Apps withCatalyst and PerlAUDIOSOLUTIONSwith HTML5UseDRUPAL 7for BasicWeb DesignINTERVIEW WITHSTEPHEN WOLFRAMof Mathematicaand Wolfram|Alpha+NEW COLUMN:THE OPEN-SOURCECLASSROOM


CONTENTSFEBRUARY <strong>2012</strong>ISSUE <strong>214</strong>WEB DEVELOPMENTFEATURES68 An Introductionto ApplicationDevelopment withCatalyst and PerlUsing Catalyst for rapidapplication development.Henry Van Styn82 Three Ways to WebServer ConcurrencyHow does Node.js workunder the hood?Martin Kalin92 HTML5 for AudioApplicationsCoding audio into HTML5pages is fairly straightforward.Paul Freitas100 Basic Web Designwith Drupal 7Creating content types andmanipulating them with aview to display data insimple ways.Kenneth P. J. Dyer4 / FEBRUARY <strong>2012</strong> / WWW.LINUXJOURNAL.COM


COLUMNS30 Reuven M. Lerner’s At the ForgeSimple Apps with Sinatra38 Dave Taylor’s Work the ShellScrabble and Words With Friends42 Kyle Rankin’s Hack and /Password Cracking with GPUs, Part II:Get Cracking50 Shawn Powers’ The Open-SourceClassroomMoodle. It Works.118 Doc Searls’ EOFThe Near-Death of Blog SearchINDEPTH108 Interview with Dr StephenWolframLearn about the developer ofMathematica and the Wolfram|Alphacomputational knowledge engine.James GrayIN EVERY ISSUE8 Current_<strong>Issue</strong>.tar.gz10 Letters20 UPFRONT58 New Products62 New Projects119 Advertisers Index65 DARKTABLEON THE COVER• Intro to the Sinatra Micro-Framework, p. 30• The Best Way to Client Concurrency, p. 82• Create Web Apps with Catalyst and Perl, p. 68• Audio Solutions with HTML5, p. 92• Use Drupal 7 for Basic Web Design, p. 100• Interview with Stephen Wolfram of Mathematica and Wolfram|Alpha, p. 108• New Column: The Open-Source Classroom, p. 5050 MOODLECOVER IMAGE: © Can Stock Photo Inc. / thesupe87LINUX JOURNAL (ISSN 1075-3583) is published monthly by Belltown Media, Inc., 2121 Sage Road, Ste. 310, Houston, TX 77056 USA. Subscription rate is $29.50/year. Subscriptions start with the next issue.WWW.LINUXJOURNAL.COM / FEBRUARY <strong>2012</strong> / 5


Subscribe to<strong>Linux</strong> <strong>Journal</strong><strong>Digital</strong> Editionfor only$2.45 an issue.Executive EditorSenior EditorAssociate EditorArt DirectorProducts EditorEditor EmeritusTechnical EditorSenior ColumnistSecurity EditorHack EditorVirtual EditorJill Franklinjill@linuxjournal.comDoc Searlsdoc@linuxjournal.comShawn Powersshawn@linuxjournal.comGarrick Antikajiangarrick@linuxjournal.comJames Graynewproducts@linuxjournal.comDon Martidmarti@linuxjournal.comMichael Baxtermab@cruzio.comReuven Lernerreuven@lerner.co.ilMick Bauermick@visi.comKyle Rankinlj@greenfly.netBill Childersbill.childers@linuxjournal.comContributing EditorsIbrahim Haddad • Robert Love • Zack Brown • Dave Phillips • Marco Fioretti • Ludovic MarcottePaul Barry • Paul McKenney • Dave Taylor • Dirk Elmendorf • Justin RyanProofreaderGeri GaleENJOY:Timely deliveryOff-line readingPublisherAdvertising Sales ManagerAssociate PublisherWebmistressAccountantCarlie Fairchildpublisher@linuxjournal.comRebecca Cassityrebecca@linuxjournal.comMark Irgangmark@linuxjournal.comKatherine Druckmanwebmistress@linuxjournal.comCandy Beauchampacct@linuxjournal.comEasy navigationPhrase searchand highlightingAbility to save, clipand share articlesEmbedded videosAndroid & iOS apps,desktop ande-Reader versions<strong>Linux</strong> <strong>Journal</strong> is published by, and is a registered trade name of,Belltown Media, Inc.PO Box 980985, Houston, TX 77098 USAEditorial Advisory PanelBrad Abram Baillio • Nick Baronian • Hari Boukis • Steve CaseKalyana Krishna Chadalavada • Brian Conner • Caleb S. Cullen • Keir DavisMichael Eager • Nick Faltys • Dennis Franklin Frey • Alicia GibbVictor Gregorio • Philip Jacob • Jay Kruizenga • David A. LaneSteve Marquez • Dave McAllister • Carson McDonald • Craig OdaJeffrey D. Parent • Charnell Pugsley • Thomas Quinlan • Mike RobertsKristin Shoemaker • Chris D. Stark • Patrick Swartz • James WalkerAdvertisingE-MAIL: ads@linuxjournal.comURL: www.linuxjournal.com/advertisingPHONE: +1 713-344-1956 ext. 2SubscriptionsE-MAIL: subs@linuxjournal.comURL: www.linuxjournal.com/subscribeMAIL: PO Box 16476, North Hollywood, CA 91615-9911 USALINUX is a registered trademark of Linus Torvalds.SUBSCRIBE TODAY!


2U Appliance:You Are the CloudExpansionShelvesAvailableStorage. Speed. Stability.With a rock-solid FreeBSD® base, Zettabyte File System (ZFS)support, and a powerful Web GUI, TrueNAS pairs easy-to-manageFreeNAS software with world-class hardware and support foran unbeatable storage solution. In order to achieve maximumperformance, the TrueNAS 2U System, equipped with the Intel®Xeon® Processor 5600 Series, supports Fusion-io’s Flash MemoryCards and 10 GbE Network Cards. Titan TrueNAS 2U Appliancesare an excellent storage solution for video streaming, file hosting,virtualization, and more. Paired with optional JBOD expansionunits, the TrueNAS System offers excellent capacity at anaffordable price.For more information on the TrueNAS 2U System, or to requesta quote, visit: http://www.iXsystems.com/TrueNAS.CloneSnapshotAll VolumesKeY feATUreS:. Supports One or Two Quad-Core or Six-Core, Intel® Xeon® Processor 5600 Series. 12 Hot-Swap Drive Bays - Up to 36TB ofData Storage Capacity*. Periodic Snapshots Feature Allows You toRestore Data from a Previously GeneratedSnapshot. Remote Replication Allows You to Copy aSnapshot to an Offsite Server, forMaximum Data Security. Software RAID-Z with up to Triple Parity. 2 x 1GbE Network interface (Onboard) +Up to 4 Additional 1GbE Ports or Single/Dual Port 10 GbE Network CardsJBOD expansion is available on the2U System* 2.5” drive options available; pleaseconsult with your Account ManagerCreate Periodic SnapshotCall iXsystems toll free or visit our website today!1-855-GREP-4-IX | www.iXsystems.comIntel, the Intel logo, Xeon, and Xeon Inside are trademarks or registered trademarks of Intel Corporation in the U.S. and/or other countries.


Current_<strong>Issue</strong>.tar.gzSHAWN POWERSMore Than DarkRooms and Red LightsDeveloping photographs used to be amysterious process that took placein rooms lit like horror films, usingpans of dangerous chemicals. From thosecreepy rooms eventually emerged beautifulphotographs of literally everything under thesun. Web development is surprisingly similar.If you replace the dangerous chemicals witha clacking keyboard and the red lights withthe blue glow of an LCD screen, they’re justabout the same. This month, we delve intothe mystical world of Web development,which turns ordinary tags and scripts into thebeautiful Web sites we visit every day.Reuven M. Lerner is right at home with ourfocus this month and shows us Sinatra. No,he doesn’t teach us to be crooners; instead,he demonstrates the micro-framework thatmakes small Web apps a breeze to create. Ifyou need to do something small, and Rubyseems like overkill, give Sinatra a try.Dave Taylor explains how to make a smallprogram this month as well, but his script isa little more nefarious. If you want to be alying, cheating dog when you play Scrabbleagainst your friends, Dave can help you out.He shows how to make a shell script thatfinds words based on the letters you have.As a purely educational endeavor, it’s a greatarticle, but as of now, I will no longer playWords With Friends with any <strong>Linux</strong> <strong>Journal</strong>readers!Kyle Rankin continues his series on GPUpoweredpassword cracking. Even if you’renot interested in learning to brute-force attackpasswords, I recommend reading his article.It will convince you to use a strong passwordquicker than any warning I might give you.Don’t tell Kyle I told you, but I watched himenter his password once at a conference. It’sjust a bunch of asterisks!I got into the Web-themed spirit this monthtoo. This month we’re launching a brand-newcolumn, written by yours truly. The Open-Source Classroom is an education-focusedcolumn, and this month, I break down thevenerable Moodle software package. Moodlehas matured so much since we last covered it,I felt it deserved some attention.Ruby on Rails is a very popular Webframework, but Henry Van Styn knowsthat it’s not the only show in town. He8 / FEBRUARY <strong>2012</strong> / WWW.LINUXJOURNAL.COM


CURRENT_ISSUE.TAR.GZAs a purely educational endeavor, it’s a greatarticle, but as of now, I will no longer play WordsWith Friends with any <strong>Linux</strong> <strong>Journal</strong> readers!describes how to develop Web applicationswith Catalyst and Perl. Regardless of theframework you use to develop, an applicationis only as good as the server hosting it. MartinKalin shows us the nitty-gritty of Web serversand explains multiprocessing, multithreadingand evented I/O. The Internet demands a lotfrom our Web servers, and Martin helps usunderstand exactly how those demands aremet.Possibly bigger than even the Web 2.0 buzzof a few years ago is the transition to HTML5.Although to most folks it’s just a bunch ofgeek jargon, for Web programmers it meansuser interaction like never before. Paul Freitasshows how to take advantage of HTML5 toserve up audio. No, we don’t mean thoseannoying MIDI files playing when the pageloads, but rather using plain-old HTML tags toplay audio on your Web site. If it sounds toosimple to be true, you’ll want to read Paul’sarticle.What if you want to develop a Web site,but you’re not a programmer? That’s wherecontent management systems like Drupalcome into play. Kenneth P. J. Dyer walksthrough designing a Web site with Drupal7. The learning curve for using Drupaltraditionally has been pretty steep, but withversion 7, that’s starting to change. Kennethteaches how things work in Drupal andgets us started on our way to developing apowerful and flexible Web site.We never alienate our non-developerreaders in issues like this, and this month is nodifferent. We have tons of UpFront articles,product announcements and even somehandy tips to make your <strong>Linux</strong> life a littleeasier. In fact, this month James Gray had anopportunity to interview Stephen Wolfram.Yes, that Stephen Wolfram. Whetheryou’re a math nut who loves Mathematicaor are fascinated by the Wolfram|Alphacomputational knowledge engine, this is aninterview you won’t want to miss.So until next month, keep clacking thosekeyboards. If turning on a red light will helpyou develop Web sites, by all means, feel freeto do so. The only dangerous chemical werecommend, however, is caffeine. If you wantto drink your coffee out of developing trays,well, I guess that’s up to you. Either way, wehope you enjoy this issue!■Shawn Powers is the Associate Editor for <strong>Linux</strong> <strong>Journal</strong>. He’s alsothe Gadget Guy for <strong>Linux</strong><strong>Journal</strong>.com, and he has an interestingcollection of vintage Garfield coffee mugs. Don’t let his silly hairdofool you, he’s a pretty ordinary guy and can be reached via e-mailat shawn@linuxjournal.com. Or, swing by the #linuxjournal IRCchannel on Freenode.net.WWW.LINUXJOURNAL.COM / FEBRUARY <strong>2012</strong> / 9


[ LETTERS ]print run. Heck, I might try to print onejust to see how it looks!—Ed.<strong>Digital</strong> Format Forces SomePersonal Changes<strong>Linux</strong> <strong>Journal</strong>’s abandoning paper is takingsome getting used to and will requiresome personal changes if I am to continueto enjoy my favorite magazine. I used tokeep may latest copy next to my favoritechair and would read it in bits and piecesand during commercials on TV. Now theissues go mostly unread because I don’tlike reading magazines or books on mydesktop or laptop. Today, I took my lastpaper copy to the gym to read while usingthe elliptical exercise machine (there is abook holder on the machine). This wasvery workable, but then it dawned onme that I cannot do this with the digitalversion unless I purchase a Kindle orother E Ink equivalent. Your conversionto digital media is going to cost meat least $79 and force some behaviorchanges about which I am not too happy.That said, <strong>Linux</strong> <strong>Journal</strong> is my favoritemagazine, and I am willing to invest inmaking it more readable for me. Maybeyou should do a deal with Amazon andsell <strong>Linux</strong>-branded Kindles!—Edward ComerEdward, although <strong>Linux</strong> <strong>Journal</strong> certainlycan be read on a desktop or laptop, Imust admit an e-reader is my favoriteway to read it. There are advantages anddisadvantages to both E Ink devices andcolor ones, but for a traditional paper“feel”, you are correct, E Ink is hard tobeat. And, as far as a <strong>Linux</strong>-brandedKindle? I’m not sure Amazon would gofor it, but because the Kindle runs <strong>Linux</strong>,we’ll claim the victory anyway.—Ed.The Web Is Not PaperHTML should be the format for Webpublications. One of the first things aWeb page designer learns is that Webpages are not paper. There is no needto fill a Web page like a sheet of paper.Web pages can have open space anduncluttered design with no cost. Paper isexpensive; pixels are not.One should be able to scroll through yourentire magazine with the mouse wheeland an occasional click on a link. The PDFformat itself is bad enough, but laying outthe pages side by side makes it worse. Ifyou stacked single pages, it would be easyto read even a PDF file by a continuousscroll down with the mouse wheel.If you feel a need to have narrowcolumns like a paper magazine, don’tthink paper and put them side byside—have one continuous column witha larger font size. On paper, narrowWWW.LINUXJOURNAL.COM / FEBRUARY <strong>2012</strong> / 11


[ LETTERS ]although I am not and never have beenan Ubuntu guy, I still look forward tothe magazine. However, I feel a greatdisturbance in the force with the lossof a good magazine. Oh, how manyconversations have been struck up due toholding the magazine while standing in acheckout line! I feel as though I wastedmy year’s subscription, since I nevercared to read a digital edition. My moneywould have been better spent on Wiredor some other magazine that still prints.Maybe I will have to buy a NOOK, butI cannot justify spending $200 to reada $3 magazine. I wish you the best,however much longer it lasts.—Nathan EnglandNathan, I could give you the ad-tocontentratio of our magazine comparedto others, showing our passion for fillingpages with content and only limited,relevant ads. But really, what a boringdiscussion that would be. We had toswitch for reasons we’ve highlightedduring the past few months, so for betteror for worse, we’re 100% digital.I am curious, however, if you’ve tried theseveral ways to consume <strong>Linux</strong> <strong>Journal</strong>on your phone. The <strong>Linux</strong> <strong>Journal</strong> appfor the Android will keep your libraryautomatically up to date. As an e-reader,your phone also can display the epubversion using a variety of programs. I’mthe first to admit reading the PDF on asmartphone is a recipe for frustration,but perhaps one of the other formatswill be more comfortable on yourphone? And, of course, if you prefer thetraditional paper look, an E Ink-basedreader like the $79 Kindle is always apossibility.—Ed.At the Forge—December 2011 <strong>Issue</strong>I was quite dismayed by Reuven M.Lerner’s comment “I hope you’re notreally using a queue class but ratherjust using arrays”. Not only does thiscontradict the seminal research andarguments for using abstractions in thefirst place (see Dijkstra, Hoare, Wirth andmany others), but it has the immediatepractical problem of polluting the codewith functions that will not make senseshould the implementation of queueshave to be changed, even slightly.It is almost axiomatic that someone willget bitten when code is written thatdepends on implementation details.—David JamesonReuven M. Lerner replies: I wasn’ttrying to say that people should avoidwriting their own abstractions thatwrap native data types. Rather, I wassaying that if all you need is the simpleimplementation that I showed, youshould just use a Ruby array, ratherthan what amounts to a wrapperaround the array, which offers noadditional functionality.14 / FEBRUARY <strong>2012</strong> / WWW.LINUXJOURNAL.COM


[ LETTERS ]Wrappers are great, and they do providea large degree of safety and abstractionthat can be useful if the implementationchanges. But if you just need an array,there’s no need to wrap it in a classjust in case you might eventually needadditional functionality.LJ Electronic MagazineI wanted to let you know that I justsubscribed to LJ for two years and lovethe material. In Western Australia,your magazine was very hard to find,and by chance, I picked up the August2011 issue and loved it.I looked around after that and could notfind the September 2011 issue. Finally,I picked up my old copy, checked yourWeb site and realized why. I actuallyhad read the Slashdot article about thecancellation, but many months before Ibought your print version.I really just wanted to make this point:without the newsstand copy, I neverwould have seen the magazine and neverwould have become a subscriber. I am a<strong>Linux</strong> lover, and I’ve been reading <strong>Linux</strong>Format/Magazine/User and Developer,and they don’t cut it compared to your


[ LETTERS ]mag. Going electronic only, how willpeople ever find you?I am an avid reader of Slashdot and LWN.I imagine that the latter especially is yourcore market, and I know it strugglesto find advertisers (or used to, it runsAdSense now). You probably should run aPPC campaign every so often to gain newsubscribers. Just make sure you have adecent landing page, as your home pagemakes subscribing a mission and a half.I really hope the switch to electronicworks for you, as <strong>Linux</strong> needs all the goodquality journalism and documentation itcan get.PS. I bought the back-issue DVDas well, so total lifetime value ofsubscribers can be pretty high.—Davidhave to carry for work. I subscribed assoon as I found out you guys went alldigital. I know some are annoyed by theconversion, but I’m really liking the newformat. I have 200+ manuals for work,and it makes a great addition, and whenI’m on the go, I can keep reading on myiTouch. Thanks for the great work. Youguys rock. I have converted my wife to<strong>Linux</strong> and even she enjoys your mag.—RobertThat’s great to hear, Robert! If you’vebeen reading the Letters for the pastfew months, it’s clear that reactionsto the switch have been mixed. We’vepurposefully posted letters from bothsides, because we don’t want tominimize anyone’s frustration. It is greatto hear that a large number of folks notonly tolerate, but also prefer the digitalformat. Thanks for the feedback!—Ed.David, thanks! Yes, losing a newsstandpresence is something we’re bummedabout. You highlight one of the changeswe need to make, and that is how wepromote the magazine. Thank you for thesuggestion, as it’s an issue we need toaddress.—Ed.<strong>Digital</strong> = AwesomeI love that you went all digital. Normally,I run to the local Fred Meyers eachmonth to pick up LJ. I use an iPhoneand have a Kindle. I hate carrying booksor magazines due to the equipment IElectronic VersionI cannot save trees, since I have foundthat I need to print an article in order tobe able to read it easily.The problem is that the height of alaptop screen is not sufficient to displayfonts that an old geezer like me canread without overflowing the page. Pageoverflows would require me to scroll upand down (and maybe left and right) inorder to see everything.I understood that you used flowing text,16 / FEBRUARY <strong>2012</strong> / WWW.LINUXJOURNAL.COM


Mobile changes everywhere.The explosion of mobile technologies has put location-aware devices everywhere. The mobilelandscape is constantly evolving and making smart decisions about buying or building the righttools isn’t easy.Get a handle on what’s what with location at the O’Reilly Where Conference. Learn from leadingedgedevelopers, business leaders, marketers, and entrepreneurs what’s happening how andwhat’s lurking just below the radar—and how you can leverage location for your business.Program TracksMobile Development, Location Development, Business & Strategy,Marketing—and the return of the Location Marketing Boot Camp.Featured SpeakersThomas GoetzWiredCharlene LiAltimeter GroupJer ThorpNew York TimesBrian McClendonGoogleNoah IliinskyComplex DiagramsLeah BusqueTaskRabbitSave 15% on registrationwith code WHR12LJOU©<strong>2012</strong> O’Reilly Media, Inc. The O’Reilly logo is a registered trademark of O’Reilly Media, Inc. 12057


[ LETTERS ]which meant to me that page boundarieswould not be hard-coded, but that zoomingin could simply result in the reformatting ofthe pages to make the articles easier to see.—JimJim, we do use flowing text, but only inthe formats that support such a thing.It sounds like you’re reading the PDFversion, which unfortunately is the leastflexible when it comes to reformatting.Although e-reader devices are the bestfor reading the “flowing” versions (epuband mobi), it is possible to read thoseversions on your computer as well.Calibre, for example, includes an e-bookreadingapplication, and there are waysto read epubs from inside your Webbrowser. One disadvantage to having somany versions available is that it’s easy toget confused regarding which version isbest for different situations.—Ed.More on E-FormattingI’m slowly coming around to life withoutpaper. I now have two e-zines. I have twosuggestions on improving yours. 1) Addlinks within your Kindle version to skip thecurrent article and jump to the next. Thereare just some parts that don’t interest me.Right now, I have two choices: hit theNext button on my Kindle numerous timesor jump to the table of contents and thenjump again. 2) Give us a link to downloadall the formats with one link. Right now,I am downloading each of them. I useCalibre to store all my electronic readingcontent, and this great tool allows meto store different formats of the samedocument under one title.On my Christmas list is a Kindle Fire,so I hope I am reading your magazineon this new baby come January 1.—ScottScott, I’m jealous you’re getting aKindle Fire, but I hope you enjoyit nonetheless. Thank you for theformatting suggestions; we are tryingevery month to make the magazinemore and more user-friendly.Recommendations from readers arevital, so thank you very much.—Ed.Electronic vs. PaperLike some of the readers who have beenunpleasantly surprised by the suddenswitch to pixels from paper, I was initiallyoutraged. As one reader said, I paid forprint and have issues remaining in mysubscription. Your explanation of thereasons for the switch made sense, andyou were obviously doing your best togive value for the money under adverseconditions, so I decided to wait and seehow life in the 21st century would work.After downloading the PDF versions, andthen the iPad app, I can say that I’m gladyou switched! I much prefer the digitalversion. I can carry multiple issues with me,read in the dark, follow links with a fingertouch rather than having to write down18 / FEBRUARY <strong>2012</strong> / WWW.LINUXJOURNAL.COM


URLs for later entry into a browser, and I can put theold issues up on my LAN server for future reference(the HTML versions are even searchable!). It’s eveneasy to send thank-you notes to the editors! Thanks!—Mike BartmanMike, thanks for sticking with us! We tried (andcontinue to try) to be as transparent as possibleregarding the switch. Although there are obviousfrustrations when transitioning to digital, we honestlyare excited about the advantages it can offer. Ofcourse, those advantages don’t erase the frustrationabout the end of paper, but looking forward isexciting. We’re glad you’ll be here with us.—Ed.ezPDF ReaderI read in the December 2011 issue’s Letters thatDave was having issues with the PDF version on hisNOOK Color. I too have a NOOK Color and wouldlike you to please pass on some advice to Dave. Tellhim to buy the app ezPDF Reader. It is far superiorto the NOOK’s built-in PDF reader.By the way, I’ve been a subscriber for 14 years,and I love the digital transition. You’ve all done afantastic job of it.—Doug McComberDoug, we decided this was the best way to passthe information on to Dave. We figured he’d read ithere, and then anyone else reading would benefitas well! For the record, our Webmistress KatherineDruckman agrees with you 100% and seconds yourrecommendation of ezPDF.—Ed.WRITE LJ A LETTER We love hearing from our readers. Please send usyour comments and feedback via http://www.linuxjournal.com/contact.At Your ServiceSUBSCRIPTIONS: <strong>Linux</strong> <strong>Journal</strong> is availablein a variety of digital formats, including PDF,.epub, .mobi and an on-line digital edition,as well as apps for iOS and Android devices.Renewing your subscription, changing youre-mail address for issue delivery, paying yourinvoice, viewing your account details or othersubscription inquiries can be done instantlyon-line: http://www.linuxjournal.com/subs.E-mail us at subs@linuxjournal.com or reachus via postal mail at <strong>Linux</strong> <strong>Journal</strong>, PO Box16476, North Hollywood, CA 91615-9911 USA.Please remember to include your completename and address when contacting us.ACCESSING THE DIGITAL ARCHIVE:Your monthly download notificationswill have links to the various formatsand to the digital archive. To access thedigital archive at any time, log in athttp://www.linuxjournal.com/digital.LETTERS TO THE EDITOR: We welcome yourletters and encourage you to submit themat http://www.linuxjournal.com/contact ormail them to <strong>Linux</strong> <strong>Journal</strong>, PO Box 980985,Houston, TX 77098 USA. Letters may beedited for space and clarity.WRITING FOR US: We always are lookingfor contributed articles, tutorials andreal-world stories for the magazine.An author’s guide, a list of topics anddue dates can be found on-line:http://www.linuxjournal.com/author.FREE e-NEWSLETTERS: <strong>Linux</strong> <strong>Journal</strong>editors publish newsletters on botha weekly and monthly basis. Receivelate-breaking news, technical tips andtricks, an inside look at upcoming issuesand links to in-depth stories featured onhttp://www.linuxjournal.com. Subscribefor free today: http://www.linuxjournal.com/enewsletters.ADVERTISING: <strong>Linux</strong> <strong>Journal</strong> is a greatresource for readers and advertisers alike.Request a media kit, view our currenteditorial calendar and advertising due dates,or learn more about other advertisingand marketing opportunities by visitingus on-line: http://ww.linuxjournal.com/advertising. Contact us directly for furtherinformation: ads@linuxjournal.com or+1 713-344-1956 ext. 2.WWW.LINUXJOURNAL.COM / FEBRUARY <strong>2012</strong> / 19


UPFRONTNEWS + FUNdiff -uWHAT’S NEW IN KERNEL DEVELOPMENTAfter the security breach on kernel.org,the administrators of that site had tore-implement the site from scratch, and theyhad to prioritize the features that wouldbe coming back soonest. They also had theopportunity to exclude features that seemedto be more trouble than they were worth.One of the latter seems to be theMercurial-based kernel repository mirrorthat Matt Mackall had maintained onkernel.org. Matt’s repository offered analternative for developers who didn’t carefor Git’s approach to source control—orat least who just liked Mercurial better.Matt intends to bring the repositoryback to life somewhere else, but he’s notsure when that might be, and he’s alsoaffirmed that the new repository won’t befully compatible with the old. So, peoplewanting to update their local repositorieswill need to get a fresh one instead.Davidlohr Bueso recently inauguratedan argument over user quotas, whenhe posted a patch to limit regular users’ability to fill up the /tmp directory on <strong>Linux</strong>systems. His justification was that filling upthat directory represents a denial-of-serviceattack. His patch actually created a quotasystem for all tmpfs filesystems.Everyone (except the attackers) agreesthat DoS attacks are bad, but this may bean area where it’s not so easy to agree onthe best approach. Christoph Hellwig,for example, felt that Davidlohr shouldjust use the existing user quota systemand apply it to /tmp. Lennart Poetteringargued that this would require a lot ofuser-space configuration that wouldn’tbe necessary with Davidlohr’s approach.And, Alan Cox felt that other securityissues were more pressing than this one.No one’s argument won the day, and it’snot clear that such a long-standing issuewill catch Linus Torvalds’ attention.Likewise, long-standing securityproblems in /proc may not be on theradar either. Vasiliy Kulikov posted apatch to give tighter permissions to/proc/interrupts, but this got a coolreception. Apparently the longtimeweaknesses of things like /proc and /tmpare dangerous only if someone alreadyhas a login account on a given machine,in which case a variety of other exploitsare available as well.Marek Szyprowski has been workingon a contiguous memory allocatorfor Samsung. The idea is that a lot ofsmaller embedded systems don’t supportsoftware jumping around in RAM, and20 / FEBRUARY <strong>2012</strong> / WWW.LINUXJOURNAL.COM


[ UPFRONT ]video-editing software can sometimesrequire a contiguous chunk of memoryfor its image data. But even on regularsystems, contiguous RAM can provide aspeedup over fragmented RAM. However,the problem with trying to make everythinguse contiguous memory is that eventuallyyou get stuck with chunks of RAM thataren’t big enough for anyone, and thatjust hang out, unused, even when thesystem really needs more RAM. Mareksaid his code wasn’t quite ready forinclusion, but it was coming along.—ZACK BROWNEPUBReaderWith our recent transition to a digital-only format, it’s now possible to consume <strong>Linux</strong><strong>Journal</strong> in a number of ways. For those so inclined, it’s even possible to print each issueand bind it into a paper magazine. (The PDF lends itself quite nicely to that in fact.)Electronically speaking, however, it’shard to beat the .epub/.mobi editions.If you’d like to browse this month’sissue without ever leaving yourcomputer, you might want to check outEPUBReader, a Firefox add-on that turnsyour browser in to a mini-library. Afterinstalling the add-on, epub files areopened automatically and added to thelocal epub library. To access your library,simply go to Tools, and select ePub-Catalog. You’ll be presented with a listof all your locally stored epub books, andwith a simple click, you can be browsing.EPUBReader includes support for aninteractive table of contents, which makes wise use of a computer’s widescreen display. Iteven supports keyboard shortcuts! EPUBReader is free, cross-platform and quite honestly, areally nice e-reader app. Check it out at http://www.epubread.com.—SHAWN POWERSWWW.LINUXJOURNAL.COM / FEBRUARY <strong>2012</strong> / 21


[ UPFRONT ]Non-<strong>Linux</strong> FOSSTrueCrypt is a fully open-source tool for encryptingdata. That data can be on a completely encryptedhard drive, or just an encrypted image file. Thankfully,the encryption works the same regardless of yourplatform, so Windows and OS X users can shareencrypted files between computers.We reallylike to useTrueCrypt incombination with Dropbox, another cross-platform tool,to protect our data in the cloud. Pictured here is the OSX version of TrueCrypt, mounting an encrypted image asa local hard drive. Whether you are storing sensitive dataor Grandma’s secret recipe, TrueCrypt can keep yourdata private, even if it’s stored on someone else’s server.They Said ItThe glass is neitherhalf-full nor halfempty:it’s twice asbig as it needs to be.—UnknownI would love tochange the world,but they won’t giveme the source code.—UnknownI changed all mypasswords to“incorrect”. So mycomputer just tellsme when I forget.—UnknownA stitch in timewould haveconfused Einstein.—UnknownFor more information and downloadable binaries forWindows and OS X, visit http://www.truecrypt.org.—SHAWN POWERSAn effective way todeal with predatorsis to taste terrible.—Unknown22 / FEBRUARY <strong>2012</strong> / WWW.LINUXJOURNAL.COM


[ UPFRONT ]<strong>Linux</strong><strong>Journal</strong>.comThis month’s issue is about my favorite <strong>Linux</strong>-related topic, Web development. The<strong>Linux</strong>-powered Web is a subject I believe we all particularly enjoy, as it is one of thosefantastic instances where <strong>Linux</strong> enters many people’s lives without their awareness.It’s always fun for geeks like us to know that our work behind the scenes can havesuch impact on the unsuspecting public. The technologies highlighted in this issue areshaping the current and future Web, so we hope you’ll take away some inspiration togo out and make something awesome on-line.I am more than a little biased, as Drupal powers <strong>Linux</strong><strong>Journal</strong>.com, but I hopeyou’ll be inspired to try Drupal 7 after this month’s introduction to content types andviews, and if you’d like to learn even more about Drupal 7, see the following posts on<strong>Linux</strong><strong>Journal</strong>.com:n “Angela Byron on Drupal 7” by Katherine Druckman: http://www.linuxjournal.com/content/interview-angie-byron-drupaln “Drupal 7: the Webchick behind the Wheel” by Katherine Druckman:http://www.linuxjournal.com/article/10999n “Drush: Drupal for People Who Hate Mice” by James Walker:http://www.linuxjournal.com/article/11000This month, we also feature an article about HTML5’s audio capabilities, whichillustrates one of the many exciting new options HTML5 brings to the table. To readmore about other HTML5 possibilities, including for mobile applications, see thesearticles on <strong>Linux</strong><strong>Journal</strong>.com:n “Augmented Reality with HTML5” by Rick Rogers: http://www.linuxjournal.com/article/10920n “At the Forge—HTML5”: http://www.linuxjournal.com/article/10926You’ll find more about these topics and many others in our Web Developmentsection at http:/www.linuxjournal.com/tag/web-development.—KATHERINE DRUCKMANWWW.LINUXJOURNAL.COM / FEBRUARY <strong>2012</strong> / 23


[ UPFRONT ]Science the GNU Way, Part IIn my past several articles, I’ve lookedat various packages to do all kinds ofscience. Sometimes, however, therejust isn’t a tool to solve a particularproblem. That’s the great thing aboutscience. There is always something newto discover and study. But, this meansit’s up to you to develop the softwaretools you need to do your analysis. Thisarticle takes a look at the GNU Scientific<strong>Library</strong>, or GSL. This library is the SwissArmy library of routines that you will finduseful in your work.First, you need to to get a copy of GSLand install it on your system. Because itis part of the GNU Project, it is hostedat http://www.gnu.org/s/gsl. Youalways can download and build from thesource code, but all major distributionsshould have packages available. Forexample, on Debian-based systems, youneed to install the package libgsl0-devto develop your code and gsl-bin to runthat code. GSL is meant for C and C++,so you also need a compiler. Most of youprobably already are familiar with GCC,so I stick with that here.The next step is actually the last step.I’m looking at compiling now so that Ican focus on all the tools available inGSL. All the header files for GSL arestored in a subdirectory named gsl. So,for example, if you wanted to includethe math header file, you would use:#include All the functions are stored in a singlelibrary file called libgsl.a or libgsl.so. Youalso need a library to handle basic linearalgebra. GSL provides one (in the filelibgslcblas.so), but you can use your own.Additionally, you need to link in the mathlibrary. So, the final compile and linkcommand should look like this:gcc -o hello_world hello_world.c -lgsl -lgslcblas -lmThere are optional inline versionsfor some of the performance-criticalfunctions in GSL. To use these, youneed to include -DHAVE_INLINEwith your compile command. To tryto help with portability issues, GSLoffers some functions that exist only oncertain platforms (and not others). Asan example, the BSD math library hasa function called hypot. GSL offers itsown version, called gsl_hypot, thatyou can use on non-BSD platforms.Some functions have both a generalalgorithm as well as optimized versionsfor specific platforms. This way, if youare running on a SPARC, for example,you can select a version optimized forSPARC if it exists.One of the first things you likelywill want to do is check whether youare getting correct results from your24 / FEBRUARY <strong>2012</strong> / WWW.LINUXJOURNAL.COM


[ UPFRONT ]code or if there were errors. GSL has anumber of functions and data structuresavailable in the header file namedgsl_errno.h. Functions return a value ofzero if everything is fine. If there wereany problems in trying to complete therequested action, a nonzero value isreturned. This could be an actual errorcondition, like a wrong data type ormemory error, or it could be a conditionlike not being able to converge to withinthe requested accuracy in the functioncall. This is why you always need to checkthe return value for all GSL function calls.The actual values returned in an errorcondition are error codes, defined inthe file gsl_errno.h. They are defined asmacros that start with GSL_. Examplesinclude the following:n GSL_EDOM — domain error, used byfunctions when an argument doesn’tfall into the domain over which thefunction is defined.n GSL_ERANGE — range error, either anoverflow or underflow.n GSL_ENOMEM — no memory available.The library will use values only up to1024. Values above this are availablefor use in your own code. There alsoare string versions of these errorcodes available. You can translate theerror code to its text value with thefunction gsl_errno().Now that you know how to compileyour program and what to do witherrors, let’s start looking at what kindof work you can do with GSL. Basicmathematical functions are definedin the file gsl_math.h. The set ofmathematical constants from the BSDmath library are provided by this partof GSL. All of the constants start withM_. Here are a few of them:n M_PI — pi.n M_SQRT2 — the square root of 2.n M_EULER — Euler’s constant.There also are capabilities for dealingwith infinities and non-numbers. Threemacros define the values themselves:n GSL_POSINF — positive infinity.n GSL_NEGINF — negative infinity.n GSL_NAN — not a number.There also are functions to test variables:n gsl_isnan — is it not a number?n gsl_isinf — is it infinite?n gsl_finite — is it finite?There is a macro to find the sign ofa number. GSL_SIGN(x) returns theWWW.LINUXJOURNAL.COM / FEBRUARY <strong>2012</strong> / 25


[ UPFRONT ]sign of x: 1 if it is positive and –1 if it isnegative. If you are interested in seeingwhether a number is even or odd, twomacros are defined: GSL_IS_ODD(x)and GSL_IS_EVEN(x). These return 1if the condition is true and 0 if it is not.A series of elementary functionsare part of the BSD math library. GSLprovides versions of these for platformsthat don’t have native versions, includingitems like:n gsl_hypot — calculate hypotenuse.n gsl_asinh, gsl_acosh, gsl_atanh —the arc hyperbolic trig functions.If you are calculating the power of anumber, you would use gsl_pow_int(x,n),which gives you x to the power of n.There are specific versions for powersless than 10. So if you wanted to findthe cube of a number, you would usegsl_pow_3. These are very efficientand highly optimized. You even caninline these specialized functions whenHAVE_INLINE is defined.Several macros are defined to helpyou find the maximum or minimum ofnumbers, based on data type. The basicGSL_MAX(a,b) and GSL_MIN(a,b)simply return either the maximum orminimum of the two numbers a and b.GSL_MAX_DBL and GSL_MIN_DBLfind the maximum and minimum oftwo doubles using an inline function.GSL_MAX_INT and GSL_MIN_INT dothe same for integer arguments.When you do any kind of numericalcalculation on a computer, errorsalways are introduced by round-offand truncation. This is because youcan’t exactly reproduce numbers on afinite binary system. But, what if youwant to compare two numbers andsee whether they are approximatelythe same? GSL provides the functiongsl_fcmp(x,y,epsilon). Thisfunction compares the two doubles x andy, and checks to see if they are withinepsilon of each other. If they are withinthis range, the function returns 0. If x < y,it returns –1, and it returns 1 if x > y.Complex numbers are used in manyscientific fields. Within GSL, complexdata types are defined in the header filegsl_complex.h, and relevant functionsare defined in gsl_complex_math.h. Tostore complex numbers, the data typegsl_complex is defined. This is astruct that stores the two portions.You can set the values with thefunctions gsl_complex_rect(x,y)or gsl_complex_polar(x,y). In thefirst, this represents “x+iy”; whereasin the second, x is the radius, and yis the angle in a polar representation.You can pull out the real and imaginaryparts of a complex number with themacros GSL_REAL and GSL_IMAG.There is a function available to find theabsolute value of a complex number,gsl_complex_abs(x), where x isof type gsl_complex. Because complex26 / FEBRUARY <strong>2012</strong> / WWW.LINUXJOURNAL.COM


numbers actually are built up of two parts,even basic arithmetic is not simple. To dobasic math, you can use the following:n gsl_complex_add(a,b)n gsl_complex_sub(a,b)n gsl_complex_mul(a,b)n gsl_complex_div(a,b)You can calculate the conjugate withgsl_complex_conjugate(a) and theinverse with gsl_complex_inverse(a).There are functions for basic mathematicalfunctions. To calculate the square root,you would use gsl_complex_sqrt(x).To calculate the logarithm, you woulduse gsl_complex_log(x). Severalothers are available too.Trigonometric functions are provided,like gsl_complex_sin(x). There alsoare functions for hyperbolic trigonometricfunctions, along with the relevantinverse functions.Now that you have the basics down,my next article will explore all the actualscientific calculations you can do. I’lllook at statistics, linear algebra, randomnumbers and many other topics.—JOEY BERNARD<strong>Linux</strong> JournaLon youre-ReaderCustomizedKindle and Nookeditionsnow availablee-ReadereditionsFREEfor SubscribersLEARN MORE


[ UPFRONT ]Rock Your Webcam Like It’s 1995Many Webcam applications exist for <strong>Linux</strong>. If youwant to play with self-portraits, there’s Cheese.If you want to set up a security system in youroffice, there’s Motion. But, if you just want tohave some fun, give HasciiCam a try.HasciiCam does for Webcams what aalib+mplayerdoes for video files. It renders your live videodirectly into ASCII. It also has a feature to createa live Web feed of your ASCII video for the wholeworld to see! HasciiCam might not be the mostpractical application to use with your Webcam,but if you ever have been fascinated with ASCII art, it might be the most fun. It’s mostlikely packaged with your favorite distro, but if not, the source is available from itsWeb site: http://dyne.org/software/hasciicam.—SHAWN POWERSMarketplace MagicIf you love shopping in the Android Marketplace buthate typing on that tiny keyboard, you might likethe Web interface to the Marketplace. This isn’t anew feature, but it’s one I didn’t know about, so itseemed apropos to share with the class.On a desktop computer, simply browse overto http://market.android.com, and log inwith your Google account. (The same accountyou use on your Android phone.) You can selectan app and have it automatically installed onwhichever Android device you like! There’s noneed to touch your phone; it automatically willinstall the app you chose from the Web site.As you can tell from the screenshot, I found an excellent productivity app that will be on mynew Galaxy S2 in a few moments. Just one more reason to love Android!—SHAWN POWERS28 / FEBRUARY <strong>2012</strong> / WWW.LINUXJOURNAL.COM


Keynote:Scott McNealyCo-founder, Sun MicrosystemsOther Confirmed SpeakerschriS aNiSzcykopen Source Manager, TwitterJiM JagielSkiPresident, Apache Software FoundationBdale garBeeChief Technologist for oS and linux, HPdr. douglaS MaughaNDirector, DHS Cyber Security DivisionJoNathaN leBlaNcTechnology Evangelist, PayPalcarol SMithoS Programs Manager, Googledave aBrahaMSFounding Member, boost.orgTMJOin uS fOr the beSt SpeaKerS, tOpiCS and SOCial eventS in the COuntrypresented byTMposscon.orgMARCH 28 & 29, <strong>2012</strong> | ColuMbiA, SCBringing Open Source to the SoutheastDevelopers – eDucators – It leaDers In busIness, government, healthcare anD securIty


COLUMNSAT THE FORGESimple Appswith SinatraREUVEN M.LERNERWriting a small Web app? Consider Sinatra, a micro-frameworkthat makes Web development quick and easy.For the past month or two, I have beenteaching my nine-year-old daughter toprogram in Ruby. She has enjoyed it agreat deal, as have I. To be honest, I’vebeen a bit surprised by how much shehas gotten out of the experience andhow excited she is to be discovering thejoy of programming.Not surprisingly, I’m planning tointroduce her to the wonderful worldof Web development. But given thatwe’re working with Ruby, I was a bitconcerned. After all, the de factostandard for Web development in Rubyis Rails, and although I think Railsis a wonderful framework, it alwayshas assumed that newcomers were atleast familiar with the basics of Webdevelopment. Modern versions of Rails,with CoffeeScript, Sass stylesheets, anasset pipeline and many other features(which are wonderful in their own right)would pose a pedagogical challenge forboth my daughter and me.Just as I was trying to figure out howto introduce Rails or whether I shouldgive up on the idea of teaching herWeb development at all, I realized Ihad been overlooking a gem (no punintended) of software that is perfect forthese purposes—Sinatra. Sinatra hasbeen around for a few years already,but I never really gave it much thought.It turns out, however, that Sinatra is aseasy (or easier!) than the CGI programs Iwrote back in the early days of the Web,supports a huge number of plugins andfeatures, can be hosted easily on Herokuor Phusion Passenger and is a great dealof fun to work with.So in this article, I’m taking a look atSinatra. I describe how to configure andinstall it and explain why I’m convincedthat whenever I now need to do a quickand-dirtyWeb application, Sinatra (andnot Rails) will be my tool of choice.Sinatra Origins and InstallationSinatra first was written by BlakeMizerany, a longtime Ruby programmer30 / FEBRUARY <strong>2012</strong> / WWW.LINUXJOURNAL.COM


COLUMNSAT THE FORGESinatra makes it ridiculously easy to puttogether Web applications, because that’sall it is meant to do.who currently works at GitHub.Sinatra is an example of both amicro-framework—that is, a Webdevelopment framework that handlesjust the bare minimum of what youmight want to do—and also a domainspecificlanguage (DSL). A DSL givesyou a narrow, but deep, vocabularyfor writing programs in a particulardomain, allowing you to concentrateon the high-level development process,rather than the nitty-gritty details.Sinatra makes it ridiculously easyto put together Web applications,because that’s all it is meant to do. Atthe same time, it’s still written in Ruby,meaning that you have access to thelanguage’s core functionality, alongwith gems, ranging from ActiveRecord(from Rails) to templates to networkcommunicationsystems.To create a simple Sinatra application,you first have to install the Sinatra gem,either as root or (if you are using rvm,the wonderful Ruby version manager) asa nonroot user:gem install sinatraWith that in place, you’re ready toget started! You can create a file thatlooks like this:#!/usr/bin/env rubyrequire 'rubygems'require 'sinatra'get '/' do"Hello"endIt doesn’t get easier than this, right?The first line indicates that you wantto execute Ruby. The second and thirdlines load the Gem libraries and also the“sinatra” gem itself. The third line definesa route, such that if a Web browser usesthe GET method to request /, the methoddefined in the “do” block is executed.Run this program, and you see this:~/Desktop $ ./atf-sinatra.rb== Sinatra/1.3.1 has taken the stage on 4567 fordevelopment with backup from Thin>> Thin web server (v1.3.1 codename Triple Espresso)>> Maximum connections set to 1024>> Listening on 0.0.0.0:4567, CTRL+C to stopIn other words, you’re now runninga live Web application, via an HTTPserver (Thin, if you have installed iton your system—otherwise, Sinatratries to find something else). As Imentioned previously, Sinatra makesWWW.LINUXJOURNAL.COM / FEBRUARY <strong>2012</strong> / 31


COLUMNSAT THE FORGEListing 1. atf-sinatra.rb#!/usr/bin/env rubyrequire 'rubygems'require 'sinatra'require 'erb'get '/' do@first_number = rand(5000)@second_number = rand(@first_number)@operation = %w(+ - *).sampleerb :indexendpost '/answer' do@first_number = params[:first_number].to_i@second_number = params[:second_number].to_i@operation = params[:operation].to_s@user_answer = params[:user_answer].to_i@right_answer = @first_number.send(@operation, @second_number)erb :answerenditself accordingly. If you want to havesuch functionality, you can install the“shotgun” gem, which restarts theapplication with each request.Sinatra uses the common Rackinterface for Web applications underRuby. This means that a Sinatraapplication, even one as simple as whatI have written here, can be deployedanywhere that supports Rack, such asthe various Ruby-flavored HTTP servers(for example Phusion Passenger) or onhosting sites like Heroku.Of course, Web applications tendto receive input from the user. Simpleparameters can come as part of theURL, following a question mark (?)character. A POST request also cancontain parameters, but they are sent ina separate channel. Sinatra can handleboth of these:get '/' do"Hello, #{params[:name]}"endIf I invoke this as:the development of Web applicationseasier and faster than ever was thecase, even with CGI programs, and withmany more capabilities.You can stop the application bypressing Ctrl-C. Note that unlike Railsin development mode, Sinatra doesn’t(by default, at least) notice when theprogram has changed and updatehttp://localhost:4567/?name=Reuvenmy Web browser happily prints the text:Hello, ReuvenViewsNow, it’s certainly possible to produce aworking Web application using just the32 / FEBRUARY <strong>2012</strong> / WWW.LINUXJOURNAL.COM


COLUMNSAT THE FORGEFortunately, Sinatra supports not just ERbtemplates, but also a number of other types,including popular Haml templates.above. But, the output in this example isfairly limited. It’s safe to assume that inanything more sophisticated than a “Hello,world” program, you’ll want to use atemplating system to display your views.Fortunately, Sinatra supports not just ERbtemplates, but also a number of othertypes, including popular Haml templates.For example, let’s say you want your“GET /” handler to invoke an ERbtemplate, and that you will call thetemplate “index”. Create a subdirectorynamed views in the same directorywhere the Sinatra application islocated. Then, put a file named index.erbin the views directory, and put sometext into it:Sinatra indexSinatraHello, Finally, modify the “get” handlermethod such that it both uses the ERbtemplate and so that it assigns theinstance variable @name with something:get '/' doerb :index@name = params[:name]endAs is the case in all ERb templates, suchas in Rails, instance variables (that is, thosestarting with @) are passed untouchedto the template. Your ERb template maycontain any HTML you want, as well asRuby code inside of the delimiters.One bug (or feature?) that kept biting mewas the lack of delimiters, asin Rails. I quickly trained my fingers notto type it, but I admittedly was confusedwhen Sinatra gave me a stack backtracethat was less than obvious.A Simple ApplicationSo, what kinds of simple applicationscan you create with Sinatra? You can,of course, use a database on the backend or any number of other features,such as sessions or authentication. But,there are a lot of little applications I’vewritten during the years that didn’trequire much in the way of server-sideprogramming. One example is a simpleWWW.LINUXJOURNAL.COM / FEBRUARY <strong>2012</strong> / 33


COLUMNSAT THE FORGEListing 2. index.erbSinatra MathSinatra Math math-practice program I wrote for mydaughters several years ago using Rails.How easy would it be to produce such aprogram in Sinatra?First, you need two different handlers,one for GET requests and one to POST theanswers. The GET handler will choose tworandom numbers and a math operation toperform on them. This handler then willdisplay the results as a math problem on apage of HTML, providing a form in whichthe user can submit the answer. My GEThandler looked like this:get '/' do@first_number = rand(5000)@second_number = rand(@first_number)@operation = %w(+ - *).sampleerb :indexendThis code sets three instancevariables, the values of which thenare available for display in the ERbtemplate, which will be index.erb in theviews directory. The first number can beanything up to 5,000, and the secondnumber must be smaller than the first.I then allowed for addition, subtractionand multiplication. Doing division withtwo 4-digit numbers seemed like astretch for my children at this stage,even by my tough standards. By givingthe first number as the parameter tothe second call to rand(), you ensurethat the second number will be nolarger than the first—an importantconsideration when producingelementary-school problems.index.erb (Listing 2) is, as you wouldexpect, rather plain. The most interestingpart is the HTML form, into which users34 / FEBRUARY <strong>2012</strong> / WWW.LINUXJOURNAL.COM


COLUMNSAT THE FORGEwill provide their answers:Listing 3. answer.erbNotice how the original operands andoperation are kept as hidden fields in theform. This allows you to avoid putting themin the session and makes debugging easier.The answer-checking program, whichexpects to receive three parameters(first_number, second_number andoperation), then grabs them andcalculates the right answer:Problem: Your answer: Right answer: You got it right!Sorry, you got it wrong.post '/answer' do@first_number = params[:first_number].to_i@second_number = params[:second_number].to_iTry again?@operation = params[:operation].to_s@user_answer = params[:user_answer].to_i@right_answer = @first_number.send(@operation, @second_number)erb :answerendoperator into a symbol and then sendthat symbol to the first operand. Inother words, the Ruby calculation:5 + 3There is a bit of magic in the abovecode. Because operators (such as +)are methods in Ruby, you can turn theis always turned into:5.send(:+, 3)WWW.LINUXJOURNAL.COM / FEBRUARY <strong>2012</strong> / 35


COLUMNSAT THE FORGESinatra is packed with features. It’s hard toexaggerate just what this tiny framework can do.But in this case, you do it explicitly,turning the string into a symbol.It took me just a few minutes to throwtogether this program. With a bit moretime, it’s hard to say just what the limitwould be.Other FeaturesSinatra is packed with features. It’s hard toexaggerate just what this tiny frameworkcan do. For example, if you want to usesessions, such that you can carry user datafrom one HTTP request to the next, youcan enable the “sessions” feature:enable :sessionsThis creates a hash-like object (“session”)into which you can store or retrieve anyRuby object—although it’s generallyconsidered to be a good idea to store onlysimple objects, keeping more seriousones inside of a database or object store.Sinatra also provides sophisticatedrouting, such that you can tell it to acceptrequests for a particular URL templateand then put one or more elements ofthe template into parameters. Sinatraprovides before-and-after filters, whichcan be activated on some or all of thehandlers. Really, the number of simpleapplications that are appropriate forSinatra is almost limitless.ConclusionIf you want to throw together a simpleWeb application, but don’t want theoverhead of Rails, you seriously should trySinatra. It has a huge number of features,great documentation, lots of communitysupport, and it can be deployed just abouteverywhere Rails can be. I’m planning to useSinatra for many small projects in the future,both with and without my kids. It’s not aspowerful as Rails, but that’s just the point!■Reuven M. Lerner is a longtime Web developer, architectand trainer. He is a PhD candidate in learning sciences atNorthwestern University, researching the design and analysisof collaborative on-line communities. Reuven lives with hiswife and three children in Modi’in, Israel.ResourcesThe Sinatra home page is athttp://sinatrarb.com. From there,you also can get to the Sinatra book(http://sinatra-book.gittr.com) andthe community-supported Rack(http://sinatra-book-contrib.com).There are similar small frameworks inPython, if you’re less of a Rubyist, suchas “Denied”. I have played with theseonly briefly, but they’re worth examiningif you and/or your project works betterwith Python.36 / FEBRUARY <strong>2012</strong> / WWW.LINUXJOURNAL.COM


COLUMNSWORK THE SHELLThat’s actually the problem with crossword-puzzlefinderapps. There simply are too many words inthe English language.system, it’ll still be lightning fast, evenwith 128,985 lines of data.aerialaerierLooking for WordsLet’s start by looking up that partial matchfor “feline” from earlier. Fortunately, wedon’t need to look much further thangrep, because we can express what weneed with a regular expression:That’s better, except there are a lot of wordsthat match this pattern. In fact, it’s surprisinglycommon. How common? Let’s see:$ grep -E '^.e.i..$' words.txt | wc -l264$ grep -E '.e.i..' words.txtThe problem is, a quick glance at the outputreveals that this pattern isn’t good enough:abbreviateaberdevineabiogenistabstemiousacademicalTo root the search so that it’s an exactmatch, not a portion within a larger word,we need to root the regular expression. Thisis done with ^ to denote the beginning ofthe line and $ to denote the end:Sheesh, there are 264 possibilities.Drop in another letter though, and it’s abit more manageable:$ grep -E '^.e.in.$' words.txt | wc -l58One more letter, and althoughtheoretically we should be able toguess it anyway, at least the choices arereduced to a viewable list:$ grep -E '^.elin.$' words.txtfelinehelingreline$ grep -E '^.e.i..$' words.txtaeciumaedileThat’s actually the problem withcrossword-puzzle-finder apps. Theresimply are too many words in the EnglishWWW.LINUXJOURNAL.COM / FEBRUARY <strong>2012</strong> / 39


COLUMNSWORK THE SHELLlanguage. Still, it’s quite possible that forsome letter combinations, even having mostletters missing still produces a short list:$ grep -E '^...cc.t.$' words.txtbraccateplaccatespiccatostaccatostoccataThis should be motivation to learn howto solve as much of that darn crosswordpuzzle as possible before turning to ourlittle shell solution!satscatscattsoststaccatotatacotacttaotattatttattoototooWords With FriendsGames like Scrabble and Words WithFriends present an opposite problem. Weknow all the letters; we just want to figureout what words we can create with them.On first blush, the solution could be assimple as searching the words databasefor all words that contain zero or oneoccurrence of each letter in the sequence.Not so fast though—look at this:$ grep -E '^s*t*a*c*c*a*t*o*$' words.txtaaactatcatcoooosacThere are two problems here. The firstis that the * actually is shorthand for zeroor more matches, and the second is thatthe letters in the pattern are analyzed inorder of occurrence. So, although “tao”is a valid word extracted from the letters“STACCATO”, the word “tots” never willbe found, because the letter s appearsbefore the others in the pattern.The first problem can be solvedby making a more complex regularexpression: X{0,1} means zero orexactly one occurrence of the letter X inthe pattern. It’s definitely more complex:$ grep -E '^s{0,1}t{0,1}a{0,1}c{0,1}c{0,1}a{0,1}t{0,1}o{0,1}$'➥words.txtaaact40 / FEBRUARY <strong>2012</strong> / WWW.LINUXJOURNAL.COM


COLUMNSWORK THE SHELLHowever, a more interesting way to try to addressthis is to take a complete left turn and lose thisincreasingly complicated regular-expressionapproach by using a chained set of simpleone-letter grep patterns instead.atcatsacsatscatsoststaccatotatacotacttaotattoThe second problem of letter order isa lot harder to solve. We could generaterandom sequences, but some quick mathshows that if we have ten characters,that’s 10*9*8*7*6*5*4*3*2 possiblecombinations—a lot!However, a more interesting way totry to address this is to take a completeleft turn and lose this increasinglycomplicated regular-expression approachby using a chained set of simple onelettergrep patterns instead.That’s not quite what we’ll do though,because the first thing we need to do isscreen out all words that contain lettersnot in our acceptable set. That’s donewith the set notation:$ grep -vE '[^staccato]' words.txtaaaccoastaccoastsaccostaccostsThat’s still not quite right, because we’renot taking into account the frequency ofindividual letters (note that “accoasts” hastwo occurrences of the letter s, but there’sonly one in our original letter set).Let’s wrap this up here for this month,however. Next month, I’ll dig deeper intothe problem and see if I can come upwith some sort of smart solution.■Dave Taylor has been hacking shell scripts for more than30 years. Really. He’s the author of the popular Wicked CoolShell Scripts and can be found on Twitter as @DaveTaylorand more generally at http://www.DaveTaylorOnline.com.WWW.LINUXJOURNAL.COM / FEBRUARY <strong>2012</strong> / 41


COLUMNSHACK AND /PasswordCracking withGPUs, Part II:Get CrackingKYLE RANKINYour hardware is ready. Now, let’s load up some software andget cracking.In Part I of this series, I explained howpassword cracking works in general termsand described my specific passwordcrackinghardware. In this article, I diginto the software side of things anddescribe how to put that hardware touse cracking passwords. I also discuss thetwo main types of attacks: dictionary andbrute-force attacks. As I describe eachattack, I also give specific examples ofhow I used the software to attack phpass,the hashing algorithm currently used forPHP-based software like WordPress.For the purposes of this article, I createda sample WordPress blog on my server andcreated a few custom accounts—somewith weak passwords and others with trulyrandom passwords. Then, I went into thedatabase for the site and pulled out thephpass password hashes for each accountand put them into a file that looked like this:$P$BpgwVqlfEwuaj.FlM7.YCZ6GQMu15D/$P$BGMZP8qAHPjTTiTMdSxGhjfQMvkm2D1$P$BOPzST0vwsR86QfIsQdspt4M5wUGVh.$P$BjAZ1S3pmcGOC8Op808lOK4l25Q3Ph0$P$BPlIiO5xdHmThnjjSyJ1jBICfPkpay1$P$BReStde51ZwKHVtiTgTJpB2zzmGJW91The above hashes are legitimate phpasshashes created from six-character passwords.I could tell you the passwords, but that woulddefeat the fun of cracking them yourself.Proprietary Video DriversFor those of you who, like me, believein open-source software, this nextsection may be a bit disappointing. To42 / FEBRUARY <strong>2012</strong> / WWW.LINUXJOURNAL.COM


COLUMNSHACK AND /At first glance, it can be a bit confusing, asyou can choose from hashcat, oclHashcat,oclHashcat-plus, oclHashcat-lite and evensoftware called maskprocessor.get hardware-accelerated passwordcrackingsoftware working on yoursystem, you need to install theproprietary video drivers from eitherAMD or NVIDIA. That said, if you alreadyhave been using your system for Bitcoinmining, you already have the driversand libraries you need, so you can skipto the next section about Hashcat.Honestly, you also could just follow theBitcoin mining HOWTOs for <strong>Linux</strong>, andthat would describe how to get all thedrivers and libraries you need.Many modern desktops make itrelatively easy to pull down and install theproprietary video drivers. For instance,an Ubuntu desktop will prompt you thatrestricted drivers are available to installboth for AMD and NVIDIA cards. Mostother popular distributions provide gooddocumentation on how to pull down theproprietary drivers as well. In the worstcase, you may have to download thesoftware directly from AMD or NVIDIA andinstall it that way—they both have clearinstructions and software available for<strong>Linux</strong> just like for other OSes.Once you have the proprietary driversinstalled, you also need the AMD APP SDKfor its OpenCL libraries or the NVIDIA CUDAlibraries, depending on who made yourvideo card. You likely will need to get theselibraries directly from the AMD or NVIDIAWeb sites. The install is straightforwardthough. In my case, I downloaded theAMD-APP-SDK-v2.5-lnx32.tgz file fromAMD, extracted it, and ran the providedInstall-AMD-APP.sh shell script as root.HashcatMany different password-cracking suitesexist both for CPU- and GPU-basedcracking. After reviewing all the options, Idecided on the Hashcat family of crackingtools available at http://hashcat.net.On the site, you will see that a numberof different tools are available. At firstglance, it can be a bit confusing, as youcan choose from hashcat, oclHashcat,oclHashcat-plus, oclHashcat-lite andeven software called maskprocessor.Each program has its purpose though,depending on what you intend to do:hashcat:n CPU-based, so slower than theWWW.LINUXJOURNAL.COM / FEBRUARY <strong>2012</strong> / 43


COLUMNSHACK AND /GPU-based software.maskprocessor:n Supports the widest range ofhashing algorithms.n Generates dictionaries based onpatterns you supply.oclHashcat:n GPU-based password cracker.n Not a password cracker in its own right,but can pipe output to oclHashcat-plusfor a brute-force attack.n Supports a moderate number ofhashing algorithms.n Built-in support for dictionary,brute-force and mask attacks.oclHashcat-plus:n GPU-based.n Supports the most hashing algorithmsof the GPU-based hashcat crackers.n Optimized for dictionary attacksagainst multiple hashes.n Can support dictionary input from apipe, so brute-force is possible.oclHashcat-lite:n GPU-based.n Optimized for attacks against a singlepassword hash.n Fastest of the hashcat family, but withthe most-limited password hash support.Even with the above lists, it may notalways be clear which software to use.Basically, it comes down to what type ofpassword you want to crack and whatkind of attack you want to use. Thepage on hashcat.net devoted to eachpiece of software provides a list of thehashing algorithms they support alongwith benchmark speeds of how manycomparisons they can do per second ondifferent types of hardware. For a givenpassword hash, go through those pagesand see which type of Hashcat softwaresupports your hash and has the highestbenchmarks. Beyond that, use oclHashcatfor mask or brute-force attacks againstmultiple hashes, oclHashcat-lite for singlehashes or oclHashcat-plus if, as was thecase with me, it’s the only GPU-acceleratedversion that supported your hash.Once you decide which type of Hashcatsoftware to use, installation is relativelysimple, if old-school. Just download the .7zpackage that corresponds to the software,and use the 7za command-line tool (whichshould be packaged for your distribution) toextract it. The software will extract into itsown directory that provides 32- and 64-bit44 / FEBRUARY <strong>2012</strong> / WWW.LINUXJOURNAL.COM


COLUMNSHACK AND /versions for both <strong>Linux</strong> and Windows. Ifyou have NVIDIA hardware, you will use thebinaries that begin with cuda; otherwise,you will use the versions that start with ocl.The directory also will contain a numberof example hashes and dictionaries andexample shell scripts you can use to makesure your libraries and drivers are in place.For instance, here’s the example providedwith the oclHashcat-plus software forcracking a phpass hash on a 64-bit system:$H$9y5boZ2wsUlgl2tI6b5PrRoADzYfXD1:hash234Status.......: CrackedInput.Mode...: PipedHash.Target..: $H$9y5boZ2wsUlgl2tI6b5PrRoADzYfXD1Hash.Type....: phpass, MD5(Wordpress), MD5(phpBB3)Time.Running.: 1 secTime.Util....: 1008.2ms/0.0ms Real/CPU, 0.0% idleSpeed........: 65009 c/s Real, 619.7k c/s GPURecovered....: 1/1 Digests, 1/1 SaltsProgress.....: 65543Rejected.....: 0cat example.dict | ./oclHashcat-plus64.bin -m 400 example400.hashHW.Monitor.#1: 0% GPU, 47c TempHere’s what the command outputlooked like when I ran the exampleagainst the 32-bit version on my test rig:cat example.dict | ./oclHashcat-plus32.bin -m 400 example400.hashoclHashcat-plus v0.06 by atom starting...Hashes: 1Unique salts: 1Unique digests: 1Bitmaps: 8 bits, 256 entries, 0x000000ff mask, 1024 bytesRules: 1GPU-Loops: 128GPU-Accel: 16Password lengths range: 1 - 15Platform: AMD compatible platform foundWatchdog: Temperature limit set to 90cDevice #1: Cayman, 2048MB, 0Mhz, 22MCUDevice #1: Allocating 52MB host-memoryDevice #1: Kernel ./kernels/4098/m0400.Cayman.32.kernel (274238 bytes)Starting attack in wordlist stdin mode...Started: Mon Dec 5 21:12:03 2011Stopped: Mon Dec 5 21:12:04 2011In this case, the password was hash234.For all of the hashcat commands, it’s simpleenough just to open a terminal and changeto the directory you extracted and runthe commands locally from there. At thebeginning of the command output, you willbe able to see what GPUs the software candetect. If you have multiple GPUs in use(even if they aren’t chained), it should findthem automatically. If it can’t find your GPU,you will need to revisit how you installedyour proprietary drivers and extra libraries.Dictionary AttacksThe first attack you should try is adictionary attack. With a dictionaryattack, you provide the cracking softwarewith a dictionary full of possiblepasswords to try, such as all the wordsin the English dictionary. The crackingWWW.LINUXJOURNAL.COM / FEBRUARY <strong>2012</strong> / 45


COLUMNSHACK AND /software then tries each dictionary worduntil one matches your hash. Since thenumber of combinations in a dictionaryattack is much smaller than with a bruteforceattack, dictionary attacks completemuch faster. As an example, when Iwas first researching this article, I let abrute-force attack run for days againsta sample set of hashes without crackingone of them. I was able to crack threeout of the five hashes with a dictionaryattack in less than a minute.To run a dictionary attack withoclHashcat-plus, first run the commandwith the --help argument. That willprovide you with the number thatcorresponds to the hash algorithm youwant to crack. In the case of phpass, thatnumber is 400. Then, run the commanda second time and specify the passwordhash to use with the -m option, thefile in which to store the recoveredpasswords with the -o option, and thenlist the file that contains your hashesand the file or files you want to use as adictionary. Here’s an example dictionaryattack against phpass hashes:/path/to/oclHashcat-plus32.bin -m 400 -o recovered_hashes➥example400.hash example.dictIf I had multiple dictionaries, I could listall of them on the command line or evenuse a shell glob. A dictionary attack is onlyTry Before You Buy!Benchmark Your Code on Our GPU Cluster withAMBER, NAMD, or Custom CUDA CodesConfigure your WhisperStation or Cluster today!www.microway.com/tesla or 508-746-7341NEW Microway MD SimCluster with8 Tesla M2090 GPUs, 8 CPUs and InfiniBand30% Improvement Over Previous Teslas46 / FEBRUARY <strong>2012</strong> / WWW.LINUXJOURNAL.COMGSA ScheduleContract Number:GS-35F-0431N


COLUMNSHACK AND /as good as its dictionaries, but a numberof good password dictionaries are availableon the Web that you can find with a quicksearch for “password cracking wordlist”.Calculating Cracking SpeedBefore I discuss brute-force attacks indetail, it’s important to learn how toestimate how long a particular bruteforceattack will take. With a bruteattack, you aren’t just going througha dictionary of words, you are actuallytrying all possible combinations of aset of characters. In researching thearticle, I wasted days attempting abrute-force attack against an eightcharacterpassword before I finallydid the math and realized it wascompletely impractical.The first step is to figure out how fastyour hardware can crack a particular typeof hash. As you will discover, the numberof comparisons per second your hardwarecan perform will vary widely depending onthe hash type, so start a sample bruteforceattack just long enough to get a bitof progress output, and then press Ctrl-cto exit. In my case, because I’m usingoclHashcat-plus, I needed to downloadand extract the maskprocessor softwarefrom hashcat.net, so it, combined withoclHashcat-plus, could perform a bruteforceattack against phpass (don’t worryabout the command syntax for now, IMicroway’s Proven GPU ExpertiseThousands of GPU cluster nodes installed.Thousands of WhisperStations delivered.Award Winning BioStack – LSAward Winning WhisperStation Tesla – PSC with 3D‘11AWARDBESTBest NewTechnologyns/Day (Higher is Better)CPU + GPUCPU Only1.070.332.020.653.541.301 Node2 Nodes 4 NodesNAMD F1-ATP Performance GainVisit Microway at SC11 Booth 2606WWW.LINUXJOURNAL.COM / FEBRUARY <strong>2012</strong> / 47


COLUMNSHACK AND /discuss the specifics later):/path/to/mp32.bin -1 ?d?l?u ?1?1?1?1?1?1 | \/path/to/oclHashcat-plus32.bin -m 400 \-o recovered_hashes phpass-hashesoclHashcat-plus v0.06 by atom starting...Hashes: 6Unique salts: 6Unique digests: 6Bitmaps: 8 bits, 256 entries, 0x000000ff mask, 1024 bytesRules: 1GPU-Loops: 128GPU-Accel: 16Password lengths range: 1 - 15Platform: AMD compatible platform foundWatchdog: Temperature limit set to 90cDevice #1: Cayman, 2048MB, 0Mhz, 22MCUDevice #1: Allocating 264MB host-memoryDevice #1: Kernel ./kernels/4098/m0400.Cayman.32.kernel (274238 bytes)Starting attack in wordlist stdin mode...Status.......: RunningInput.Mode...: PipedHash.Type....: phpass, MD5(Wordpress), MD5(phpBB3)Time.Running.: 10 secsTime.Util....: 10001.4ms/180.8ms Real/CPU, 1.8% idleSpeed........: 315.3k c/s Real, 351.4k c/s GPURecovered....: 0/6 Digests, 0/6 SaltsProgress.....: 3153920Rejected.....: 0HW.Monitor.#1: 96% GPU, 54c TempThe output line to pay attention to is theline that begins with Speed. As you can seefrom that output, my GPU can do around350,000 comparisons per second, so I’ll usethat number for the rest of my calculations.One good site I’ve found for doing crackingestimates is http://www.lockdown.co.uk/?pg=combi. This site describes all sortsof different character sets and passwordlengths, and it describes how long anythingfrom a single Pentium CPU to a mythicalgovernment supercomputer might take tobrute-force all combinations. Otherwise,the math is pretty straightforward. Just takethe number of characters in your characterset (for instance, all lowercase letters wouldequal 26), then figure out how long of apassword you want to brute-force, then raisethe first number to the power of the second.So, for instance, all mixed-casealphanumeric characters (A–Za–z0–9)equals 62 characters. If I wanted to bruteforce a six-character password, thatwould be 62 6 = 57 billion combinations.If you divide 57 billion combinations by asystem that can do 350,000 comparisonsa second, you get approximately 45 hoursto complete the brute-force attack. That’snot bad, but let’s do the same mathfor eight-character passwords: 62 8 =218 trillion combinations.At 350,000 comparisons per second, itwould take me approximately 7,200 days,or 19 years, to complete the attack. Onthe plus side, for another $250, I couldcomplete the attack in less than 10 years!If you add symbols to your brute-forceattack, the number jumps to 7.2 quadrillioncombinations, or around 652 years.48 / FEBRUARY <strong>2012</strong> / WWW.LINUXJOURNAL.COM


COLUMNSHACK AND /Brute-Force AttacksOnce you’ve figured out whethera brute-force attack will completein your lifetime, the next step is torun maskprocessor and tell it whatkind of word list to generate. Themaskprocessor command supports anumber of common character sets bydefault with the following symbols:n ?d = all decimals (0–9).n ?l = lowercase characters (a–z).n ?u = uppercase characters (A–Z).n ?s = symbols.You also can define a custom characterset with -1 (or -2, -3) and then use ?1to use that custom set. For instance, if Iwanted to enumerate through all threecharacterpasswords made up of lowercasecharacters and numbers, I could type:/path/to/mp32.bin -1 ?d?l ?1?1?1000001. . .zzyzzzIn my example brute-force attack, Iwanted to run through all combinationsof uppercase, lowercase and numbers ina six-character password. The resultingmaskprocessor command would be:/path/to/mp32.bin -1 ?d?l?u ?1?1?1?1?1?1Then, I would pipe the output of thatcommand to oclHashcat-plus:/path/to/mp32.bin -1 ?d?l?u ?1?1?1?1?1?1 | \/path/to/oclHashcat-plus32.bin -m 400 \-o recovered_hashes phpass-hashesAs with my dictionary attack, the -moption specifies I want to crack phpasshashes, the -o lists the file in which Iwant to store my recovered hashes, andfinally, I specify the file that contains thephpass hashes to crack. On my hardware,it took around two days to run fullythrough the above brute-force attack.Now you should be ready to get cracking,but as you’ll find, the world of passwordcracking can get pretty dense, pretty quickly.In my next and final part of the series, I willdiscuss how you can tune the above attacksto get better performance, and also how toblend both dictionary and brute-force attacksto get the best of both worlds.■Kyle Rankin is a Sr. Systems Administrator in the San FranciscoBay Area and the author of a number of books, including TheOfficial Ubuntu Server Book, Knoppix Hacks and Ubuntu Hacks.He is currently the president of the North Bay <strong>Linux</strong> Users’ Group.ResourcesHashcat: http://hashcat.netPassword Recovery Speeds:http://www.lockdown.co.uk/?pg=combiWWW.LINUXJOURNAL.COM / FEBRUARY <strong>2012</strong> / 49


COLUMNSTHE OPEN-SOURCE CLASSROOMMoodle.It Works.SHAWN POWERS<strong>Linux</strong> has become mainstream in server rooms, commonplaceon the desktop and dominant in mobile devices. Unfortunately,it’s still a rarity in the classroom. This month, I start a columndedicated to <strong>Linux</strong> in education. Grab a desk, sharpen yourpencils and join me!LJ’s newest column, the one you’recurrently reading, is dedicated toeducation. Each month, I plan to equipreaders with ways to improve studentachievement using freely available tools.Schools are required to function on lessand less money every year, yet due to thedemand for technologically proficientstudents, they need to spend moreand more every year on technology. Inturn, there is no money left to invest intraining the teachers. That is one reasonopen-source software is such a perfectfit for education. If money is spent onpreparing teachers rather than buyingsoftware, we will have state-of-the-arttechnology and teachers fully preparedto use it. That’s why this column wasborn. If our kids grow up with opensourcetools, they’ll turn into adultswho understand the difference betweeninvesting in software versus investingin people. Basically, we want to takeover the world, and we want to startwith the kids.Moodle is an open-source LearningManagement System (LMS) designedfor students of various ages. Theconcept of LMS isn’t a new one, andit isn’t limited to the FOSS world.Many colleges are using systems likeBlackboard (http://www.blackboard.com)to facilitate a virtual classroomenvironment. Blackboard offers manyfeatures, including collaboration,document management, informationdissemination and even live discussions.Unfortunately, those awesome featurescome at a substantial price. Enter: Moodle.<strong>Linux</strong> <strong>Journal</strong> has covered Moodlebefore, but it has matured so muchthrough the years that it deservesanother look. Moodle started as a littleproject teachers might implement in50 / FEBRUARY <strong>2012</strong> / WWW.LINUXJOURNAL.COM


COLUMNSTHE OPEN-SOURCE CLASSROOMtheir classrooms, but it has grown into aproduct used at multiple universities andschools around the world.ways—flexibility is one of Moodle’sstrengths. Every instructor doesn’t haveto use it the same way.What Does It Do?Figure 1 shows a demonstration courseset up in Moodle. Instructors can setup their “classrooms” in a variety ofways. In the Romeo and Juliet example,the instructor has given a basic outlineof the class with appropriate links fordownloading assignments, taking on-linequizzes and on-line journaling. Figure 2shows a demo course on Film Studies. Inthis example, the instructor has brokenup the class into sections (apparently,each section represents a class session).Classes can be broken up in severalWhy Would a School Choose Moodle?Let’s be honest. For most <strong>Linux</strong> <strong>Journal</strong>subscribers, this one is simple. Whenit comes to school boards and schooladministrators, the argument, “Becauseit’s open source!”, doesn’t really meanmuch. Certainly Moodle goes along withthe traditional reasons an organizationmight choose open source: the initial costis lower, the maintenance cost is lower,Figure 1. Sample Course, Showing One PossibleLayoutFigure 2. Sample Course, Showing a DifferentLayoutWWW.LINUXJOURNAL.COM / FEBRUARY <strong>2012</strong> / 51


COLUMNSTHE OPEN-SOURCE CLASSROOMlicensing isn’t an issue, it’s free, free, freeand so on. But with Moodle, there areeven more reasons.Moodle was designed by teachers andmade for teachers. Although certainlythe commercial alternatives have largeties to the educational community,ultimately their goal is to make money.There’s nothing wrong with that, butit would be foolish to assume altruismwhen it doesn’t exist. Moodle, on theother hand, was designed fully andcompletely for the sole purpose ofimproving pedagogy. Moodle exists tobolster student achievement. Period.FeaturesThis is where Moodle really shines.Students can interact with the coursedirectly in their browsers. It means lesspaper waste and fewer lost assignments.It also means a single place for all courseinformation. Resources like handouts,photos, URLs and study notes can beplaced into the Moodle course andalways be available to students. Someinstructors simply use Moodle as anon-line repository for those types ofdocuments and don’t use the interactivefeatures Moodle offers. Nothing is wrongwith that approach, and Figure 1 showsthat type of Moodle in action.For teachers wanting to use Moodleas a more interactive platform, there aremany built-in features:n Assignments: students can uploadfinished assignments directly to theteacher, upload a file with commentsor additional information, or evencomplete an assignment directlyinto the on-line text editor (Figure3). The instructor decides how theassignment should be completed,and students complete it using theappropriate method. Moodle evenallows assignments to be completelyoff-line, with no interaction from thestudent. They simply are listed sothe student knows the assignmentmust be completed. Assignments aregraded by the instructor, and studentscan see the results on-line.n Gradebook: instructors can choose tokeep their gradebooks directly in theMoodle database. This allows studentsto see their grades at any time andalso interact with other modules thatcan assess materials and automaticallyenter grades.n Chat: instructors can have “officehours” when they are available forreal-time chat. Students also canuse the real-time chat feature tocollaborate with other students fromthe class. Chats can be designed tobe available constantly, or they canbe scheduled for specific times. Ifinstructors aren’t available, they stillcan go back and look at the chatlog to identify areas that need moreclassroom discussion (Figure 4).52 / FEBRUARY <strong>2012</strong> / WWW.LINUXJOURNAL.COM


COLUMNSTHE OPEN-SOURCE CLASSROOMn Forum: each course may have aforum available for discussion. Unlikechat, the forum is not real time. Likeany traditional forum, a user postsquestions or discussion items andwaits for responses.n Surveys and polls: Moodle offersinstructors the opportunity to asktheir students survey questions fromwithin the course. These surveyscould be used as an assessmentfor the teacher, as a way to gaugethe level of understanding on anupcoming assignment, or to getfeedback from students on any topicthe teacher desires. They also can beset to anonymous so the studentsaren’t identifiable, or they can beset to record user accounts withresponses (Figure 5).n Quizzes: Moodle quizzes are similar tosurveys, but they are designed morespecifically to be graded automatically.Quiz times can be specified to avoidat-home cheating, or they can be leftopen for students to take at theirleisure. The multiple-choice natureof Moodle quizzes makes gradingautomatic, so students see theirresults immediately.n Wikis: each course can have awiki that students are able to editcollaboratively. This wiki might containinformation gathered from multiplegroups that needs to be shared withthe class. Every enrolled user can editthe wiki, so it’s truly collaborative.n Workshops: assignments are set upas direct communication betweenstudents and instructors. Withthe workshop module, studentscan participate in peer reviewsand assessments. Instructors candesign specifically how studentscan respond to assignments in theworkshop module, so although itis a peer assessment, the processstill is guided by instructors. Figure6 shows an example of a possibleworkshop, with some criterion forthe users to assess.n Site design: the classroom featuresmentioned above are the meat andpotatoes of using Moodle. The Moodlecourse itself can be tweaked andmodified as well, however, to makethe site as useful as possible. Thelayout for the course page is designedusing blocks. Anyone familiar withcontent management systems likeDrupal or WordPress will understandthe concept of blocks. Figure 7 showsthe default layout of blocks in a newlycreated course. Blocks can be added,deleted and moved around. The functionof available blocks varies from calendarsto quiz results, and it includes the abilityto embed Flickr photos or YouTubevideos right into the Moodle page.WWW.LINUXJOURNAL.COM / FEBRUARY <strong>2012</strong> / 53


COLUMNSTHE OPEN-SOURCE CLASSROOMFigure 3. Assignments can be turned in usingvarious methods (or none at all).Figure 6. Peer assessments are guided by theinstructor, but performed by other students inthe course.Figure 4. Real-time chat enables students andinstructors to discuss material, even if in-personclassroom time isn’t possible.Figure 5. Surveys either can be anonymous ortracked by user.Figure 7. New courses start with this blocklayout, which can be modified by the instructor.54 / FEBRUARY <strong>2012</strong> / WWW.LINUXJOURNAL.COM


COLUMNSTHE OPEN-SOURCE CLASSROOMdesire, including adding content,changing layout and so on. Instructorsalso can decide how students canenroll in their courses. Students canbe added manually; they can be givena code that allows them to join, orthey even can gain access to a coursevia PayPal payment.n Server management: this is the onlypart that really requires a sysadminto manage. System backups, securitysettings, performance tweaks andother server-related tasks are doneby the administrator. Some of theseroles can be assigned to manageraccounts, but at some point, theserver maintenance leaves the realmof Moodle administration and entersthe domain of the IT department.This responsibility line obviouslywill be different for every case. It’spossible for Moodle to be centrallyadministered and accessed over theInternet for multiple locations. It’s justas possible for teachers to run Moodleon their classroom workstations andadminister it for their single class. Theimportant thing is to determine inadvance who will be in charge of whataspects of administration.Let’s Collaborate!You’ve seen Moodle and what it can do,but the power of open source isn’t just infree code. A huge community of Moodleusers is providing plugins, pre-packagedassignment modules, themes andcountless other enhancements forMoodle. Here are some great on-lineresources for teachers interested inimplementing and enhancing Moodle:n Moodle Docs (http://docs.moodle.org):this Moodle-hosted wiki is a collaborativeeffort to document every aspect ofusing Moodle. Whether you’re anadministrator trying to configure asecure install or a teacher trying toadd a quiz to your course, the MoodleDocs site is invaluable.n Moodle Plugins (http://moodle.org/plugins): Moodle offers an extensivenumber of features in the standardinstall, but it also allows for thirdpartyplugins to enhance courses. Theofficial repository for plugins is hostedon the Moodle.org Web site. Youcan find pre-packaged assignments,alternate course layouts, visual themesand additional blocks to customizeyour Moodle site or individual course.Once you become a Moodle user, youmay want to contribute back to thecommunity as well.n Course Exchange (http://moodle.org/course/view.php?id=15): many Websites share complete Moodle courses,but this particular exchange is hostedon the Moodle.org servers. There aredirect links to downloadable coursesand lists of Web sites offering courses56 / FEBRUARY <strong>2012</strong> / WWW.LINUXJOURNAL.COM


COLUMNSTHE OPEN-SOURCE CLASSROOMto download. In true “eat your owndog food” style, the Course Exchangeis actually a Moodle course openfor enrollment. You can enroll andparticipate in the Exchange.n Moodle Share(http://www.moodleshare.org):this third-party Web site offersan extensive selection of coursesavailable for download. Many of thecourses were designed by MinnesotaDistrict 287, using funding fromARRA Grant Funds. Hats off toDistrict 287 for sharing its resources!(Figure 8 shows a freely availablelesson from Moodle Share.)n Commercial Support(http://www.moodle.com): althoughMoodle itself is free in every sense ofthe word, there is a commercial sideas well. That doesn’t mean Moodlecomes crippled or feature-stripped, itjust means that commercial support isavailable if required. The moodle.comWeb site offers links to vendorsthat can host a Moodle install, offersupport for existing installs, train onthe use of Moodle or even becomecertified in Moodle itself. Again,these commercial options don’toffer any “Pro” features to Moodle;they’re just available if customersneed them.Finally, Let’s Take Over the World!The world we live in is one of on-linecollaboration, 24-hour interaction anddigital communication. Heck, you’rereading this right now on a digitaldevice, or you printed it from a digitalsource. Moodle is a perfect exampleof open-source ideals succeeding inregular, everyday life. The first steptoward an Open Source world is to getkids excited about open-source tools.Hopefully, the next steps will take careof themselves.Note: all images in this article are fromhttp://www.moodle.com.■Figure 8. Moodle Share offers complete courses,available to download and use at no cost.Shawn Powers is the Associate Editor for <strong>Linux</strong> <strong>Journal</strong>. He’salso the Gadget Guy for <strong>Linux</strong><strong>Journal</strong>.com, and he has aninteresting collection of vintage Garfield coffee mugs. Don’tlet his silly hairdo fool you, he’s a pretty ordinary guy andcan be reached via e-mail at shawn@linuxjournal.com. Or,swing by the #linuxjournal IRC channel on Freenode.net.WWW.LINUXJOURNAL.COM / FEBRUARY <strong>2012</strong> / 57


NEW PRODUCTSVariCAD, VariCAD ViewerOne of the most veteran CAD apps on the <strong>Linux</strong>platform, VariCAD, recently was upgraded toversion <strong>2012</strong>-1.0. The application is a 3-D/2-DCAD system for mechanical-engineering design,whose core features include tools for 3-Dmodeling and 2-D drafting and dimensioning;libraries of standard mechanical parts (ANSI,DIN); calculations of standard mechanical components; and tools for working withbills of materials (BOM) and blocks. Enhancements in version <strong>2012</strong>-1.0 includesignificant improvements to the GUI, improved and rebuilt 2-D printing dialog, new2-D dimensioning and editing of dimensions, improvements to DWG/DXF and STEPinterfaces, a batch printing module and a better 3-D modeling kernel. Also includedin the new update is VariCAD Viewer, a free combination viewer/converter/printingsoftware for working with 2-D DWG, DXF, 3-D STEP and 2-D/3-D VariCAD file formats.http://www.varicad.comSecPoint PenetratorThe SecPointPenetrator, upgradedto version 9.9, is avulnerability-scanningappliance that recentlywas beefed up withnew applicationsto boost corporatesecurity. The product helps companies prevent hackers from entering their serversand networks, as well as understand their vulnerabilities. The new version 9.9now includes the Google Hacking Database to identify whether sensitive companyinformation or files have been indexed by search engines, improved word lists forcracking (now more than 1.1 billion entries) and a tool to show whether a Wi-Finetwork is vulnerable. SecPoint Penetrator has no limit on the amount of auditingnor a limit on the number of IP addresses.http://www.secpoint.com58 / FEBRUARY <strong>2012</strong> / WWW.LINUXJOURNAL.COM


NEW PRODUCTSJosh Carter’sNew Programmer’s Survival Manual(Pragmatic Programmers)This one is for all of you recent comp sci grads! Think of JoshCarter’s new book—New Programmer’s Survival Manual: NavigateYour Workplace, Cube Farm, or Startup—like job insurance. Thebook is intended to introduce novice programmers to practicesthey’ll find while working on large-scale, long-lived programs at aprofessional level of quality. They will find out how to work most efficiently with currenttools and discover essential new ones. Other aspects include learning “street smarts”,navigating the corporate working environment, collaborating with colleagues, fitting intothe big picture and contributing to company success—thus, increasing one’s job security.Finally, the title helps readers look ahead to the years to come to make plans for theirlong-term success as programming professionals, regardless of their area of focus.http://www.pragprog.comPenelope Trunk’s Slave to Happiness (Que)In her new book, Slave to Happiness: Why Having an InterestingLife is the New American Dream, author Penelope Trunk positsa societal trend that <strong>Linux</strong> folk can relate to. The new Americandream, she says, is not based on the acquisition of more stuff,more money, more happiness or the like. Instead, a powerful newmotivator replacing “more” for a new generation of Americansis the goal of an interesting life. Publisher Que calls Trunk’s booka “powerful, revelatory book [that] captures a radical shift that’sbeen taking place just below the surface of American culture: onethat is about to explode across the American landscape”. Someof her revelations include why Americans will increasingly chooseinterest over contentment, how to make choices when all of the world’s knowledge is atyour fingertips and how collaboration and connection are gaining a central place in thenew American dream. Sound familiar? It will be interesting to see greater society adopt aphilosophy that <strong>Linux</strong> community has embraced for nearly a generation.http://www.informit.comWWW.LINUXJOURNAL.COM / FEBRUARY <strong>2012</strong> / 59


NEW PRODUCTSJetBrains’ PhpStormBeside providing a delightfully psychedelicmental picture, JetBrains’ PhpStorm, whichis now in version 3.0, offers softwaredevelopers an intelligent, productivityenhancing,code-centric PHP IDE. The most noteworthy features of the new versioninclude UML for quick view of the entire code structure plus the changes in therecent VCS commits, Smart Duplicated Code Detector to remove similar blocks ofcode without losing intended functionality, and a new PHPUnit test runner andJSTestDriver to make code run faster than ever. Other new functionality includessupport for cutting-edge technologies, such as CoffeeScript and XSLT 2.0, anintegrated XSLT debugger, PHP UML roundtrip diagrams, streamlined UI across alloperating systems and Mac OS X Lin support, among others.http://www.jetbrains.comMetaCase’s MetaEdit+ Plug-in for EclipseThe case that MetaCase makes for its new MetaEdit+ Plug-in for Eclipse is that nowdevelopment teams can combine the use of models and code—that is, modelingtools and programming environments—in the Eclipse environment. Until now, teamshave utilized the MetaEdit+ domain-specific modeling environment on its own. Thenew MetaEdit+ Plug-in allows users to work with MetaEdit+ models directly fromEclipse, and it automatically imports sourcecode generated from the MetaEdit+ modelsinto Eclipse and builds and runs it there.Traditionally, development teams have foundit difficult to combine the use of models andcode due to the modeling languages usedand the programming environments. Now,with the plugin, however, the domain-specificmodels—expressed as diagrams, matrices ortables in MetaEdit+—can be browsed andused directly from Eclipse.http://www.metacase.com60 / FEBRUARY <strong>2012</strong> / WWW.LINUXJOURNAL.COM


NEW PRODUCTSOpengear IM4216-34The Opengear team capped a productive2011 with the release of OpengearIM4216-34, a high-capacity infrastructuremanagement gateway that proactivelymonitors and maintains the health of all theIT equipment in data centers and remotelocations. The IM4216-34 provides one point of control for managing all the servers,networking and power equipment in a rack. Provided are 16 serial ports for advancedconsole management, a 32-port Ethernet gateway for SNMP device management, threeUSB ports and 16GB of internal Flash memory. Product highlights include myriad enterprisegradesecurity technologies, Automated Remote Management and Support (ARMS) andremote rack-level management capabilities. Opengear says that the IM4216-34 allowsoverstretched IT and security organizations to get more results with fewer resources.http://www.opengear.comParagon Universal File System DriverThe target market for the new Paragon Universal File SystemDriver (UFSD) is OEMs of consumer multimedia devices that areseeking cross-platform filesystem support. The software’s creator,Paragon Software Group, says that if its Paragon UFSD, whichsupports all popular filesystems, is built in to digital devices,consumers can enjoy issue-free compatibility between filesystemsused on all of their devices including those found not just in mediacenters, digital televisions and set-top boxes, but also variousstorage media. Key features include full read-write access, easymounting of any NTFS, HFS+ or exFAT partition like a native one,non-Roman character support, low system requirements and nolimitation on maximum file/partition size.http://www.paragon-software.comPlease send information about releases of <strong>Linux</strong>-related products to newproducts@linuxjournal.com orNew Products c/o <strong>Linux</strong> <strong>Journal</strong>, PO Box 980985, Houston, TX 77098. Submissions are edited for length and content.WWW.LINUXJOURNAL.COM / FEBRUARY <strong>2012</strong> / 61


NEW PROJECTSFresh from the LabsObix—Reliable Programming,Quicklyhttp://www.obix.luDo you want to create more reliablecode in less time? Obix may be justwhat you need. However, I’m guessingthis probably looks like just anotherprogramming language, but it’s actuallycontained within a philosophy that maybe an important evolutionary step inprogramming methods, called “Fail fast!”Take note of that term. At first, it mayseem bizarre, but on further inspection, theamusing name is actually very logical witha profound approach to programming. Iexplore this philosophy and its implicationsfollowing the next section.To quote some carefully chosen partsof the documentation:Obix is a high-level, object-oriented,statically-typed, compiled, portableprogramming language.The compiler generates Java binary code(.class files). Hence, applications writtenin Obix can run on any system with a JavaVirtual Machine (JVM) installed, such as<strong>Linux</strong>, Mac OS, Windows and so on.Obix has been designed from the outsetwith a very specific main goal in mind,namely to help write more reliablerandom_arcs is a cool tutorial that comes with Obix.code. In practice, this means that: 1)once your code passes compilation itcontains less bugs and 2) remaining bugsare more quickly detected at runtime.As a result, you can expect to reducedevelopment time and costs.Installation Whether it be indevelopment mode or production mode,Obix is designed around Java, so installingJava on your PC is a prerequisite. Ifyou haven’t done so already, installthe Java JDK version 6.0 or later. Thedocumentation notes that it’s not enough62 / FEBRUARY <strong>2012</strong> / WWW.LINUXJOURNAL.COM


NEW PROJECTSto install the Java Runtime Environment(JRE); you need to have the JavaDevelopment Kit (JDK) installed.If your machine is Debian/Ubuntubased,the package name is sun-java7-jdk.If your machine is RPM-based,look for jdk-7u1-linux-x64.rpm orjdk-7u1-linux-i586.rpm. Either version6 or 7 will do, but version 7 of Java ispreferable. Other than that, there isnothing else in the way of dependencies.To install Obix, grab the latest tarballfrom the Web site, extract it, and opena terminal in the new folder. From there,you now can check the installation withthe following command that displaysObix’s version number in your terminal:$ ./obix.sh versionUsage As these are early days,Obix isn’t supported by a graphicalenvironment. All tools for managingprojects and compiling, running andtesting code are executed from thecommand line, so get a console andtext editor ready.So what was all the “Fail fast!” stuffabout? The idea is this: every codingerror should be detected as early aspossible, preferably at compile time, orelse as early as possible at runtime.To achieve this, Obix has errorpreventingconcepts, such as:n Contract programming (designby contract).n Feature re-definition in child types.n Unit testing.n Generic types without type erasureat runtime.n Objects are immutable by default.n Void (null) values are not allowedby default.Although this may seem like a hassle,Obix designer Christian Neumanns foundthat a forgiving approach to coding in alanguage resulted in some horrendouserrors in the long run, with some veryangry customers. However, start out witha “Fail fast!” approach, and your codingnaturally will be tighter and more reliable.To illustrate one of Obix’s uniquefeatures for more reliable code, look atthe following example source code:int server_port = 8080int age_of_my_elephant = server_portCan you see the error? Of course youcan. Can your compiler see the error?No, it can’t. Although server_portand age_of_my_elephant obviouslyare two semantically different values,the compiler can’t see an incompatibility,because both values are of type integer.Moreover, no runtime error will begenerated, despite the fact that elephantscan’t be older than about 100 years.WWW.LINUXJOURNAL.COM / FEBRUARY <strong>2012</strong> / 63


NEW PROJECTSYou might say, “No programmer wouldever write silly code like this!” This istrue (for most programmers). However,look at this code:int age_of_elephant = utilities.get_initial_valueNow, you can’t tell if the assignment isokay just by looking at the source code.You would have to verify manually thatutilities.get_initial_valueactually returns an “age of elephant”value that can’t be negative and can’texceed 100. It would be helpful if thecompiler could check all this for youautomatically, wouldn’t it?Without digging too deeply intohow it works, here is the solution inObix. You would define a specific typeage_of_elephant and declare apositive maximum value of 100. Thesource code for this type looks like this:type age_of_elephantendinherit simple_positive32endattribute value and_check: i_value


NEW PROJECTShoping that Christian’s “Fail fast!” ethoswill take root in future programminglanguages, creating another evolutionarystep in programming methods, andultimately, more reliable computing.darktable—Virtual Photo Darkroomhttp://www.darktable.orgIf you’re a photographer dealingwith many images at a time, darktablemay well strike the perfect compromisebetween image browsing and pictureenhancement.According to the Web site:darktable: a mass-photo browser with astrikingly good interface.darktable is an open-source photographywork-flow application and RAWdeveloper—a virtual lighttable anddarkroom for photographers. It managesyour digital negatives in a database,lets you view them through a zoomablelighttable and enables you to developraw images and enhance them....darktable tries to fill the gap betweenthe excellent existing free raw convertersand image management tools (such asUFRaw, Rawstudio, F-Spot, digiKam andShotwell). It focuses on the work flow tomake it easier for the photographer tohandle quickly the thousands of imagesa day of shooting can produce. It’s alsoone of the very few FOSS projects able todo tethered shooting.Installation Binary packages areprovided for Ubuntu, Fedora, SUSEdarktable with all the tools visible and readyfor editing.and Arch <strong>Linux</strong>, as well as a Portagepackage for Gentoo/Funtoo. There alsois an experimental version for Mac OSX, and Windows also is a possibility, butamusingly, the Web site notes that thecommunity for this commercial distributionhasn’t made a native version yet, so itrecommends installing Ubuntu instead.In terms of library requirements, theWeb site gives the following list ofWWW.LINUXJOURNAL.COM / FEBRUARY <strong>2012</strong> / 65


NEW PROJECTS$ sudo make installIf your distro uses root, enter:$ su# make installdarktable with the tools cleared away to enjoy thepicture in peace. Yes, those are my drums.Note that on my machine, it installeddarktable to /opt by default, in whichcase, at the command line, it may berequired that you enter:$ /opt/darktable/bin/darktablepackages: libsqlite3, libjpeg, libpng,libraw (supplied), rawspeed (supplied),gtk+-2, cairo, libglade2, lcms2, exiv2,gconf, tiff, curl, gphoto2, dbus-glib,gnome-keyring, fop and openexr.If you want to build from source, theWeb site is incredibly helpful, with allthe instructions you’ll need, in greatdetail. Nevertheless, I include a simplifiedversion here.Download the latest tarball, extract it,and open a terminal in the new folder.Enter the command:$ ./build.shOnce the building has finished, changeinto the build folder with:$ cd buildNow, to install darktable, if your distrouses sudo (such as Ubuntu), enter:For other users (especially withbinaries), you can run the program withthis command:$ darktableUsage As soon as you’re inside the mainwindow, you’ll notice an arrow at eachedge: this is for expanding and collapsingpanes within the window. You maywonder why I’m starting with somethingso mundane, but this function actually isincredibly useful (more on that later).Working within darktable, the interfaceis split into three view modes: lighttable(browsing), darkroom (editing) and cameratethering (a clever means of interactingwith a camera). I don’t really have the wordspace or equipment to explore the tetheringmode, so I primarily cover the lighttableview and the darkroom view here.lighttable When the program starts,you should find yourself in lighttable66 / FEBRUARY <strong>2012</strong> / WWW.LINUXJOURNAL.COM


NEW PROJECTSview. Here, you manage your images aswell as do things like add tags and colorlabels. Keep in mind that its shortcut keyis L, as darktable’s design has been basedaround switching between the lighttableand darkroom views, easily and rapidly.The first order of business is to import someimages with the import field on the left.Do you see a field? If not, remember thearrows that I mentioned at the start of thissection. Click on the left arrow, and theimport section will expand and collapse.Collapsing one section can be very useful,as it lets the actual picture section growmuch larger. With the import sectionexpanded, import some pictures (you havethe choice of a singular image, a folder orto scan for devices), and they will appear inthe main section in the middle.While you’re still here, try expandingand collapsing all four arrows, and seehow it affects the rest of the window. Withall the fields collapsed, the image sectiongets center stage and takes up the wholewindow, and with all the fields expanded,you have a great many tools available,but your images are reduced to small,insignificant squashy things. With just asmall number of clicks, this clever GUI designallows you to switch between beautifulZen-like minimalism on one end and ugly butuseful functionalism on the other.darkroom With that covered, selectsome of your pictures, and let’s moveon to the darkroom. Remember that itsshortcut key is D. In fact, try alternatingbetween lighttable and darkroom with Land D now. Nice, huh? This darkroom iswhere you do the editing, and you cando all sorts of things, like toy with thecolor profile, sharpen the image, applycropping, rotate and so on.While you’re in the darkroom, you stillcan change between images with thefilmstrip, toggled with Ctrl-F. Chancesare that you’ll have quite a number ofimages along the strip, so if you want toscroll along it, hover your mouse pointerover the strip and use your scroll wheel.Double-clicking will open an image.That’s about all the space I have fordarktable, but it’s been an absolutepleasure to use. The GUI design is oneof the best I’ve ever come across, andI hope to see its design copied in thefuture. Plus, the aesthetics are great aswell, with a really cool light-black colorscheme that is such a nice change fromthe endless beige and grays that makecomputing so depressing at times.For mid-level photo management,this probably is the coolest tool I’vecome across, and whether you like yourinterface minimal or maximal, it doesn’tmatter. You can change it around inabout two seconds.■John Knight is a 27-year-old, drumming- and bass-obsessedmaniac, studying Psychology at Edith Cowan University in WesternAustralia. He usually can be found playing a kick-drum far too much.BREWING SOMETHING FRESH, INNOVATIVE OR MIND-BENDING? Send e-mail to newprojects@linuxjournal.com.WWW.LINUXJOURNAL.COM / FEBRUARY <strong>2012</strong> / 67


An Introduction toApplicationDevelopmentwithCatalystPerlandRails isn’t the onlyopen-source Webframework in town.HENRY VAN STYN68 / FEBRUARY <strong>2012</strong> / WWW.LINUXJOURNAL.COM


Catalyst is the latest in theevolution of open-source Webdevelopment frameworks.Written in modern Perl andinspired by many of the projects thatcame before it, including Ruby onRails, Catalyst is elegant, powerful andrefined. It’s a great choice for creatingany Web-based application from thesimple to the very complex.Like many other popular Perl-basedprojects, Catalyst has a strong focuson flexibility and choice. Catalyst isespecially powerful because it providesan abundance of features and the coreenvironment, structure and interfaceson which virtually anything can bebuilt without forcing you to do thingshigh-level features as optional pluginsand modules. This is one of the greateststrengths of Perl—a tremendous numberof refined modules and libraries areavailable. So, instead of re-inventing allthis functionality, Catalyst provides aframework to bring together seamlesslywhat already exists.Catalyst is bigger than itself—it isalso everything that’s available in CPAN.That alone makes it one of the mostfeature-rich frameworks there are.In this article, I provide an introductionto Catalyst and how to use it for rapidapplication development. I cover thebasics of how to create and lay out anew application as well as how to writethe actions that will handle requests.Catalyst is bigger than itself—it is alsoeverything that’s available in CPAN.in any particular way.Writing applications in Catalyst is fasttoo. Just because you can tackle any aspectof application design yourself, doesn’t meanyou have to. Catalyst provides a wide arrayof refined, high-level, drop-in solutionsto all kinds of problems and needswithout limiting access to the nuts andbolts. Templating, ORM, authentication,automatic session management and allthe other high-level features you’d wantfrom a Web framework are available inCatalyst—and more.Catalyst’s approach is to provide theseI explain how to define flexible URLdispatch logic and some of the APIsthat are available. I focus on thefundamentals, but I cover some of thepopular available components as well,such as Template::Toolkit. I also talkabout how you can extend Catalystitself, and how you can deploy anapplication with Apache.Background Knowledge and theMVC ArchitectureCatalyst and Catalyst applicationsare written in Perl, so some basicWWW.LINUXJOURNAL.COM / FEBRUARY <strong>2012</strong> / 69


FEATURE An Introduction to Application Development with Catalyst and PerlPerl knowledge is necessary to useCatalyst effectively. You also shouldhave some experience with objectorientedprogramming concepts, suchas classes, methods, inheritance andso on.Like Rails, Django, CakePHP and manyother Web frameworks, Catalyst followsthe venerable Model-View-Controllerarchitectural pattern. MVC is a provenapproach to structuring and segmentingapplication code for efficiency, flexibilityand maintainability.Plenty of tutorials and resources areavailable for MVC, so I won’t spend toomuch time covering it here. If you’veworked with other Web frameworks,chances are you’re already familiar withMVC. If not, the most important thing tounderstand is that it is more about bestpractices than anything else.The focus of this article is to explainthe core details of how Catalyst operates,but since Catalyst made most of itslayout decisions according to MVC,you’ll still see it along the way.Getting CatalystBefore you can install Catalyst on yoursystem, you obviously need Perl. Most<strong>Linux</strong> distros already have Perl installedout of the box, but if not, install it withyour package manager.Catalyst itself is a Perl library that youcan install with cpan:cpan Catalyst::DevelThe previous command installs Catalystwith development tools along with itsmany dependencies. For production/hosting systems that will run onlyapplications without the need fordevelopment tools, you can install thesmaller Catalyst::Runtime bundle instead.Because Catalyst has so manydependencies, it can take quite a whileto install on a fresh system. By default,CPAN asks if it should install eachdependency individually, which canbecome redundant really quick. You canconfigure CPAN not to ask, but instead, Iusually just cheat by holding down Enterfor a few seconds to queue up a bunchof default (“yes, install the module!”)keystroke/answers.If the install fails on the first attempt,don’t fret. Whatever the problem maybe, it probably will be explained in thescrollback along with what to do tosolve it. Typically, this involves nothingmore than installing/upgrading anothermodule that wasn’t automatically inthe dependency tree for whateverreason, or just running the cpancommand a second time.Catalyst Application LayoutEvery Catalyst application is a Perlmodule/library/bundle—exactly like themodules on CPAN. This consists of apackage/class namespace and standardstructure of files and directories. TheCatalyst::Devel package comes with ahelper script to create new “skeleton”70 / FEBRUARY <strong>2012</strong> / WWW.LINUXJOURNAL.COM


applications and to initialize the filesand directories for you. For example, tocreate a new application called KillerApp,run the following:catalyst.pl KillerAppThis creates a new application structure atKillerApp/ with the following subdirectories:lib/: this is the Perl include directorythat stores all the Perl classes (akapackages or modules) for the application.This is added to the Perl lib path atruntime, and the directory structurecorresponds to the package/classnamespaces. For example, the twoclasses that are initially createdhave the following namespaces andcorresponding file paths:n KillerApp — lib/KillerApp.pmn KillerApp::Controller::Root —lib/KillerApp/Controller/Root.pmThese directories also are created butinitially are empty:n lib/KillerApp/Model/n lib/KillerApp/View/root/: this is where other kindsapplication-specific files are stored.Static Web files, such as images, CSS andJavaScript go in the subdirectory static,which usually is exposed as the URL/static. Other kinds of files go in heretoo, such as templates.script/: this contains applicationspecificscripts, including thedevelopment server (killerapp_server.pl)that you can use to run the applicationin its own standalone Web server,as well as scripts to deploy theapplication in a “real” Web server.The helper script killerapp_create.plcreates new model, view and controllercomponent classes.t/: this is where “tests” go. If youfollow a test-driven development process,for every new feature you write, you alsowill write an automated test case. Testslet you quickly catch regressions that maybe introduced in the future. Writing themis a good habit to get into, but that’sbeyond the scope of this article.The created skeleton application isalready fully functional, and you can runit using the built-in test server:cd KillerApp/script/killerapp_server.plThis fires up the app in its owndedicated Web server on port 3000. Openhttp://localhost:3000/ to see the defaultfront page, which initially displays theCatalyst welcome message.The Request/Response CycleAll Web applications handle requests andgenerate responses. The fundamentaljob of any Web framework/platform/WWW.LINUXJOURNAL.COM / FEBRUARY <strong>2012</strong> / 71


FEATURE An Introduction to Application Development with Catalyst and Perlenvironment is to provide a usefulstructure to manage this process.Although there are different ways ofgoing about this—from elegant MVCapplications to ugly, monolithic CGIscripts—ultimately, they’re all doingthe same basic thing:1. Decide what to call when a requestcomes in.2. Supply an API for generating theresponse.In Catalyst, this happens in specialmethods called “actions”. On everyrequest, Catalyst identifies one or moreactions and calls them with specialarguments, including a reference tothe “context” object that provides aconvenient and practical API throughwhich everything else is accomplished.Actions are contained within classescalled “controllers”, which live ina special path/namespace in theapplication (lib/KillerApp/Controller/).The skeleton application sets upone controller (“Root”), but you cancreate more with the helper script. Forexample, this creates a new controllerclass KillerApp::Controller::Something:script/killerapp_create.pl controller SomethingThe only reason to have more thanone controller is for organization; youcan put all your actions in the Rootcontroller with no loss of featuresor ability. Controllers are just thecontainers for actions.In the following sections, I describehow Catalyst decides which actions tocall on each request (“dispatch”) andthen explain how to use the suppliedcontext object within them.DispatchCatalyst provides a particularly flexibleand powerful mechanism for configuringdispatch rules. Rather than having aseparate configuration to assign URLsto specific actions, Catalyst uses theactions themselves to determine URLmappings dynamically.Each action definition (which is justa Perl subroutine) represents not only ablock of code, but also what URL pathsapply to it. This is specified in subroutineattributes—a lesser-known Perl featurethat provides arbitrary labels that can beused for introspection.Catalyst supports a handful ofparameterized attributes to determinethe URL path to action mappings in avariety ways. For example, the followingaction has an absolute path set using the:Path attribute:sub myaction :Path('/some/place') {my ( $self, $c, @args ) = @_;# do stuff...}Regardless of what controller you72 / FEBRUARY <strong>2012</strong> / WWW.LINUXJOURNAL.COM


put it in, the above action would mapto all URLs starting with /some/place(http://localhost:3000/some/place withthe development server).If you omitted the starting slashand used :Path('some/place'),the action would map to a pathrelative to the namespace of thecontroller. For example, if it were inKillerApp::Controller::Foobar,it would be mapped to URL paths startingwith /foobar/some/place.Instead of using :Path to set thepath explicitly, you can set :Localto use the name of the controller andmethod. For instance, the followingaction, if contained in the controllerKillerApp::Controller::Some,would also map to /some/place:sub place :Local {my ( $self, $c, @args ) = @_;# do stuff...}If it were contained in the controllerKillerApp::Controller::Some::Other,it would map to /some/other/place.Actions include subpaths by default,so the above also would match /some/other/place/blah/foo/1. When thishappens, the leftover parts of the pathare supplied as arguments to the actionmethod (’blah’,’foo’,’1’). You can usethe :Args attribute to limit how deepthe action will match subpaths, if atall. With an Args value of 0, this actionwould match only /some/place, butnothing below it:sub myaction :Path('/some/place') :Args(0) {}my ( $self, $c ) = @_;# do stuff...Other attributes are available too.:Global works like :Local but ignoresthe controller name, and path patternmatching can be done with :Regexand :LocalRegex.When a URL matches more thanone action, Catalyst picks the one thatmatches best. However, there are a fewbuilt-in actions (method names “begin”,“end” and “auto”) that, if defined, arecalled at various stages of every requestin addition to the matched action. Usingthe advanced :Chained attribute type,you can configure additional/multipleactions to be called with single requestsin any order you like.You also can programmatically dispatchto other action/paths from within theaction code itself:sub myaction :Path('/some/place') {}my ( $self, $c, @args ) = @_;$c->forward('/some/other/place');The Context Object ($c)Controller actions serve as entry pointsto application code. A special perrequestobject called the “context” isWWW.LINUXJOURNAL.COM / FEBRUARY <strong>2012</strong> / 73


FEATURE An Introduction to Application Development with Catalyst and Perlsupplied as an argument to every actionwhen it is called by the dispatcher. Thecontext object typically is read intoa variable named $c, but it could becalled anything.The context provides interfaces andinformation about the applicationand its current state. It contains thedetails of the request currently beingprocessed ($c->request) and accessto what will become the response($c->response).At the beginning of the request, beforeany actions are called, the responseobject is created with empty/defaultdata. Each of the actions that are calledthen has an opportunity to manipulatethe response. At the end of the request,its final state is sent back to the client.This iterative approach to generating theresponse lends itself to a modular anddynamic structure.The following action illustrates a fewof the simple APIs that are available,such as inspecting the User-Agent andquery/post parameters in the request,and setting the body and headers ofthe response:sub myaction :Path('/some/place') {my ( $self, $c, @args ) = @_;my $myparam = $c->request->params->{myparam};if(defined $myparam) {}$c->response->body("myparam is $myparam");}else {}$c->response->body("myparam was not supplied!!");$c->response->body($c->response->body ."\n\nExtra path args: " . join('/',@args)) if (@args > 0);$c->response->headers->header( 'Content-Type' => 'text/plain' );$c->response->body("Bad command or file name")if ($c->request->user_agent =~ /MSIE/);Accessing the URL http://localhost:3000/some/place/boo/baz?myparam=foo woulddisplay the text that follows (except whenusing IE, in which case “Bad command orfile name” is displayed instead):myparam is fooExtra path args: boo/bazWithin the action code, you canwrite any logic you like to build yourapplication. Because the context objectis just a variable, you can pass it asan argument into other functions.Following normal Perl programmingrules, you can use other classes andlibraries, instantiate objects and so on.This is the extent of what you haveto do—write controller actions anduse the context object—but it’s onlythe beginning of what you can do.74 / FEBRUARY <strong>2012</strong> / WWW.LINUXJOURNAL.COM


Over and above the core functionality,Catalyst provides a robust MVC structureto build your application.Catalyst ComponentsOver and above the core functionality,Catalyst provides a robust MVC structureto build your application. This includesuseful base classes, sensible defaultbehaviors and helpful sugar functions.You can leverage a tremendous amountof turnkey functionality by creating yourclasses within the supplied framework asmodels, views and controllers.All these are considered “components”within Catalyst, and there aren’t actuallymany functional differences betweenthem. The Model-View-Controller monikersprimarily are used for the purpose ofcategorization. Models are meant tocontain data and business logic; views aresupposed to handle rendering and display;and controllers tie everything together.Operationally, components areessentially application classes with someextra, Catalyst-specific functionally. Theyare loaded automatically at startup asstatic object instances. Any componentcan be accessed throughout theapplication via the context object:sub myaction :Path('/some/place') {my ( $self, $c, @args ) = @_;$c->model('MyModel')->do_something;}$c->forward( $c->view('MyView') );In the above example action,you simply are calling the methoddo_something in a model namedMyModel (KillerApp::Model::MyModel),and then forward to the view namedMyView (KillerApp::View::MyView).Earlier, I showed how to use forwardto dispatch to another action bysupplying a path. When you pass acomponent to forward, the processmethod of the supplied component iscalled as if it were a controller action,which is roughly equivalent to this:$c->view('MyView')->process($c,@args);These are just a few examples of theavailable conventions and shortcuts. Theimportant thing to understand is that allthese sugar functions just boil down tocalling methods and normal program flow.Template::Toolkit ViewsOne of the most common needs of a Webapplication is a templating system forrendering content. Templates probablyare the best all-around approach toWWW.LINUXJOURNAL.COM / FEBRUARY <strong>2012</strong> / 75


FEATURE An Introduction to Application Development with Catalyst and Perlrendering text-based content, especiallyfor markup like HTML.Catalyst can use multiple Perl templatesystems, but the most popular isTemplate::Toolkit—a powerful, generalpurposetemplate-processing system thatis fast and feature-rich. It has a versatileand robust syntax that is simple and easyto use, but it also supports advancedcapabilities, such as control structures,stream processing and extendability.Template::Toolkit is a whole programminglanguage in its own right.Catalyst provides a drop-in interface toTemplate::Toolkit via the view/componentclass Catalyst::View::TT. You can create aview within your application that extendsthis class using the helper script. Run thisto create a new view named “HTML”:Message: [% message %]The character sequences within [% %]are “directives”—snippets of code that getreplaced when the template is processed.The directives above are simple variablesubstitutions, which are the most basickind. In this case, the values supplied fortitle and message will be insertedwhen the template is rendered.If you saved the above template in afile named main.tt within root/templates,for example, you could use it with anaction like this:sub myaction :Path('/some/place') :Args(0) {my ( $self, $c ) = @_;script/killerapp_create.pl view HTML TTThe new view is fully functional out ofthe box. As a general-purpose wrapperaround Template::Toolkit, it provides asimple API to select templates and supplyinput data. The rest of the view-specificcode goes in the templates themselves,which are stored within “root” in yourapplication directory.Here is an example of a simpleTemplate::Toolkit template to renderan HTML page:[% title %]}$c->stash->{template} = 'templates/main.tt';$c->stash->{data}->{title} = 'TT rendered page';$c->stash->{data}->{message} = 'A cool message!';$c->forward( $c->view('HTML') );The stash object above is anotherbuilt-in feature of Catalyst that I haven’tcovered so far. It isn’t very complicated;it’s simply a hashref within the contextobject. It provides a standard per-requestplace to share data across components,similar to request and response, but forgeneral use.Catalyst::View::TT-based views usethe content of the stash to determine76 / FEBRUARY <strong>2012</strong> / WWW.LINUXJOURNAL.COM


operation. The value of templateidentifies the template to call, and thestash as a whole is used as the inputdata—each key in the stash becomes avariable in the template. The contentgenerated from processing the templateis used to set the body of the response.The data in a real applicationprobably will be more complex thanthe simple key/values in the previousexample. One of Template::Toolkit’sgreat features is its ability to handlePerl data structures directly. Considerthe following action:sub myaction :Path('/some/place') :Args(0) {This would work with a templatelike this:[% data.title %]Alpha: [% data.subhash.alpha %]Bravo: [% data.subhash.bravo %]Charlie: [% data.subhash.charlie %]List of Things:[% FOREACH item IN data.thinglist %][% END %][% item %]}my ( $self, $c ) = @_;$c->stash->{template} = 'templates/main.tt';$c->stash->{data} = {title => 'TT rendered page',subhash => {alpha => 'foo',bravo => 'abdc',charlie => 'xyz'},thinglist => ['Thing 1','Thing 2','Big thing','Small thing']};$c->forward( $c->view('HTML') );Objects also can be supplied andaccessed in the same manner as hashes.In fact, the context object is suppliedautomatically in “c”. For example,if you want to display the client’s IPaddress, instead of separately putting$c->request->address in the stash,you can just access it directly within thetemplate like this:[% c.request.address %]Template::Toolkit has many morefeatures and abilities, includingwrappers, conditional statements,filters, function calls and so on.Catalyst::View::TT also has additionaldefaults and configuration optionsthat I didn’t cover here (see thedocumentation for more details).WWW.LINUXJOURNAL.COM / FEBRUARY <strong>2012</strong> / 77


FEATURE An Introduction to Application Development with Catalyst and PerlIt is totally up to you how to balancelogic between the templates and therest of your application. Depending onwhat you are trying to achieve, yourapplication easily could be written morein Template::Toolkit than in Perl!DBIx::Class ModelsOne of the other most common needs ofan application is a database. DBIx::Class(often shortened to DBIC) has emergedas the most popular ORM (ObjectRelational Mapper) library available forPerl. It is an exceptionally powerful,robust, object-oriented interfaceto many relational database servers(including MySQL, PostgreSQL, Oracle,MSSQL and many others).Like Template::Toolkit, but to an evengreater degree, Catalyst provides refined,drop-in component wrappers to interface withDBIx::Class (Catalyst::Model::DBIC::Schema).Using DBIx::Class is a whole topic inand of itself that I don’t have space tocover here, but it is a must-have if youplan to integrate your application with adatabase. See Resources for informationon where to go to start learning aboutthis wonderful library.Plugins and Application-Wide SettingsBesides pre-built component classes fordrop-in functionality, many plugins areavailable to modify the behavior andextend the functionality of Catalystitself. A few of the most common are theoptional authentication, authorizationand session plugins.These plugins provide a consistent APIfor handling these tasks with a varietyof available back ends. Like the corerequest/response object interfaces, theyare available as application-wide featuresthat are accessed and controlled throughmethods in the context object, whichbecome available once these plugins havebeen loaded.You can authenticate a user (withinan action handling a login form post, forexample) like this:$c->authenticate({});username => $c->request->params->{username},password => $c->request->params->{password}If this succeeds, the $c->user objectis available in subsequent requests tocontrol and direct application flowbased on the authenticated user. Thisis accomplished using sessions (usuallycookie-based) that are handled for youautomatically. You also have access to$c->session to persist any additionalper-session data across requests.The API of this framework isagnostic to the back end, andmany are available. You can handleauthentication and user storage viadatabases (DBIC), system accounts,PAM and LDAP, to name a few. Therealso are multiple ways to handlesession data to support differentapplication needs, such as distributed78 / FEBRUARY <strong>2012</strong> / WWW.LINUXJOURNAL.COM


server deployments and soon. (See the documentation forCatalyst::Plugin::Authentication,Catalyst::Plugin::Authorization andCatalyst::Plugin::Session for moreinformation.)Plugins and application-wide settingsare configured within the main/coreclass (lib/KillerApp.pm). Within this file,you can specify global configurationparameters, load Plugins and even addyour own code to override and extendcore functionality.The top-level “KillerApp” classactually is the application—itprogrammatically loads and integratesthe other components and classesthroughout the system. Like anyderived class, its behaviors can beselectively altered from that of itsparent class (“Catalyst”). Since it usesthe powerful “Moose” object system,in addition to adding and replacingmethods, you also can take advantageof additional powerful features likemethod modifiers and Roles (in fact,Plugins are essentially Moose Rolesapplied to this class).Catalyst was written withcustomization and extensibility inmind. It’s structured to allow itsfunctions and behaviors to be modifiedeasily in a fine-grained manner.For example, you could configureevery response to be set with “nocache”across the whole applicationsimply by adding a method modifierlike this to lib/KillerApp.pm:before 'finalize_headers' => sub {};my $c = shift;$c->response->headers->header( 'Cache-control' => 'no-cache' );Catalyst calls methods with meaningfulnames (such as ’finalize_headers’)throughout the various stages of processingthat you are free to hook into or override.Deploying Your ApplicationLike most things in Catalyst, many optionsare available when you’re ready to deployyour application to a real Web server—Apache/FastCGI is one of the best choicesavailable. I briefly cover this below.If you put your application in /var/www,for example, you can deploy with anApache virtual host configuration like this:ServerName www.example.comServerAdmin webmaster@example.comAlias /static/ /var/www/KillerApp/root/static/FastCgiServer /var/www/KillerApp/script/killerapp_fastcgi.pl \-processes 5Alias / /var/www/KillerApp/script/killerapp_fastcgi.pl/ErrorLog /var/www/logs/error_logCustomLog /var/www/logs/access_log combinedWWW.LINUXJOURNAL.COM / FEBRUARY <strong>2012</strong> / 79


FEATURE An Introduction to Application Development with Catalyst and PerlFastCGI is a proven, languageindependentinterface for running Webapplications. It is essentially just plainCGI, but it keeps programs running in thebackground instead of firing them up forevery request. This is the major limitationof CGI that FastCGI overcomes. FastCGIhas been around for a long time. Theuse of this efficient protocol is anotherexample of how Catalyst leveragesexisting solutions.FastCGI allows you to specify thenumber of processes to run (five in theexample above), making your applicationmultithreaded. Incoming requests aredistributed evenly among the processes,which are maintained in a pool.The alias for /static/ above tellsApache to serve the files directly inthis directory (images, CSS, JavaScriptfiles and so on). This is more efficientthan serving these files through theapplication, which isn’t necessary.ConclusionThis article is meant to provide only ataste of Catalyst and its capabilities.As I hope you have seen, Catalyst is aviable platform for any Web developmentproject. With a flexible design and manyavailable mature features, you can useCatalyst to build robust applicationsquickly and conveniently.Catalyst is actively developed and isgetting better all the time, including itsever-increasing quality documentation.It also has a very active user communitywith top experts available via IRC.When you’re ready to start writingan application, you should be able tofind the information and support youneed to hit the ground running. See theResources for this article for importantlinks and where to get started.■Henry Van Styn is the founder of IntelliTree Solutions, an ITconsulting and software development firm located in Cincinnati,Ohio. Henry has been developing software and solutions for morethan ten years, ranging from sophisticated Web applications tolow-level network and system utilities. He is the author of StrongBranch <strong>Linux</strong>, an in-house server distribution based on Gentoo.Henry can be contacted at www.intellitree.com.ResourcesCatalyst Home Page:http://www.catalystframework.orgCatalyst::Manual: http://search.cpan.org/perldoc?Catalyst::ManualTemplate Toolkit Home Page:http://www.template-toolkit.orgDBIx::Class::Manual: http://search.cpan.org/perldoc?DBIx::Class::ManualCatalyst IRC Channel: #catalyst onhttp://irc.perl.org“Moose” by Henry Van Styn, LJ, September2011: http://www.linuxjournal.com/content/mooseThe Definitive Guide to Catalyst (c) 2009ISBN: 978-1-4302-2365-8 (print) and978-1-4302-2366-5 (on-line).80 / FEBRUARY <strong>2012</strong> / WWW.LINUXJOURNAL.COM


Three Ways toWeb ServerConcurrencyMultiprocessing, multithreadingand evented I/O:the trade-offs in Web servers.MARTIN KALINA Web server needs to support concurrency. The server should service clientsin a timely, fair manner to ensure that no client starves because some otherclient causes the server to hang. Multiprocessing and multithreading, andhybrids of these, are traditional ways to achieve concurrency. Node.jsrepresents another way, one based on system libraries for asynchronousI/O, such as epoll (<strong>Linux</strong>) and kqueue (FreeBSD). To highlight the trade-offsamong the approaches, I have three echo servers written in close-to-the-metal C:a forking_server, a threading_server and a polling_server.82 / FEBRUARY <strong>2012</strong> / WWW.LINUXJOURNAL.COM


Shared CodeThe Web servers use utils.c (Listing 1).The function error_msg printsmessages and optionally terminatesthe server; announce_client dumpsinformation about a connection; andgenerate_echo_response creates asyntactically correct HTTP response.The central function iscreate_server_socket, whichcreates a blocking or a nonblockinglistening socket. This function invokesthree system functions:n socket — create socket.n bind — set port.n listen — await connections.The first call creates a TCP-basedsocket, and the bind call then specifiesthe port number at which the Webserver awaits connections. The listencall starts the waiting for up toBACKLOG connections:if (listen(sock, BACKLOG) < 0) /* BACKLOG == 12 */error_msg("Problem with listen call", true);A Multiprocessing ServerThe forking_server in Listing 2 supportsconcurrency through multiprocessing,an approach that early Web servers,such as Apache 1 used to launch Webapplications written as, for example,C or Perl scripts. Separate processesListing 1. utils.c#include #include #include #include #include #include #include "utils.h"void error_msg(const char* msg, bool halt_flag) {perror(msg);if (halt_flag) exit(-1);}/* listening socket */int create_server_socket(bool non_blocking) {/* Modify as needed. */const int port = 3000;struct sockaddr_in server_addr;/* create, bind, listen */int sock = socket(AF_INET, /* family */SOCK_STREAM, /* TCP */0);if (socket < 0) error_msg("Problem with socket call", true);/* non-blocking? */if (non_blocking) fcntl(sock, F_SETFL, O_NONBLOCK);/* bind */bzero(&server_addr, sizeof(server_addr));server_addr.sin_family = AF_INET;server_addr.sin_addr.s_addr = INADDR_ANY;server_addr.sin_port = htons(port); /* host to network endian */if (bind(sock, (struct sockaddr*) &server_addr,➥sizeof(server_addr)) < 0)error_msg("Problem with bind call", true);/* listen */fprintf(stderr, "Listening for requests on port %i...\n", port);if (listen(sock, BACKLOG) < 0)error_msg("Problem with listen call", true);return sock;}void announce_client(struct in_addr* addr) {char buffer[BUFF_SIZE + 1];inet_ntop(AF_INET, addr, buffer, sizeof(buffer));fprintf(stderr, "Client connected from %s...\n", buffer);}void generate_echo_response(char request[ ], char response[ ]) {strcpy(response, "HTTP/1.1 200 OK\n");strcat(response, "Content-Type: text/*\n");strcat(response, "Accept-Ranges: bytes\n");strcat(response, "Connection: close\n\n");strcat(response, request);}WWW.LINUXJOURNAL.COM / FEBRUARY <strong>2012</strong> / 83


FEATURE Three Ways to Web Server ConcurrencyListing 2. forking_server.c#include #include #include #include #include #include "utils.h"int main() {/* Avoid zombies. */signal(SIGCHLD, SIG_IGN);char buffer[BUFF_SIZE + 1];struct sockaddr_in client_addr;socklen_t len = sizeof(struct sockaddr_in);/* listening socket */int sock = create_server_socket(false);/* connections + requests */while (true) {int client = accept(sock,(struct sockaddr*) &client_addr,&len);if (client < 0) error_msg("Problem with accept call", true);announce_client(&client_addr.sin_addr);/* fork child */pid_t pid = fork();if (pid < 0) error_msg("Problem with fork call", false);/* 0 to child, child's PID to parent */if (0 == pid) { /** child **/close(sock); /* child's listening socket *//* request */bzero(buffer, sizeof(buffer));int bytes_read = recv(client, buffer, sizeof(buffer), 0);if (bytes_read < 0) error_msg("Problem with➥recv call", false);/* response */char response[BUFF_SIZE * 2];bzero(response, sizeof(response));generate_echo_response(buffer, response);int bytes_written = send(client, response,➥strlen(response), 0);if (bytes_written < 0) error_msg("Problem with➥send call", false);close(client);exit(0); /* terminate */}else /** parent **/close(client); /* parent's read/write socket. */}return 0;}handle separate connections. Thisapproach is hardly outdated, althoughmodern servers, such as Apache 2,typically combine multiprocessing andmultithreading.The forking_server divides thelabor among a parent process andas many child processes as there areconnected clients. A client is activeuntil the connection closes, which endsthe session.The parent process executes main fromthe first instruction. The parent listens forconnections and per connection:n Spawns a new process to handlethe connection.n Resumes listening for other connections.The following is the critical code segment:pid_t pid = fork(); /* spawn child */if (0 == pid) { /* child */}close(sock); /* close inherited listening socket *//* handle request and terminate */...else /* parent */close(client); /* close client, resume listening */The parent executes the call tofork. If the call succeeds, fork returnsa non-negative integer: 0 to theforked child process and the child’sprocess identifier to the parent.The child inherits the parent’s open84 / FEBRUARY <strong>2012</strong> / WWW.LINUXJOURNAL.COM


Creating and destroying processes areexpensive. Modules, such as FastCGI,remedy this inefficiency through pre-forking.socket descriptors, which explains theif-else construct:n if clause: the child closes its copyof the listening socket becauseaccepting clients is the parent’sjob. The child handles the client’srequest and then terminates with acall to exit.n else clause: the parent closes theclient socket because a forkedchild handles the client. The parentresumes listening for connections.Creating and destroying processesare expensive. Modules, such asFastCGI, remedy this inefficiencythrough pre-forking. At startup,FastCGI creates a pool of reusableclient-handling processes.An inefficiency remains, however.When one process preempts another,a context switch occurs with theresultant system working to ensurethat the switched-in and switchedoutprocess behaves properly. Thekernel maintains per-process contextinformation so that a preemptedprocess can restart. The context’sthree main structures are:n The page table: maps virtual addressesto physical ones.n The process table: stores vital information.n The file table: tracks the process’open files.The CPU cycles that the systemspends on context switches cannotbe spent on applications such asWeb servers. Although measuringthe latency of a context switch isnontrivial, 5ms–10ms per switch is aballpark and even optimistic range.Pre-forking mitigates the inefficiencyof process creation and destruction butdoes not eliminate context switching.What good is multiprocessing? Theprocess structure frees the programmerfrom synchronizing concurrent accessto shared memory locations. Imagine,for example, a Web application thatlets a user play a simple word game.The application displays scrambledletters, such as “kcddoe”, and a playertries to unscramble the letters toform a word—in this case, “docked”.This is a single-player game, and theapplication must track the game’sstate: the string to be unscrambled,WWW.LINUXJOURNAL.COM / FEBRUARY <strong>2012</strong> / 85


FEATURE Three Ways to Web Server ConcurrencyListing 3. threading_server.c#include #include #include #include #include #include #include "utils.h"/* thread routine */void* handle_client(void* client_ptr) {pthread_detach(pthread_self()); /* terminates on return *//* read/write socket */int client = *((int*) client_ptr);/* request */char buffer[BUFF_SIZE + 1];bzero(buffer, sizeof(buffer));int bytes_read = recv(client, buffer, sizeof(buffer), 0);if (bytes_read < 0) error_msg("Problem with recv call", false);/* response */char response[BUFF_SIZE * 2];bzero(response, sizeof(response));generate_echo_response(buffer, response);int bytes_written = send(client, response, strlen(response), 0);if (bytes_written < 0) error_msg("Problem with send call", false);close(client);return NULL;} /* detached thread terminates on return */int main() {char buffer[BUFF_SIZE + 1];struct sockaddr_in client_addr;socklen_t len = sizeof(struct sockaddr_in);/* listening socket */int sock = create_server_socket(false);/* connections */while (true) {int client = accept(sock,(struct sockaddr*) &client_addr,&len);if (client < 0) error_msg("Problem accepting a➥client request", true);announce_client(&client_addr.sin_addr);/* client handler */pthread_t tid;int flag = pthread_create(&tid, /* id */NULL, /* attributes */handle_client, /* routine */&client); /* routine's arg */if (flag < 0) error_msg("Problem creating thread", false);}return 0;}the player’s movement of letters one ata time and on so. Suppose that there isa global variable:typedef struct {/* variables to track game's state */} WordGame;WordGame game; /* single, global instance */so that the application has, in the sourcecode, exactly one WordGame instancevisible across the application’s functions(for example, move_letter, submit_guess).Concurrent players need separateWordGames, so that one player cannotinterfere with another’s game.Now, consider two child processesC1 and C2, each handling a player.Under <strong>Linux</strong>, a forked child inheritsits parent’s address space; hence,C1 and C2 begin with the sameaddress space as each other and theirparent. If none of the three processesthereafter executes a write operation,no harm results. The need for separateaddress spaces first arises with writeoperations. <strong>Linux</strong> thus enforces acopy-on-write (COW) policy withrespect to memory pages. If C1 orC2 performs a write operation on aninherited page, this child gets its owncopy of the page, and the child’s pagetable is updated. In effect, therefore,the parent and the forked childrenhave separate address spaces, andeach client effectively has its owncopy of the writable WordGame.86 / FEBRUARY <strong>2012</strong> / WWW.LINUXJOURNAL.COM


A Multithreading ServerThe multithreading_server shown inListing 3 avoids the context-switchdownside of the forking_server butfaces challenges of its own. Eachprocess has at least one thread ofexecution. A single multithreadedprocess has multiple threads. Thethreading_server is multithreaded.The threading_server mimics thedivision-of-labor strategy in theforking_server, but the client handlers arenow threads within a single process insteadof forked child processes. This difference ishuge. Thanks to COW, separate processeseffectively have separate address spaces,but separate threads within a processshare one address space.When a client connects, thethreading_server delegates thehandling to a new thread:WordGame game; /* one instance */could become an array of these:WordGame games[BACKLOG]; /* BACKLOG == max clients */When a client connects, thethreading_server could search for anavailable game instance and pass thisto the client-handling thread:int game_index = get_open_game(); /* called in main so thread safe */In the function main, thethreading_server would invokeget_open_game, and each client-handlingthread then would have access to itsown WordGame instance:games[game_index].socket = client;pthread_create(&tid, /* id */NULL, /* attributes */pthread_create(&tid, /* id */NULL, /* attributes */handle_client, /* routine */&client); /* arg to routine */The thread gets a unique identifierand executes a thread routine—in thiscase, handle_client. The threading_serverpasses the client socket to the threadroutine, which reads from and writes tothe client.How could the WordGame be portedto the forking_server? This server mustensure one WordGame instance perclient. The single WordGame:handle_client, /* routine */&games[game_index]); /* WordGame arg */A WordGame local to the thread_routinealso would work:void* handle_client(void* client_ptr) {}WordGame game; /* local so thread safe *//* ... */Each thread gets its own copy oflocals, which are thereby threadsafe.Of importance is that the programmerrather than the system ensures oneWWW.LINUXJOURNAL.COM / FEBRUARY <strong>2012</strong> / 87


FEATURE Three Ways to Web Server ConcurrencyWordGame per client.The threading_server would bemore efficient with a thread pool.The pre-forking strategy used inFastCGI for processes extends nicelyto threads.A Polling ServerListing 4 is a polling_server, whichresembles the forking_server in somerespects and the threading_serverin others.The polling_server is complicated:Listing 4. polling_server.c#include #include #include #include #include #include #include #include #include "utils.h"while (true) {socklen_t len = sizeof(client_addr);int client = accept(sock,(struct sockaddr *) &client_addr,&len);/* no client? */if (client < 0 && (EAGAIN == errno ||➥EWOULDBLOCK == errno)) break;#define MAX_BUFFERS (BACKLOG + 1) /* max clients + listener */int main() {char buffer[BUFF_SIZE + 1];/* epoll structures */struct epoll_event event, /* server2epoll */event_buffers[MAX_BUFFERS]; /* epoll2server */int epollfd = epoll_create(MAX_BUFFERS); /* arg just a hint */if (epollfd &lt; 0) error_msg("Problem with epoll_create",➥true);struct sockaddr_in client_addr;socklen_t len = sizeof(struct sockaddr_in);int sock = create_server_socket(true); /* non-blocking *//* polling */event.events = EPOLLIN | EPOLLET; /* incoming, edge-triggered */event.data.fd = sock; /* register listener */if (epoll_ctl(epollfd, EPOLL_CTL_ADD, sock, &event) < 0)error_msg("Problem with epoll_ctl call", true);/* connections + requests */while (true) {/* event count */int n = epoll_wait(epollfd, event_buffers, MAX_BUFFERS, -1);if (n < 0) error_msg("Problem with epoll_wait call", true);/*-- If connection, add to polling: may be none or more-- If request, read and echo*/int i;for (i = 0; i < n; i++) {/* listener? */if (event_buffers[i].data.fd == sock) {}}}/* client */fcntl(client, F_SETFL, O_NONBLOCK); /* non-blocking */event.events = EPOLLIN | EPOLLET; /* incoming,edge-triggered */event.data.fd = client;if (epoll_ctl(epollfd, EPOLL_CTL_ADD, client, &event) < 0)error_msg("Problem with epoll_ctl ADD call", false);announce_client(&client_addr.sin_addr);}}/* request */else {bzero(buffer, sizeof(buffer));int bytes_read = recv(event_buffers[i].data.fd, buffer,➥sizeof(buffer), 0);/* echo request */if (bytes_read < 0) {char response[BUFF_SIZE * 2];bzero(response, sizeof(response));generate_echo_response(buffer, response);int bytes_written =send(event_buffers[i].data.fd, response,➥strlen(response), 0);if (bytes_written < 0) error_msg("Problem with➥send call", false);}return 0;}close(event_buffers[i].data.fd); /* epoll stopspolling fd */88 / FEBRUARY <strong>2012</strong> / WWW.LINUXJOURNAL.COM


while (true) /* listening loop */for (...) /* event loop */if (...) /* accepting event? */while (true) /* accepting loop */else /* request event */array of epoll structures to record suchevents. The division of labor is:n The polling_server registers events ofinterest with epoll.This server executes as one threadin one process and so must supportconcurrency by jumping quickly fromone task (for example, acceptingconnections) to another (for example,reading requests). These nimble jumpsare among nonblocking I/O operations,in particular calls to accept (connections)and recv (requests).The polling_server’s call to acceptreturns immediately:n If there are no clients waiting toconnect, the server moves on to checkwhether there are requests to read.n If there are waiting clients, thepolling_server accepts them in a loop.The polling_server uses the epollsystem library, declaring a single epollstructure and an array of these:struct epoll_eventevent, /* from server to epoll */event_buffers[MAX_EVENTS]; /* from epoll to server */The server uses the single structure toregister interest in connections on thelistening socket and in requests on theclient sockets. The epoll library uses then The epoll library records detectedevents in epoll_event structures.n The polling_server handlesepoll-detected events.The polling_server is interested inincoming (EPOLLIN) events and inLow Cost Panel PCPDX-057Tl Vortex86DX 1 GHz Fanless CPUl 5.7" VGA LCD with Touchscreenl 1 RS232/422/485 serial portl Mini-PCI Expansion slotl 2 USB 2.0 Host Portsl 10/100 BaseT Ethernet & Audiol PS/2 mouse & keyboardl CompactFlash & MicroSD card socketsl Resolution/Colors: 640 x 480 @ 256Kl Low Power Consumptionl <strong>Linux</strong>, Embedded XP or Windows CE OS Optionsl Wide Input Voltage and Wireless OptionsSince 1985OVER24YEARS OFSINGLE BOARDSOLUTIONS2.6 KERNELSetting up a Panel PC can be a Puzzling experience. However, the PDX-057Tcomes ready to run with <strong>Linux</strong> Operating System installed on flash disk. Just applypower and watch the <strong>Linux</strong> X-Windows desktop User Interface appear on the vividcolor LCD . Interact with the PDX-057T using the responsive integratedtouchscreen. Everything works out of the box, allowing you to concentrate on yourapplication rather than building and configuring device drivers. Just Write-It andRun-It... Starting at $440 Qty 1.For more info visit: www.emacinc.com/panel_pc/pdx089.htmEQUIPMENT MONITOR AND CONTROLPhone: (618) 529-4525 · Fax: (618) 457-0110 · www.emacinc.comWWW.LINUXJOURNAL.COM / FEBRUARY <strong>2012</strong> / 89


FEATURE Three Ways to Web Server ConcurrencyUnlike the forking_server, the polling_serverdoes not incur the cost of context switchesamong forked children.edge-triggered (EPOLLET) rather thanlevel-triggered events. The distinctioncomes from digital logic design butexamples abound. A red traffic lightis a level-triggered event signalingthat a vehicle should remain stopped,whereas the transition from green tored is an edge-triggered event signalingthat a vehicle should come to a stop.The polling_server is interested inconnecting and requesting eventswhen these first occur.A for loop iterates through detectedevents. Above the loop, the statement:int n = epoll_wait(epollfd, event_buffers, MAX_EVENTS, -1);gets an event count, where the eventsare either connections or requests.My polling_server takes a shortcut.When the server reads a request, it readsonly the bytes then available. Yet theserver might require several reads to getthe full request; hence, the server shouldbuffer the partials until the request iscomplete. I leave this fix as an exercisefor the reader.How could the WordGame be portedto the polling_server? This server, likethe threading_server, must ensureone WordGame instance per clientand must coordinate a client’s accessto its WordGame. On the upside,the polling_server is single-threadedand thereby threadsafe. Unlike theforking_server, the polling_server doesnot incur the cost of context switchesamong forked children.ConclusionsWhich is the best way to clientconcurrency? A reasoned answer mustconsider traditional multiprocessing andmultithreading, together with hybrids ofthese. The “evented I/O” way that epollexemplifies also deserves study. In theend, the selected method must meet thechallenges of supporting concurrencyacross real-world Web applications underreal-world conditions.■Martin Kalin is a professor at the College of Computing and <strong>Digital</strong>Media at DePaul University, Chicago, Illinois. He earned his PhD atNorthwestern University. Martin has co-authored various books onC and C++, authored a book on Java and, most recently, a bookon Java Web services.ResourcesThe three Web servers together withan iterative_server are available athttp://condor.depaul.edu/mkalin.For more on Node.js, see: http://nodejs.org.90 / FEBRUARY <strong>2012</strong> / WWW.LINUXJOURNAL.COM


Please visit us at http://northeastlinuxfest.org for more informationJoin us for the 2 nd annualNortheast GNU-<strong>Linux</strong>fest!MARCH 17, <strong>2012</strong>WORCESTER STATE UNIVERSITYSTUDENT CENTER486 CHANDLER STREETWORCESTER MAhttp://northeastlinuxfest.orghttp://northeastlinuxfest.orgAmong the highlights -Speakers:Dru LavigneJohn SullivanJames TurkEventsHackerspace competitionOpen Street Map workshopLPI & BSD examsPlease visit us at http://northeastlinuxfest.org for moreinformation


HTML5forAudioApplicationsHTML5 lets you play music throughcompliant browsers—no “cloud” required.PAUL FREITASRecently, “cloud”-based music services, from big names likeAmazon, Google and Apple, have been getting attention inthe press. These services allow you to store your music ona corporate server and access it through your own Internetconnecteddevice anytime you like. It’s easy to see the appeal ofthese services. This is the kind of thing the Internet is for, right?92 / FEBRUARY <strong>2012</strong> / WWW.LINUXJOURNAL.COM


If you’re reading this article, you’reprobably a <strong>Linux</strong> user, and as oftenhappens, support for <strong>Linux</strong> is beingneglected by these big corporatesolutions. For example, Apple’sservice relies on its proprietary iTunesapplication, which doesn’t exist in <strong>Linux</strong>.Other products have a Web interface,but uploading works only through aproprietary “app” not available for <strong>Linux</strong>users. Who wants to use proprietarysoftware anyway? File-type support islimited as well with all the corporateproducts I’ve mentioned. Most of myown music is stored in Ogg Vorbis files,and none of the big company servicesFox Agency.) Cloud services can’t helpyou. Also, transfer to the service is oneway.Aside from listening to your music,once you transfer music to the service,you can’t download it again easily ifsomething happens to your personalstorage. What if you want to use yourown storage solution, like your ownpersonal (and appropriately secured)Internet-accessible Web server? What ifyou live outside the United States, wheresome cloud services are not yet available?All these problems make “cloud”solutions more like fog, obscuring thetruth that there is another way. ModernHTML5-compliant Web browsers likeAll these problems make “cloud” solutions more like fog,obscuring the truth that there is another way.seem to support it, lack of patentsnotwithstanding. There also are financialcosts associated with the corporateofferings (explicit fees comparable toInternet-hosting costs, vendor lock-inand so on) that also are unattractive.“Cloud” music services have otherdownsides as well. They are all intendedfor personal use. What if you want toshare music with other people? (I am,of course, talking about legal musicsharing involving files with CreativeCommons-type free licensing or recordedcover songs with appropriate royaltypayments being made to songwritersthrough licensing agencies like the HarryChrome, Firefox (Iceweasel to Debianusers) and Apple’s Safari all support theHTML5 audio element, which can makeaudio files as easy to handle as imagefiles. Adobe Flash is not necessary. AnyWeb server can be your own personal“cloud” server that you can use forpersonal or business use. With somecustomized HTML and JavaScript, theinterface can be anything you want.Let’s see how.Playing Music through Your BrowserA typical browser supports multipleaudio file types, regardless of theoperating system running it. They allWWW.LINUXJOURNAL.COM / FEBRUARY <strong>2012</strong> / 93


FEATURE HTML5 for Audio Applicationssupport different file types, however,and there are some interestingsurprises, the most notable one beingthat Firefox/Iceweasel doesn’t supportMP3 files because of patent andlicensing issues. That’s okay, becauseit supports the patent-unencumberedOgg Vorbis format used by many <strong>Linux</strong>users. So does Google’s Chrome, andeven Apple’s Safari can play Ogg Vorbiswith Xiph’s QuickTime Componentsinstalled (see Resources).Let’s try it. Imagine you have anOgg Vorbis file named test.ogg in thedirectory /home/me/music/. You can openit in a <strong>Linux</strong>-based browser like Chromeor Firefox with the URL file:///home/me/music/test.ogg. Your browser should loadthe file and start to play it. You’ll see aplayer in the browser tab/window similarto the one shown in Figure 1.Figure 1. Google Chrome’s default audio playercontrol—other browsers have similar controlsets, but different appearances.Browsers render controls differently,but you’ll see all the usual controls:play/pause button, position slider, currenttrack position indicator and volumecontrol. Note how much HTML you’vehad to write so far: none. If all you reallywant to do is play one file at a time,and you don’t care what exactly showsup in the browser window, you canstop reading now.Most Web users care aboutappearances, so the default audiocontrols alone probably won’t cut it formost people. Fortunately, you can putan audio player explicitly in any HTMLpage. It’s a lot like adding an image to apage. Instead of using an img element,you use an audio element, and thesyntax of the two elements is similar. Forexample, to load and play test.ogg in anotherwise-empty HTML page using thebrowser’s default controls, you could usethe following page:Get an HTML5 browser!Note that HTML5 simplifies the syntaxof the root HTML element from whatyou might be used to. The message “Getan HTML5 browser!” will appear onlywhen the page is loaded in a non-HTML5browser. Other users will see a playerelement like the one shown in Figure 1,thanks to the controls attribute beingset. By default, the audio element hasno controls. (HTML5 allows you to set anattribute without a value. If you prefersomething more XML-like, you can set anattribute to itself instead—for example,controls="controls".)It’s easy to modify the audio tag forsome simple use cases. If you want a94 / FEBRUARY <strong>2012</strong> / WWW.LINUXJOURNAL.COM


sound clip to play in the backgroundwith no controls, you can omit thecontrols attribute:Get an HTML5 browser!You can add a loop attribute to makethe audio file restart upon completion:A browser will attempt to read andplay test.ogg first. If it fails for whateverreason (it can’t find the file, it can’tplay that file type and so on), it simplywill move on to test.mp3 and use thatinstead. Use as many source elementsas you like, although in practice, two isusually enough.Get an HTML5 browser!As I mentioned earlier, differentbrowsers support different file formats,and they aren’t all the same. OggVorbis works for Chrome, Firefox andSafari (with Xiph’s extension), but otherbrowsers need something else, like MP3.At the time of this writing, it seems thatall browsers support one or the other,but not necessarily both. What can youdo to fix this problem?HTML5 has another element calledsource that replaces the src attribute ofthe audio tag. It goes inside the audioelement. Unlike the src attribute, you canhave multiple source elements inside anaudio tag. A browser will load the filereferenced by the first source element itfinds that it can actually work with. Let’slook at the first example again, this timewith source attributes:Get an HTML5 browser!Adding a Custom User InterfaceThese simple examples have their uses,of course. Still, most Web developersrather would see a more-consistentuser interface than these examplescan provide. Having three differentUIs appear on three different browserscan affect the usability of a pagedramatically. For a professional site,you’ll need a professional-lookingpage. Fortunately, the audio elementhas a JavaScript API you can use tocontrol the player in real time. To getthe interface you want, write it usingstandard HTML techniques, and setevent handlers to access the audioplayer via JavaScript’s API.Here’s a simple example. The followingpage displays a single play/pause buttoninstead of the native controls:Get an HTML5 browser!WWW.LINUXJOURNAL.COM / FEBRUARY <strong>2012</strong> / 95


FEATURE HTML5 for Audio Applicationsvar audioPlayer = document.getElementById("player");function PlayPause(){}if (audioPlayer.paused){}else{}audioPlayer.play();document.getElementById("playpause").value = "Pause";audioPlayer.pause();document.getElementById("playpause").value = "Play";After the page loads, press the Playbutton to start playing test.ogg in a loop.When a user presses the button, thebrowser calls the audio player object’splay() function to start playing thetrack. The button label then changesto Pause. You then can press the samebutton to pause the audio, which callsthe audio player object’s pause()function to pause playback.There are many attributes and methodsassociated with an audio player. Youcan change the current play time of theplayer by changing the currentTimeproperty. Change the volume bychanging the volume attribute. Thereare many others, not all of themimplemented in all browsers at the timeof this writing. For more information,see the W3C HTML5 specification listedin the Resources section of this article,as well as the documentation for yourpreferred browser.A More-Detailed Example: PlaylistHTML5 Audio PlayerBy now you’ve seen the basicsof developing HTML5 for audioapplications. You might want to see amore-detailed example. Unfortunately,magazine articles are limited in size,and Web development code takes upa lot of space. Instead, I’d like to referyou to an open-source project I’vewritten called the Playlist HTML5 AudioPlayer (see Resources). Here is somebackground on the project.The goal of Playlist is to provide auser interface for playing a collectionof audio files in series, like an album ofrecorded music. To use the interface, allyou need are a collection of audio filesand a text file, called a playlist, thatlists the files individually. If cover art isavailable, Playlist will show that as well.Playlist also can load extra informationabout the collection for display in itsAbout tab. Neither of the last two itemsare required. Figure 2 shows Playlistplaying some freely redistributablesample music.Playlist supports controls commonlyfound on a car’s CD player, including ashuffle button. It will loop through the96 / FEBRUARY <strong>2012</strong> / WWW.LINUXJOURNAL.COM


Figure 2. Playlist HTML5 Audio Player Playing Some Freely RedistributableSample Musicchosen playlist indefinitely until youpause it. It has jQuery-based controlsand tabs, which allow you to changethe appearance easily using jQuery’sThemeroller tool. Thanks to jQuery’stable-sorting and re-ordering abilities,you can re-organize the track order inthe Playlist tab any way you like for theduration of the session. For example,Wikipedia says that the Beatles’ song“Her Majesty” originally appearedbetween “Mean Mr. Mustard” and“Polythene Pam”on the Abbey Roadalbum. With Playlist,you can drag itfrom the end of thealbum and drop itbetween the othertwo tracks to hearwhat that actuallysounds like. Playlistis client-side only,so the next time youload your AbbeyRoad page, “HerMajesty” will beback at the end ofthe album again.You can usePlaylist for yourown personal musiccollection on yourown computerthrough its ownWeb server. Ifyou want the full“cloud” experience, you also can useit on your own Web site on any of theubiquitous Web-hosting services thatare available today. You don’t needany special server-side tools like PHPor MySQL, because Playlist contains noserver-side code. You can access yourmusic locally or remotely, through anyHTML5-compliant browser that supportsyour preferred audio file type. I usePlaylist for my own music collection, andfor my purposes, it works as well as orWWW.LINUXJOURNAL.COM / FEBRUARY <strong>2012</strong> / 97


FEATURE HTML5 for Audio Applicationsbetter than <strong>Linux</strong> players like Rhythmbox,Exaile and Amarok.Playlist also can be useful formore-commercial applications. Bands,musicians and songwriters oftenwant to distribute recordings of theirown work as part of their overallpromotional strategy. If the recording isof original music, something like Playlistcan be used directly. If any of the songsare re-recordings of other songwriters’work, appropriate licenses must beobtained, such as the mechanicallicenses available for US distributionfrom the Harry Fox Agency. Accountingfor such licenses must happen at leastin part on the server, but you still canuse Playlist for the UI.Installing Playlist is reasonablystraightforward. In its most simpleform, Playlist HTML5 Audio Playerconsists of a series of ordinary Webfiles, including Playlist.html (anHTML5 file), Playlist.js (a JavaScriptfile) and a series of accessory files,including images and jQuery themingelements. All these files are containedin a directory named jsapps (think“JavaScript Applications”). Drop thisfolder on a Web server where it canbe accessed easily. The content to beplayed (which is, of course, separatedfrom the player) goes somewhere elsethat makes logical sense to your site,like a folder named music at the samelevel as jsapps.Once your audio files are in place, youwill need a text file in the same directorynamed Playlist.m3u that lists the files toplay. For example, if you have two tracksnamed Track1.ogg and Track2.ogg, yourfile would look like this:Track1.oggTrack2.oggYou can use command-line tools likels or GUI tools like Audio Tag Tool tocreate Playlist.m3u more easily.Finally, you need a file that redirectsthe browser to Playlist.html in thejsapps directory, along with queryparameters that reference the Playlistfile. For your convenience, there’sone named redirect.html in thejsapps/playlist directory that will dothe job via JavaScript. Copy or linkthat file into your music’s directory,alongside Playlist.m3u. I often namethe redirect file index.html. Add coverart (Cover.jpg) and HTML-formattedadditional information (About.xml) ifyou like. You’re done. Browse to theredirect file and see what happens.I have Playlist set up on my ownWeb site so you can easily try it (seeResources). To try Playlist on your ownmachine, download it from the projecthome on SourceForge (see Resources).I’ve packaged it inside a version of Jetty,an open-source Java-based Web serverthat will run on any platform with a JavaRuntime Environment. I’ve added Jettyas a convenience, but you don’t need98 / FEBRUARY <strong>2012</strong> / WWW.LINUXJOURNAL.COM


to use it. You either can download thesource from the project page with Gitor get the full download with Jetty andcopy the music and jsapps directoriesout of Jetty’s webapps directory intoan appropriate location on your ownWeb server. If you want to use Jetty,run start.sh (or start.bat inWindows) to get the server going, thenbrowse to it via port 8080 (for example,http://localhost:8080/music). All of thesetest cases will cause freely redistributablesample music to play that will give youan idea of Playlist’s capabilities.server configuration files (includingApache’s htaccess and norobots.txt),user authentication and othercommon-sense server-side strategiescan help you enjoy your audioanywhere while keeping your privatemusic collection private. If you’redistributing music legally, make sureyou have all appropriate rights andlicenses, mechanical and otherwise.■Paul Freitas (paulfreitas.com) is an independent technologyconsultant based in Boise, Idaho.Conclusion (and Warning)HTML5 is a powerful tool for listeningto audio via the Internet, as powerfulas anything the “cloud” services haveto offer and much more versatile.Coding audio into HTML5 pages isfairly straightforward. If writing HTMLdoesn’t interest you and you’re lookingfor a packaged solution, try my opensourcedPlaylist HTML5 Audio Player.I’ll end with a warning. With HTML5’sgreat power comes great responsibility—to yourself first and foremost. We’veall heard about lawsuits and arrestsrelated to copyright violations andfile sharing. You don’t want to bepart of that.To protect yourself, use HTML5 audioresponsibly. Don’t put nonfree musicin a publicly accessible or searchengine-crawlablelocation on any Webserver. Firewalls, SSL certificates, WebResourcesHTML5 in General: http://www.w3.org/TR/html5HTML5’s Audio Element in Detail:http://www.w3.org/TR/html5/the-iframe-element.html#the-audio-elementXiph.org’s QuickTime Components:http://www.xiph.org/quicktimePlaylist HTML5 Audio Player:https://sourceforge.net/projects/playlistplayerJQuery: http://jquery.comAn example of Playlist, served from my ownWeb site and playing music with a free license:http://paulfreitas.com/jsapps/playlist/Playlist.html?/music/Brad%20Sucks/I%20Don't%20Know%20What%20I'm%20Doing/Playlist.m3uHarry Fox Agency’s Web Site (for obtaining“cover music” mechanical licenses):http://www.harryfox.comWWW.LINUXJOURNAL.COM / FEBRUARY <strong>2012</strong> / 99


BasicWebDesignwithDrupal 7Using Drupal to manage and display data.KENNETH P. J. DYERDrupal is one of the most popularand versatile platforms for Webdesign. It’s free, open sourceand will run on <strong>Linux</strong>. Early last year,a new version was released (Drupal 7),making it even better with improvementsin usability, performance and security.If you’ve looked at Drupal before, butdidn’t end up using it, you may want totake another look.Drupal is built using a modularstructure to accommodate extensionsfrom third-party developers. Thesemodules allow you to add features thatotherwise might be unavailable. Theimprovements to Drupal 7 make them farmore accessible and easier for new users.This article covers the basics of creatinga data scheme (that is, content types), howto manipulate that data (that is, views) andfundamental ways to display data in Drupal7. For the examples in this article, I useproducts of a business site that sells writinginstruments. I assume you have alreadydownloaded the Drupal 7 from drupal.organd have installed it successfully.100 / FEBRUARY <strong>2012</strong> / WWW.LINUXJOURNAL.COM


Content TypesA content type is simply a definition of atable of data, such as text, numbers andimages. Behind the scenes, Drupal usesMySQL for storing data. When you createa content type in Drupal, in essence,you’re creating a table in MySQL andsetting the columns in MySQL. Forthis example writing instruments site,let’s create a content type for theproducts. It will include the name anddescription, as well as a field for storinga photograph of each product.To create a content type, you needto do a few things. After logging in toDrupal as an administrator, go to theAdministration page. From there, clickthe link for Structure. On the Structurepage, click on Content Types. On theContent Types page, click the Add contenttype link. Incidentally, in the Drupalcommunity, navigation to this pagewould be described typically in a shortermethod: Click on Administration→Structure→Content Types→Add contenttype. This menu-tree method generallyis accompanied with an absolutepath for the domain shown withinparentheses (for example, /admin/structure/types/add). From this pointon, I use the shortened method.After you’ve opened the admin pagefor creating a content type (Figure 1), inthe Name field, enter “Product”. Leavethe rest, and click the button that reads“Save and Add Fields”. On the nextpage, you’ll see a table with a few fieldsFigure 1. Content Type Add Fields(for example, Title, Body). Let’s add acouple more for the site’s specific needs.In the Add new field section, type inthe first box, “Product Image”. For theName column, enter “product_image”(this creates a field in MySQL,field_product_image). For the Field Type,select “Image” from the drop-downlist. Now click Save. On the next twoscreens, accept the defaults and clickthe save buttons for each page.Completion of the above will take youback to the table of fields for Product.Now, let’s add another field to indicatewhether an item is a pen or a pencil. Callit “Product Type”, and set the Field Typeto “List (text)”, leaving the Widget setto Select List, so that when content isentered later, you can select the producttype from a list. This time after you save,you’ll see a form containing a field called,“Allowed values list”. Enter in that field,on separate lines, “1|Pen” and “2|Pencil”(without the quotation marks). This isa key and value hash that will becomethe available choices for users. Now saveyour way out, accepting default settings.The field list should then look like thescreenshot shown in Figure 2.WWW.LINUXJOURNAL.COM / FEBRUARY <strong>2012</strong> / 101


FEATURE Basic Web Design with Drupal 7Figure 2. Product Type Manage FieldsYou may want to experiment and adda few more fields (such as Price, InkColor and so on). Otherwise, you nowcan create products on the site. To makethings easier to understand, add a fewpens and pencils. Search the Web forphotos of pens and pencils, and grabthem so you’ll have images to go withthe products you add. To enter products,go to Administration→Content→Addcontent and click on the contenttype, “Product” (/node/add/product).If you make a mistake and want tochange a product after it’s saved, orif you just want to see a list ofproducts, go to Administration→Content(/admin/content). There, select the type,“Product”, and click Filter to showonly products (Figure 3).Building ViewsEach content entry that you create, youcan access individually, as an on-the-flypage, which are referred to as nodes.However, let’s also create a page that listsFigure 3. Content ListFigure 4. Add New View102 / FEBRUARY <strong>2012</strong> / WWW.LINUXJOURNAL.COM


all of the products with links to thesenodes. To do this, you need to create aview. A view allows you to aggregateand arrange content on a site, and toorganize and group data based on fieldvalues and other factors.To create a view showing a list of pensand pencils, go to Administration→Structure→Views, and then click on“Add new view” (/admin/structure/views/add). This displays a form (Figure4) for creating a page—one that drawsdata from MySQL and generates a Webpage when called.In the View Name field, enter“Product List”. In the section thatbegins with Show, you can selectthe kind of view to create. For ourpurposes, select “Content”. To theright of this, after the options update,you may select the content type toshow. Choose “Product” from thelist. If you hadn’t noticed, this form issomething of a wizard. Now change thesorting method to “Unsorted”.Next you have two check boxes: one forcreating a page and another for creatinga block. Basically, pages in this senseare views and may be used to generatestandalone pages. Blocks are views thatcan display the same information, but thatmay be used as components within otherpages. Pages are better at this point, socheck “Create a page”.In the section that opens for creatinga page, type in a title for the top of thepage. Next enter the file path. The wizardprovides the domain name and leadingslash. Just add the page name in thebox as “product-list”. This means thatwhen people using a Web browser go tohttp://domain_name.com/product-list,they will see the results of the display.Next, you need to set the display format.For what’s to come, choose Grid ofFields. Ignore the other settings andclick the button, “Continue & Edit” totweak the view further.In the Fields section, by default, theview creates a Title field. Let’s add atleast two more fields. Click on the link“add” across from the FIELDS labelto add a field. This lists many fieldsthat may be added. Scan the list for“Content: Product Type”—that’s theFigure 5. Product List ViewWWW.LINUXJOURNAL.COM / FEBRUARY <strong>2012</strong> / 103


FEATURE Basic Web Design with Drupal 7one for choosing whether a product isa pen or pencil. When you find it, clickthe check box next to it. Probably justabove it, you will find “Content: ProductImage”. Check that as well. Then clickthe button at the bottom, labeled “Addand configure fields”.The fields configuration page opensfor each of the fields you’re adding, oneat a time. For the Product Type field,check the box that says, “Exclude fromdisplay”, since it won’t be necessaryto display the word Pen for each pen.Instead, let’s use this field for groupingthe data. Now, click the Apply button.When you see the form for ProductImage, for style preferences, ensurethat “Create a label” is unchecked. Forthe Image Style, select “thumbnail”from the list and then click Apply. Yourpage should look like the screenshotshown in Figure 5.Now that you’ve added the ProductType field, you can use it for groupingthe products. To do this, in the Formatsection, next to the Grid link, click on thelink for its Settings. Near the top of thebox that opens, where it says “Groupingfield”, choose “Content: Product Type”from the list. Enter 4 in the field for thenumber of columns and then click Apply.The name of each item and its photonow appear in the display, but eachproduct is grouped based on whetherit’s a pen or a pencil. A larger, boldfacedheading appears for each group.Click on the button near the bottomFigure 6. Product List Pagelabeled “Update Preview”, so that youcan see the results of the query in MySQLgenerated by the view.By default, the view sorts the groupsof products in descending alphanumericalorder, based on their Product Typeheadings. So, the pencils display beforethe pens. Because there’s more money inpens than mechanical pencils, you mightwant to put pens first. You can reversethe order by adding a Sort Criteria for“Content: Product Type” and setting itto “Sort ascending”.There’s plenty more that you can do,but this is enough to get started. Clickthe Save button at the top right. Then,check the results of your efforts byopening the page that users will see(/product-lists).Notice in Figure 6 that the pens aregrouped together, separated from themechanical pencils. Because I enteredcontent entries for four pens and fourpencils for testing and set the number104 / FEBRUARY <strong>2012</strong> / WWW.LINUXJOURNAL.COM


of columns to four in the view, theresults are showing only four of each inone row. Had I entered eight pens, tworows of pens would show. The name ofeach pen and pencil functions as a linkto the node, which presents a largerphoto of the product, as well as all ofthe other information on the pen andany other fields I may have added. Youcan adjust the view to provide moreinformation at this level. You also canhave the links set to go to a differentpage generated by the view. And, youcan change the formatting (that is, CSSusing the CSS Injector module) to alterthe colors and layout, as well as choosea different theme for Drupal. However,what I’ve done here demonstrates thebasics of creating a content type and aview to filter and organize the data fora particular content, as well as how todisplay that data dynamically.Other Considerations: TaxonomyHaving explained the absolute basicsof using Drupal to manage and displaydata, I would be remiss in speaking oncontent types and views if I did not alsomention the advantages of the Taxonomymodule. Taxonomy is a property inwhich a vocabulary of related words areassembled. In the example site, I’m usingthe Product Type field to differentiatebetween different kinds of productsavailable. This arrangement works fineif all you have are two kinds of productsand rarely change them, but it provescumbersome if the list of product types islong or were to change occasionally.For instance, instead of just pen, youmay want to distinguish between ballpointpens, felt-tip pens and fountainpens. You might want to have woodenpencils and mechanical pencils insteadof just a product type of pencil. Youmay want to rearrange the ordering ofthe products so that red felt-tip pensappear above blue ball-points, but do notovershadow orange fountain pens. Themore complex the list of product types,the less feasible it becomes to handlethem within a field in the content type,and the more reasonable it becomes toadopt taxonomy instead.The Taxonomy module allows you tocreate lists of custom values for use inorganizing your products. Unlike, thepresent Product Type field, these values,called terms, provide more configurationoptions, allowing you greater precision inadding and arranging new product types.Terms do not exist on their own inDrupal. Instead, you create them in listscalled vocabularies. A vocabulary allowsyou to keep all related terms togetherso that you can add them as possiblevalues for content types. Compared tothe Product Type field in the examplesite, “Pen” and “Pencil” in the “Allowedvalues list” are terms, and collectivelythese terms are a vocabulary.To create a vocabulary, go to theAdministration→Structure→Taxonomypage, and click the “Add vocabulary”WWW.LINUXJOURNAL.COM / FEBRUARY <strong>2012</strong> / 105


FEATURE Basic Web Design with Drupal 7link (/admin/structure/taxonomy/add).In the Name field, enter “ProductTypes”, then save. This returns you tothe Taxonomy page, which has addedan entry for Product Types. To addterms to your vocabulary, click theadd terms link for Product Types. Inthe Name field, enter “Fountain Pen”.Ignore the rest of the settings for nowand click Save. The add term formre-opens. Continue to add terms fordifferent types of writing instruments.In order to use these terms with theproducts, you must replace the existingProduct Type field with a new one thatis linked to the new vocabulary. Goback to the Content types page atAdministration→Structure→ContentTypes. On the listing for Products, click its“Manage Fields” link (/admin/structure/types/manage/product/fields). Click theDelete link for Product Type field. Thenre-create the Product Type field, this timeselecting “Term reference” for the Fieldcolumn. On the field configuration page,at the bottom, from the drop-down listfor Vocabulary select “Product Types”,and then save.The Products content types will updatewith the new field. Although it appearsthe same as the old field, the optionsavailable now are drawn from theTaxonomy, providing easier controlover their arrangement and number.Now that you have deleted theold Product Type field, the productslist view no longer groups resultscorrectly by types of products. To restorethis feature, edit the Product Listview to include the new field. Go toAdministration→Structure→Views(/admin/structure/views), and click theEdit link for Product List. Then add the“Content: Product Type” field usingthe previous configurations. Repeat thesteps given above to format your view,grouping products around the ProductType field. Save when finished.ConclusionYou now should have a good senseof how to create content types andhow to manipulate them with a viewto display data in simple ways withDrupal 7. Now you can start creatingyour own Web sites and learn more asyou go. Compared to other methodsof building Web sites, Drupal mayseem restrictive and awkward at first.However, in time, you will come to seethat it’s powerful and works well in anorganization with many people of varioustechnical backgrounds. Once you’vedeveloped a site, nontechnical users canadd and maintain content easily. Plus,as a developer, with modules, you canadd functionality easily with additionalmodules. If you would like to learn moreabout Drupal 7, see http://drupal.org.■Kenneth P. J. Dyer is a writer living in the Boston area,who has worked on Acquia Drupal’s documentation.He’s from New Orleans, where he studied English andClassical Studies at Loyola University.106 / FEBRUARY <strong>2012</strong> / WWW.LINUXJOURNAL.COM


PRESENTEDBY:FEB 29 - MAR 2 IN MONTREALMaster the art of WebConference for developers160 presentationsExperts from around the worldPHPPythonJavaRubyHTML5JavascriptMobileVisit confoo.ca for more information aboutthe conference and the training.Follow us on Twitter: @confoocaSPONSORED BY:MEDIA SPONSOR:


INDEPTHInterview with DrStephen WolframLJ chats with the developer of Mathematica and theWolfram|Alpha computational knowledge engine. JAMES GRAYThere are myriad ways to describe theprolific Dr Stephen Wolfram—inventor,author, groundbreaking scientist, ITCEO and entrepreneur and MacArthurGenius Grant recipient (also toss inRenaissance man to emphasize thediversity of his achievements). DespiteWolfram’s many laurels, there’s a fairchance you never have heard of him.This accomplished Briton, who haslived most of his adult life here onAmerican soil, developed Mathematica,the world-standard technical computingpackage, and is refining the ambitiousWolfram|Alpha computational knowledgeengine, a long-term project to makethe world’s knowledge computable andaccessible to everyone.Before Mathematica and Wolfram|Alpha,Wolfram published his first scientificpaper at age 15 and knocked out hisPhD in theoretical physics from Caltechby age 20. He’s a man who seems tobe living well ahead of his age as wellas his time.Recently, <strong>Linux</strong> <strong>Journal</strong> caught up withDr Stephen Wolfram to learn more aboutthis fascinating man and the important,cutting-edge work he continues to do.JG: Your “computational knowledgeengine” Wolfram|Alpha has been runningfor more than two years now. How has itbeen doing out in “the real world”? And,are there any surprises regarding who isusing it and how?SW: It was a difficult decisionwhen to first release Wolfram|Alpha.Eventually, we just couldn’t learnmuch more without seeing actualusers using it. Watching that has beenfascinating, and it has let us steadilymake Wolfram|Alpha better. Our goal isto understand queries in whatever forma user chooses to give them—with no“manual”. We have a whole calculus oflinguistic variation, but it’s amazing allthe strange forms people actually use.These days though, we can understandmore than 95% of queries the first time,which I think is pretty good.108 / FEBRUARY <strong>2012</strong> / WWW.LINUXJOURNAL.COM


INDEPTHDr Stephen WolframAs far as users and uses are concerned,I’m continually amazed at the diversityof people I run into who turn out to beavid Wolfram|Alpha users. We intendedWolfram|Alphato become a verywidespread tool,and that’s steadilyhappening.JG: A fellowthinker, Rudy Rucker,called Wolfram|Alphaa “platonic searchengine”—one thatunearths eternal truthsthat may never havebeen written downbefore. Is that anaccurate observation?SW: It’s a nicedescription. At apractical level, Ican say that thesedays the majority ofqueries people enterin Wolfram|Alpha getzero hits in a searchengine. But we canhandle them becausewe’re computinganswers afresh,not trying to findsomething someonehappened to writedown before.Sometimes thetruths we compute are “eternal”, like thesolution of a differential equation or theproperty of a polyhedron. But a lot of theWWW.LINUXJOURNAL.COM / FEBRUARY <strong>2012</strong> / 109


INDEPTHI’ve done some pretty complex projects in mylife, but I have to say that Wolfram|Alpha isoutrageously more complex than any of the others.time, they’re dynamic. They are based ondata that comes from the outside world,like the weather somewhere, or the priceof a stock or the position of a spacecraft.And at some level, what starts as aphilosophical issue about eternal truthsends up as a very practical issue for theWolfram|Alpha caching system.JG: What is your long-term vision forWolfram|Alpha?SW: I’d like to see as much of theworld’s knowledge as possible becomputable, so that it can be usedto answer whatever specific queryone might have. With the progress oftechnology, we’ve been able to automateso many things. But a lot of theachievements of our civilization are stillencapsulated only in the knowledge ofhuman experts. I’d like to automate usingthat knowledge and get to the point thatany question that could be answered bya human expert based on accumulatedknowledge and data can be answeredautomatically by Wolfram|Alpha. I thinkthat kind of automation is going to let ushumans get a lot further on many fronts.At an engineering level, Wolfram|Alphagives us a whole new approach that I call“knowledge-based computing”. We’reused to the idea that software has to bebuilt from raw computational primitives.But Wolfram|Alpha gives us a platformwhere we can in a sense start from theknowledge of the world, and then buildfrom that. The result is a major changein the economics of all sorts of softwaredevelopment, as well as making lots ofnew and sometimes unexpected thingspossible. We’re seeing some of thesethings as Wolfram|Alpha extends fromjust being a Web site to supporting awhole ecosystem.As of right now, Wolfram|Alpha takesshort textual queries and computesresults from them. We’re about to releasea version that can take all sorts of otherinput—whether it’s images or data filesor programs. And we’re going to seeit not just compute results, but alsocause things to happen. For example,last year we released a new version ofMathematica that uses Wolfram|Alphato synthesize runnable programs fromfree-form linguistic input.JG: What have been your technicalchallenges regarding Wolfram|Alpha?SW: I’ve done some pretty complexprojects in my life, but I have to say thatWolfram|Alpha is outrageously morecomplex than any of the others. It’s gotan incredible number of different kindsof moving parts.We’ve got to get computable data110 / FEBRUARY <strong>2012</strong> / WWW.LINUXJOURNAL.COM


INDEPTHabout every kind of thing. We’ve built apipeline for curating data that’s a mixtureof automation and expert human input.And even though we’ve handled thousandsof domains now, it’s amazing that almostevery new one seems to have some newtwist. And, to get it all right often requirestalking to the world expert in that domain.After the data, we’ve got to actuallyimplement all the methods and modelsand algorithms that are needed tocompute useful things from that data.It’s all done in Mathematica (which iswhat makes it possible), but by nowWolfram|Alpha is about 15 million linesof Mathematica code.Then there’s the linguistic understanding,which at first I thought—based on thehistory of natural language processing(NLP)—might just be plain impossible. Butthe problem we’re solving is sort of theinverse of the usual NLP problem, andparticularly by using insights from an areaof basic science that I’ve developed, we’vebeen able to make incredible progress.There are issues with generating outputtoo—automating aesthetic judgmentsand the architecture of informationpresentation. And then, of course, there’slots of supercomputer-style infrastructurethat’s needed to actually run thecomputations for Wolfram|Alpha.From a software-engineering point ofview, we’ve made use of all the tools thatwe’ve developed during the past 25 yearsfor Mathematica. These days, the toolsare almost all written in the Mathematicalanguage, and they do a really goodjob of automating building, testingand deployment. Wolfram|Alpha is anincredibly nontrivial system to monitorand test, but so far we’ve been pushingout new versions successfully every weekever since it launched.JG: I imagine your development teamfor Wolfram|Alpha must be quite eclectic.Can you tell us a little bit about that team?SW: Yes, it’s a very eclectic team. Onthe data and algorithms side, we haveexperts in lots and lots of different fields.For the overall frameworks, I think thehighest concentrations of backgroundsare physics and computer science. There’salso a huge concentration—particularly inthe linguistic algorithms area—of peoplewho’ve worked on science based on mybook A New Kind of Science.Wolfram|Alpha almost by definitionrequires incredible diversity of skills andknowledge. We’ve ended up having tokeep a WhoKnowsWhat database atour company so we can quickly findwho might happen to know aboutforestry, or Vietnamese character sets,or machine tools or whatever.It’s also interesting that Wolfram|Alphaneeds people with skills that I doubt haveever been defined before—for example,linguistic curation.JG: As you look back on 25years and eight versions of youroriginal and flagship application,Mathematica, how would you assessits impact and importance in theWWW.LINUXJOURNAL.COM / FEBRUARY <strong>2012</strong> / 111


INDEPTHworld of technical computing?SW: Before Mathematica, it wasreally rare for technical people to “dotheir own computing”. They usuallyhad to have special “programmers”who did it. Mathematica has made thatunnecessary, and the result is that anawful lot of advances have been made.It’s pretty satisfying to see how much hasbeen discovered and invented throughthe years with Mathematica. Fields likeexperimental mathematics have prettymuch been made possible by it.I’m not quite sure, but I think Iprobably coined the term “technicalcomputing”—not that I like it verymuch. I have to say that I think wepretty much defined what “technicalcomputing” should be. Through theyears, we’ve redefined it a few times,and I think that particularly as webring Wolfram|Alpha and Mathematicatogether, we’re going to see the mostdramatic changes that have happenedsince we first released Mathematica.Even after 25 years though, the storyof Mathematica is only just beginning.Through the years, I’ve slowly understoodmore and more that’s possible onthe basis of the fundamental ideas inMathematica, like symbolic programming.We’re now pretty much finished with theto-do lists that I had for Mathematica inthe late 1980s, but now I realize there’sso much more that’s possible.Through the years, Mathematica hasemerged as an incredibly strong platformfor algorithm-rich software development.We certainly use it very successfullyfor pretty much everything at ourcompany, and of course, it’s the basis forWolfram|Alpha. It’s used in plenty of otherorganizations too, but we’re buildingsome things now that I suspect will makeit a lot more widespread in the future.JG: Can you share some interestinginsights about Mathematica that wouldinterest our technical readers?SW: At a technical level, the core ofMathematica is its symbolic programminglanguage. And, that language is basedon one big idea: that everything—whether it’s data, documents, programs,interfaces, whatever—can be representedin a very uniform way, as a symbolicexpression. And because of thatunification, it’s possible to have a fairlysmall number of very powerful primitivesthat give a vast amount of functionality.In terms of scope, we’ve had a prettysimple principle: just implement everydefinite algorithm we can. At thebeginning, we emphasized things thatwould often be classified as “math”, butwe long ago expanded far, far, beyondthat. Whether it’s image processing, orcontrol theory, or network analysis or textprocessing, if there are useful algorithms,they’re probably in Mathematica.A strong principle in developingMathematica has been to automateas much as possible. The humans saywhat they want to achieve; it’s upto Mathematica to figure out which112 / FEBRUARY <strong>2012</strong> / WWW.LINUXJOURNAL.COM


INDEPTHalgorithm to use, or whatever, to achievethat. We’ve also worked very hard tokeep the design of Mathematica ascoherent and consistent as possible.And, the result of all this is that in asense we get to build Mathematicawith bigger and bigger bricks. Eachnew piece of functionality finds it easyto use larger and larger chunks ofexisting functionality.We’ve done a lot of work on bothsystem design and software engineeringduring the years, and it’s increasinglybeen paying off. So if you look, forexample, at a plot of the number offunctions supported by Mathematicaversus time, it has a pretty impressive,perhaps exponentially looking form inrecent years.JG: To what extent did Mathematicainspire and inform Wolfram|Alpha?SW: Well, of course, at a practicallevel, Wolfram|Alpha is implementedin the Mathematica language. It’s allMathematica. And if we hadn’t hadMathematica, Wolfram|Alpha neverwould have been possible.We use Mathematica for all its builtinalgorithms, but more important, weuse it as an incredibly powerful languagefor representing knowledge and definingnew algorithms. We also use it as alarge-scale deployment environment—actually delivering the computations andresults from Wolfram|Alpha on the Weband elsewhere. And, needless to say, allour software engineering and testingand monitoring systems are written inMathematica too.In a sense, Mathematica andWolfram|Alpha are conceptual opposites.Mathematica is based on a very cleanand precise language that can beused to build very large structures.Wolfram|Alpha has to handle all themessiness of the world, and of humanlanguage, and initially is used mainly forone-shot queries.For me, it was very interesting to thinkabout Wolfram|Alpha after so many yearsof working on Mathematica. I could, in asense, do everything exactly the oppositeway. But, now it’s really exciting to seehow these different approaches can bebrought together, so in the latest versionof Mathematica, we use Wolfram|Alphatechnology to let people enter free-formnatural language inputs and get preciseMathematica code out.It’s pretty interesting. It’s a new wayto do programming—just by usingnatural language. And, I am frankly quitesurprised at how well it already works,and how useful even I, as an expertMathematica programmer, find it.JG: Unlike many software developers,you’ve had your application Mathematicaavailable on the <strong>Linux</strong> platform for years.When did the first <strong>Linux</strong> version arrive,and what motivated Wolfram Research tobe such an early <strong>Linux</strong> supporter?SW: I just looked at my e-mail archive,and I see that the first internal discussionabout <strong>Linux</strong> at our company happenedWWW.LINUXJOURNAL.COM / FEBRUARY <strong>2012</strong> / 113


INDEPTHin 1993, and we started the actual portof Mathematica to <strong>Linux</strong> in late 1994. I’dhave to read through lots of messages inmy e-mail archive to remember exactlyhow the discussion about <strong>Linux</strong> went.But in general, it’s been our principleever since the beginning that we wantMathematica to be available on as manyplatforms as possible.It’s good we have a well-developed<strong>Linux</strong> version of Mathematica, becausenowadays all our Wolfram|Alpha serversare running <strong>Linux</strong>!JG: Could Wolfram|Alpha orMathematica benefit from a model similarto open-source software—that is, witha distributed group of contributors tocomplement your core development teams?SW: In Mathematica, we use lots andlots of open-source software these days.In fact, all the acknowledgements for itare getting to be the length of a smallbook. It’s wonderful when we can use astrong piece of open-source software foran algorithm or a component. It lets usput more effort into the unique parts ofthe Mathematica system, like algorithmautomation and its overall design.In Wolfram|Alpha, we have anincreasingly large volunteer program,with people around the world helping uswith particular data curation tasks thatthey’re interested in. We’re also thinkingabout how to develop open projects andcollaborations to work on very large-scaledata projects that we think would begood for the world, but which we can’tafford to do ourselves.JG: You and [the late] Steve Jobs wentway back. How did that relationshipcome about?SW: Steve Jobs was working in stealthmode on the NeXT computer. It must havebeen 1987. We met through a chain ofacquaintances and ended up making a dealto have Mathematica bundled on everyNeXT machine sold. It was actually the firstmajor deal we made for Mathematica. AndSteve Jobs was also the person who pushedme to use the name “Mathematica” insteadof various alternatives.JG: You were the youngest personever to win the MacArthur “Genius”Grant/Award. What did you win it for?SW: I got that award in 1981. WhenRod MacArthur (son of the late JohnMacArthur) called me to tell me about it,I actually asked what it was for, and hesaid they didn’t ever specifically say that.So I guess I don’t specifically know.I can say that in 1981, I was 21 yearsold, and I had mainly worked on twothings. First, starting when I was 14,I had published all sorts of papers intheoretical physics—mainly about particlephysics and about cosmology. I’d alsobecome very involved in using computersto automate the calculations I neededto do. And starting in 1979, I’d beendeveloping a symbolic manipulationsoftware system that was in some ways aforerunner of Mathematica.JG: From the outside, it appears thatyou are a person who is living the way he114 / FEBRUARY <strong>2012</strong> / WWW.LINUXJOURNAL.COM


INDEPTHwishes without much compromise. Is thatobservation accurate?SW: It’s certainly what I aspire to, andI’ve spent a lot of effort doing my best toget myself into that position.Of course, I’ve made plenty of choices.For example, I could work on things thatare somehow maximally intellectual,but don’t have practical significanceand don’t make money. Or I could try tomake the maximum amount of money,but work on things that are intellectuallyrather dull. I’ve chosen a middle path,which I’m pretty happy with. I get to dolots of very fascinating things, but they’reuseful enough that they’ve let me makea very decent amount of money, whichgives me the freedom to go on doinginteresting things.I’ve spent years building up WolframResearch and collecting lots of verybrilliant people there who I enjoy workingwith. I’ve never taken the companypublic or had investors. So I’ve beenable to concentrate on long-term thingsthat I think are really interesting (likeMathematica and Wolfram|Alpha). And Ialso don’t get fired as CEO when I spendyears working on basic science. (Althoughactually that basic science has now turnedout to be crucial to our products too, butthat’s a different story.) My theory is thathaving Wolfram Research is the best wayI can turn ideas that I care about into realthings in the world.I’ve been a remote CEO for morethan 20 years now, working at homemost of the time. I’ve ended upusing technology to make my workas efficient as possible. I figure thatwhatever I can automate and makeroutine, I don’t have to think about. SoI can spend my thinking effort on thestuff that’s really worth thinking about.And that I really enjoy.JG: From a young age, you’ve beenahead of your time, regularly producinginnovations in mathematics, scienceand computing that typically come fromsomeone ten or 20 years older, if ever.What can you tell us about what is goingon internally—your thoughts, impulses,philosophy and so on—that would helpus understand how you’ve managed tobe so ahead of your time all of your life?SW: Thanks for the kind words! Iguess I like to understand things at themost fundamental level possible, andwhen I succeed in doing that, it oftenseems fairly obvious to me what directionthe things should go in. It’s been verycommon in my life that I think aboutdoing something, and then a decade ortwo later it becomes very popular.I think I achieve the most by doinglarge long-term projects (although I findit a lot of fun to do the occasional shortproject), but one doesn’t get to do thatmany large projects in a lifetime. One hasto pick and choose. I like to pick onesthat I think won’t get done as part ofthe general development of things—oneswhere I can feel I’m making a uniquecontribution by doing them.WWW.LINUXJOURNAL.COM / FEBRUARY <strong>2012</strong> / 115


INDEPTHJG: Readers of <strong>Linux</strong> <strong>Journal</strong> tend tobe “outside the box” kind of people.(We think you’d fit right in!) Do youhave any advice for any budding StephenWolframs out there—people who havegreat ideas and want to make importantcontributions to their field, but aren’tsure how to proceed?SW: I think the first thing is to haveconfidence. Figure things out as best youcan for yourself—perhaps asking lots ofpeople for advice too—then stick to whatyou’ve concluded. At any given time,there’s always a conventional wisdomabout how things should be done orwhat’s possible. If you believe somethingdifferent, go with what you believe. Youalways can define success to be whateverit is that you achieve.I happen to find people reallyinteresting (a great asset if you’re tryingto build a company like ours!), and I’veworked with lots and lots of peoplewho’ve done great things. My mainconclusion is that there are an awful lot ofdifferent ways to achieve things. For anygiven person, it’s important to understandyourself as well as you can. Even after allthese years, I gradually understand myselfbetter and better, and every increment inunderstanding seems to help me a lot inmanaging to do the right things.It’s a fascinating problem matchingpeople (including oneself) with the bestpossible directions and niches in theworld. It’s amazing how often people getstuck in the wrong niches—sometimesbecause they just didn’t know orunderstand other niches that would bemuch better for them, and sometimesbecause they think they have too muchinvestment in one niche and can’t seehow to bridge to another. My observation(for myself and others) is that withsufficient creativity, one always can comeup with a strategy to get from hereto there, and the result is much moresatisfaction, fun and productivity.JG: Do you have more big initiativesup your sleeve, or are you contentright now to focus on Mathematicaand Wolfram|Alpha?SW: I’ve done three large projects sofar in my life: Mathematica, A New Kind ofScience (NKS) and Wolfram|Alpha. They’reall never-ending projects, and I hope to goon pursuing all of them forever, but I alsohope to do some more big projects.I have quite a long list of projectsI’d like to do, mostly very large andambitious. The big challenge is to pickthe right time to do them. I’d beenthinking about the general idea ofWolfram|Alpha for several decades,but always had decided it was tooearly to try actually doing it. One hasto wait until the ambient technologyis to the right point. Some of theprojects I’m considering may be close;some may be 50 years away.One project I’m committed to doingis to use the work I’ve done in A NewKind of Science to try to find a trulyfundamental theory of physics. I’m116 / FEBRUARY <strong>2012</strong> / WWW.LINUXJOURNAL.COM


EOFDOC SEARLSThe Near-Deathof Blog SearchA once-hot category is now down to just Google. DOC SEARLSBlogging was born in the late1990s, and it got hot after theturn of the millennium. Severalcharacteristics made blogs distinctive.First, they were personal. Second, theyconsisted of posts organized in reversechronological order: the latest stuff ontop, the older stuff scrolling towardthe bottom. Third, each post had itsown URL, called a permalink, whichsurvived with its own archival path afterit scrolled off the current page. Fourth,with the advent of RSS (Really SimpleSyndication), blogs had a journalisticadvantage: notifying the world that apost had just gone up. Thus, blogs weremore current and live than ordinaryWeb sites, and they were designedto accumulate a corpus of work thatrespected the future by organizing andpreserving the past.By contrast, ordinary Web sitestended to be static and have no archivalfunction. This was especially true ofcommercial sites. Last year’s shoes wereas gone as last year’s snow.Google and other search engines ofthe time paid little attention to blogs.They assumed that the Web was morelike real estate than like anything thatwas alive and constantly changing.“Sites” that were “designed”,“constructed” or “built” at “locations”you could “visit” or “browse” matteredmore than “journals” that were“posted”, “updated” and “syndicated”.That left open a hole in the marketplacefor search engines that indexed the liveWeb, leaving the static one to Googleand its direct competitors.The first blog search engine wasPubSub, which showed up sometimein 2002. It was inventive and tooksome getting used to, but it was fastand did a good job of finding currentpostings in the blogosphere.Second was Technorati, which camealong in late 2002, out of research118 / FEBRUARY <strong>2012</strong> / WWW.LINUXJOURNAL.COM


Advertiser IndexThat left open a holein the marketplace forsearch engines thatindexed the live Web,leaving the staticone to Google and itsdirect competitors.David Sifry and I were doing for thearticle “Building with Blogs”, whichran in March 2003 issue of <strong>Linux</strong> <strong>Journal</strong>(http://www.linuxjournal.com/article/6497). The first incarnation ofTechnorati was a MySQL hack that ranon a Debian box in the basement ofDavid’s San Francisco apartment. Whenhe exposed it to the public on the Web,it was an instant success. Not long afterthat, David quit his day job and workedon building Technorati full-time.Third was Bloglines, which camealong in early 2003. Bloglines wasa Web-based RSS news aggregator,rather than a search engine in theusual sense. Still, it served the needfor readers to know what was beingpublished right now on the Web.During the next several years, other fishin the blog-search pond came to includeGoogle Blog Search, BlogPulse, Yahoo,Feedster, IceRocket and Blogdigger.Thank you as always for supporting ouradvertisers by buying their products!ADVERTISER URL PAGE #ConfooContent & Apps forAutomotive Europe <strong>2012</strong>http://confoo.ca107http://www.telematicsupdate.com/contenteu122Emac, Inc. http://www.emacinc.com 89iXsystems http://www.ixsystems.com 7<strong>Linux</strong>Fest Northwest http://linuxfestnorthwest.org 121<strong>Linux</strong> Foundation http://events.linuxfoundation.org 37Lullabot http://store.lullabot.com 2Microway http://www.microway.com 46, 47Northeast <strong>Linux</strong>Fest http://northeastlinuxfest.org 91O'Reilly Where http://whereconf.com/where<strong>2012</strong> 17Posscon http://posscon.org 29RackMountPro http://www.rackmountpro.com 15Silicon Mechanics http://www.siliconmechanics.com 3USENIX FAST http://www.usenix.org/events/fast12/ 81ATTENTION ADVERTISERSThe <strong>Linux</strong> <strong>Journal</strong> brand’s following hasgrown to a monthly readership nearlyone million strong. Encompassing themagazine, Web site, newsletters andmuch more, <strong>Linux</strong> <strong>Journal</strong> offers theideal content environment to help youreach your marketing objectives. Formore information, please visithttp://www.linuxjournal.com/advertising.WWW.LINUXJOURNAL.COM / FEBRUARY <strong>2012</strong> / 119


EOFThis is what Twitter hath wrought, and Facebookas well. They’ve buried real news....After a while fake blogs—a form ofspam Mark Cuban called “splogs”—came to comprise about 99% of theblogs in the world. This was a hugeproblem that even Google had troublekeeping up with. Thanks to the splogissue and other problems, Feedster andBlogdigger died off. Yahoo never wasserious about blog search and quit thegame. IceRocket and BlogPulse bothwere sold and now are mostly buzzsearch engines that don’t rememberanything more than a few months old.Blogdigger’s page still is up but doesn’tdo anything. And Technorati, whichonce maintained a complete index of allsyndicated sources, including all blogsfrom the beginning of the company’sexistence, turned into one of those“content” mills several years back.The only true blog search enginestill operating is Google Blog Search,which basically is a specialized searchin Google’s main engine, which hasbeen modified in recent years to reducetime-to-index to minutes or evenseconds. I hope it keeps going, becauseit’s an essential resource for findingthe kind of news that’s syndicated live,still curates itself, and isn’t just aboutpushing or riding whatever happens tobe buzzing at the moment.For a while after Technorati gaveup, my favorite blog search enginewas IceRocket. Now owned byMeltwater Buzz, it’s about “socialmedia monitoring” that “helps youmine conversations across socialchannels for nuggets of insight”.Note that the second-person “you” isnot you and me, the users. We’re theproducers of ore from which insightnuggets are mined. The “you” they’retalking to is advertisers.This is what Twitter hath wrought,and Facebook as well. They’ve buriedreal news—stuff worth keepingaround—under a mountain of buzz,all of which melts away after minutes,weeks or months.But the durable stuff still matters.<strong>Journal</strong>ism, compromised and corruptedas it has become, still matters—perhapsmore than ever. That means blogs, andjournals like this one, still matter too.But only to the degree that the workstill can be found.■Doc Searls is Senior Editor of <strong>Linux</strong> <strong>Journal</strong>. He is also a fellowwith the Berkman Center for Internet and Society at HarvardUniversity and the Center for Information Technology and Societyat UC Santa Barbara.120 / FEBRUARY <strong>2012</strong> / WWW.LINUXJOURNAL.COM


<strong>Linux</strong>FestNorthwestBellingham, WAApril 28th & 29thHosted Bylinuxfestnorthwest.org


Organised by:the only conference focussed oncontent & apps for automotivecontEnt & appSfor automotIvE EuropE <strong>2012</strong>18th-19th April <strong>2012</strong>, kempinski Hotel, munich, GermanyCloud Hosted Services and In-Car Apps Revolutionisethe Driving Experience to Bridge the UltimateConnected Lifestyle Gap` HyBRIDISED PLAtfoRmS AnD oPERAtInG SyStEmS ACHIEvEIntERoPERABILIty: Utilise embedded, smartphone and cloud hosted services to blendnative and cached cloud data and analyse standardised OSs, required SDKs and APIs to attract3rd party developers to the auto space` oEmS to CAPItALISE on InCREASED ConnECtIvIty oPPoRtUnItIES:Analyse pan-European consumer requirements to integrate relevant content such as HDRadio, parking services and traffic updates whilst benefitting from increased connectivity forenhanced customer relationships` moBILE nEtwoRk oPERAtoRS (mnoS) StEP-UP & REPoSItIon In-LInE wItHoEm DEmAnDS: Outline business models such as data bundling through smartphoneconnectivity, or, in-vehicle SIM and MNOs’ plans to leverage consumer relationships through afully managed app store complete with billing options for tried and tested content download` EnD-to-EnD SERvICE offERInGS REvoLUtIonISED: Discuss where traditionalplayers can update services to retain their position in the telematics value-chain by identifyingsuitable content and leading the development of an ecosystem for tailored applications to fitdifferent UIs (user interface)` REALIStIC In-CAR ContEnt: Analyse the role of social networking to developcommunities to offer driver centric services and driver-to-driver interactions and gamingcontent, especially for rear-seat downloads to maximise your content portfolio` BUILD AUto APP DEvELoPER CommUnItIES: Understand the app developer mindset for the auto environment and methods for increasing volume demand such as globalisedapps, in-house OEM app development frameworks and requirements to qualify for OEM R&DsubsidiesSAVE €100Off current ticket price.Quote discount code1937LJwww.telematicsupdate.com/contenteuExpErt SpEakErSIncludE:250+ Executive Delegates30+ Expert Speakers25+ Business-FocussedSessions20+ Hours of Supreme NetworkingNew Speakers, New Intelligence,New Networking... NEW SHOW!Badge Sponsor:“Excellent networkingopportunities with well balanceddebates and discussions on keyindustry issues.”Scan me forlatest speakeradditions andnew sessionsVisit the website today for the latest updates on top speakers, sessions and the full conference program!www.telematicsupdate.com/contenteu

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!