Press enter after choosing selection

The AADL Developer's Blog. Technical info about what new features we're working on, releasing, and playing with.

Graphic for events post

Blog Post

Dev Tools: Regex101

by ejk

Analyzing text is an essential function of computing. Searching, copying and replacing text happens frequently and can be a source of frustration trying to get your code to find exactly what you want.

In PHP, if you're looking for whether a specific piece of text is included within a larger piece of text, it's quickest to use the strpos() function, but if you don't know the exact text you're looking for, sometimes the only tool for the job is to use regular expressions. Regular expressions allow you to define a pattern that will return matches without knowing the exact text beforehand. But getting that expression pattern just right can take multiple tries and can be increasingly frustrating to make a change in your code, run it, see if it worked, then go back and change it again.

The best tool I have found for designing regular expression patterns is Regex 101. It allows you to create your Regular Expression outside of your code. Paste an example of the test text you will be searching, and start typing in your expression at the top. Regex101 will update live with an explanation of any special characters in your pattern as well as highlighting the matches in your test string. You can even change "flavors" of your Regex between PCRE (Perl-style), Javascript, and Python.

Don't be a chump and write your Regexes in your code. Use Regex101 to be sure and then cut n' paste into your code.

Regex 101: http://regex101.com/
Regular Expressions: http://www.regular-expressions.info/

Graphic for events post

Blog Post

Developer Tools: JQuery Mobile

by ejk

The JQuery Mobile framework allows you to easily create HTML elements that are optimized for mobile, touch interface devices. It allows you to give a mobile-friendly user experience in a single generic interface, accessible on iOS, Android or any other mobile device that you may want to display to the user. It supports animated transitions and recognizes swipe gestures within your web app. All you need to do is add a line of Javascript to your HTML page to include the library, and then place identifiers on your page elements to apply the framework's features to your page.

Check out demos here: http://demos.jquerymobile.com/1.4.2/
Download the library: http://jquerymobile.com/download/
Learn more about JQuery Mobile: http://jquerymobile.com/

Graphic for events post

Blog Post

Talking to CalDAV from PHP

by ejk

Our internal room reservation system runs as multiple bookable calendar resources on our Zimbra email system. In order to reserve rooms for our website events, I have created a custom drupal module that hooks into the drupal node save process and places the event information on the correct calendar. The full module is not ready for the public (yet), but here's a sample of how we use the caldav-client PHP library from the Davical open source project.

In this PHP example, I will include the library, create an object of the CalDAVClient class, connect to a CalDAV Calendar, and get details about the calendar:

include_once('davical/inc/caldav-client-v2.php'); $cal_url = 'https://mail.example.org/dav/username/Calendar'; $cal_user = 'username'; $cal_pass = 'password'; $cdc = new CalDAVClient($cal_url, $cal_user, $cal_pass); $details = $cdc->GetCalendarDetails(); print_r($details);

If you are able to connect to your calendar correctly, you should see something like this:

CalendarInfo Object ( [url] => /dav/username@example.org/Calendar/ [displayname] => Calendar [getctag] => 1-98765 [calendar-timezone] => BEGIN:VTIMEZONE TZID:America/New_York BEGIN:STANDARD DTSTART:16010101T020000 TZOFFSETTO:-0500 TZOFFSETFROM:-0400 RRULE:FREQ=YEARLY;WKST=MO;INTERVAL=1;BYMONTH=11;BYDAY=1SU TZNAME:EST END:STANDARD BEGIN:DAYLIGHT DTSTART:16010101T020000 TZOFFSETTO:-0400 TZOFFSETFROM:-0500 RRULE:FREQ=YEARLY;WKST=MO;INTERVAL=1;BYMONTH=3;BYDAY=2SU TZNAME:EDT END:DAYLIGHT END:VTIMEZONE )

The CalDAVClient library includes functions to get specific events from the calendar, place new events on the calendar, and additional functions to interact and modify your calendar from your PHP script. It's an excellent foundation for building more specific calendar interactions in your script.

DAViCal source code: http://repo.or.cz/w/davical.git
DAViCal project: http://www.davical.org/
Zimbra email server: http://www.zimbra.com/

Graphic for events post

Blog Post

Tool Evaluations: Code Editors

by ejk

I've recently switched away from a two-computer desktop (Linux workstation with a Mac laptop on the side), to a single Mac laptop with multiple monitors. As part of the transition, I've been looking into the new possibilities for my primary code editor on OS X coming from Ubuntu. I primarily write PHP code, and am frequently working on Drupal modules. Here's a list of some of the apps I've been evaluating:

Komodo Edit (Free)

My longtime favorite, which I've been using as my primary code editor for the last 7 years.

Pros: cross platform, free, autocomplete, code hints, extendable, New Source Tree sidebar module.
Cons: Some display bugs with multiple monitors make the autocomplete and lookup popups appear on the wrong desktop, autocomplete not working

Some of the bugs I'm seeing while using Komodo Edit on my new machine may be configuration errors on my part, but the popups appearing on the wrong monitor are a known issue. I have a feeling I may end up coming back around to Komodo Edit eventually, just because it's so familiar and it does the things I need so well.

Coda ($75 in the App Store)

Coda comes from Panic software, creators of high quality OS X software. Aimed primarily at the Web Development audience, Coda looks great and makes it easy to work on a remote set of files.

Pros: native OS X interface, clear grouping of projects into "sites", custom autocomplete, extendable with plugins
Cons: price, autocomplete is local to current file only

Coda is very easy on the eyes, I just wish it was easier to get site-wide autocomplete with hints. I need to be able to call custom functions from one drupal module to another without having to open the file and copy the function name.

Sublime Text ($70)

Sublime Text is my current goto for code editing, is a strong favorite for OS X developers and has a great feature set.

Pros: Extensive and powerful keyboard shortcuts to get around your code quickly, edit multiple selections simultaneously (e.g. change all instances of a variable name to another name on the fly), large selection of packages for extention
Cons: bit of a steep learning curve for keyboard commands and package installation. Only local autocomplete

I'm still learning how to get around in Sublime Text, but I'm optimistic that I'll be able to get it to do the things that I want it to with a bit of time and experimentation with some of the custom packages. While it does cost $70 to register, there's no set limit on an evaluation copy, so go give it a try.

Komodo Edit: http://komodoide.com/komodo-edit/
Coda: http://panic.com/coda/
Sublime Text: http://www.sublimetext.com

Graphic for events post

Blog Post

Partner Project: UMS Rewind

by ejk

Congratulations to the University Musical Society for the recent launch of their online performance archive, UMS Rewind. We were partners on the project, providing the back end infrastructure for the data entry and editing. The project has grown over the years with many people putting in many hours of hard work. It's great to see it online and accessible to the public.

The archive contains thousands of performances, artists and works from 135 years' worth of concerts, and will be updated every season. Many of the performances link to programs and photographs in our collection of UMS materials.

The site is currently in beta, so let them know what you'd like to see.

UMS Rewind http://umsrewind.org/
UMS http://ums.org/
AADL's UMS materials http://ums.aadl.org/

Graphic for events post

Blog Post

Stuff We Like: littleBits Synth Kit

by ejk

We have a ton of cool music tools here at the library and during some down time last week I was able to play with one of our latest acquisitions for evaluation: The littleBits Synth Kit. littleBits are awesome circuit building pieces, held together with magnets. They've partnered with synthesizer giant Korg to offer a kit that contains authentic synth modules that can be chained together to create custom sounds. Here's a little sample of what I was able to put together:

This particular kit is still under evaluation, but you should explore our ever-growing collection of Music Tools!

AADL Music Tools: tools
littleBits Synth Kit: synth-kit
Korg: Korg

Graphic for events post

Blog Post

Custom Barcode Scanning from your iPhone

by ejk

We have a lot of items on our shelves, and each one of them contains a wealth of related information within our catalog system. But it's a pain to have to physically carry a item from the shelf to a computer to look up that data, which pales in comparison to hundreds of items on a cart or shelf. It'd be great to have a way to look up that information on a mobile device, ideally by entering the item's unique barcode number with a scanner.

First I built a drupal module that displayed the basic information we wanted for each item, and I added the barcode as an argument at the end of the page's URL. As a result, if you knew the item's barcode, you could open a web browser and type in the address + the barcode to automatically go to a page with the information you wanted.

Secondly, I looked for an App in the iTunes App Store which could do actual scanning of the barcode using the iPhone's camera. There are a TON of barcode scanners in the App Store, but the vast majority of them are tailored to scanning UPC codes and redirecting you to online retailers for the corresponding product, or to decode custom QR codes.

After checking about a dozen free Apps with no luck, the App I finally settled on was mobiscan, which cost $3. But it fulfilled the two requirements for this simple project:

  1. Scan a barcode in the codabar format
  2. Redirect to a custom URL with that barcode's value

There are other, similar apps that offer even more custom functionality, or even integration with your own iOS app. But for the quick and simple scan and go functionality, mobiscan worked the best.

mobiscan App: https://itunes.apple.com/us/app/barcode-scanner-for-business/id606982729
codabar: http://en.wikipedia.org/wiki/Codabar
drupal: http://www.drupal.org

Graphic for events post

Blog Post

Printing Labels from Drupal to a Zebra printer

by ejk

Some of our large items have multiple pieces, and to keep track of them we place the same barcode label on each piece. Making multiple item barcodes is a tedious process, so I created a simple function as part of our drupal intranet to create a new item label from the barcode number:

Image removed.

function spew_print_barcode_label($barcode, $printer, $num) { $header = variable_get('spew_barcode_header_text', NULL); $zpl = <<<ZPL ^XA ^FX/* Top text line */^FS ^FO8,55^BY2 ^ADN,18,10 ^FB448,1,0,C,0 ^FD$header^FS ^FX/* Barcode */^FS ^FO40,85^BY2 ^BKN,N,100,N,N,A,B ^FD$barcode^FS ^FX/* Bottom Text Line */^FS ^FO8,198^BY2 ^ADN,18,10 ^FB448,1,0,C,0 ^FD$barcode^FS ^XZ ZPL; for($i = 0; $i < $num; $i++) { try { $fp = pfsockopen($printer, 9100); fputs($fp, $zpl); fclose($fp); } catch (Exception $e) { drupal_set_message('Caught printer connection exception: ' . $e->getMessage(), 'error'); } } }

The function creates a string of ZPL commands, and sends them directly to the printer on port 9100 by opening a socket connection using pfsockopen(). This should save our materials processors a lot of time.

Image removed.

Graphic for events post

Blog Post

Summer Game Prize Fulfillment Workflow

by eby

The AADL Summer Game has an online shop where earned points can be spent on awesome schwag. To try to make it easy for the volunteers and staff to fulfill the orders we took advantage of some of the infrastructure we already had in place for other parts of the site.

As some know our hold notices currently go through a script that sends an email along with printing a custom label to a label printer, that is used for identification on our hold shelves. We reused this process to print a custom pickup/order label every time an order comes through the ubercart game shop by hooking into the payment process. This leaves a spool of order labels that those doing fulfillment can pick up throughout the week and start filling. A spool that has been increasing dramatically in length. This makes it easy for the shop keepers to keep on top of all the orders and properly mark the bags for pickup.

Image removed.

As orders are filled the barcode on the custom label is scanned, which sets the order as fulfilled and adds a notification job to a redis queue. Players have the option of getting SMS notifications (sent through Twilio) or email. Shop keepers can also cancel orders if need be which refunds the points to the player account.

After the items are delivered to the branch destinations on Friday morning, a script goes through the jobs on the redis queue and sends the notifications letting players know their items are ready for pickup.

Image removed.

More background info on our Summer Game is in the works and keep that order spool growing!

Graphic for events post

Blog Post

Under the Hood of the AADL Summer Game

by ejk

The 2011 Summer Game has brought big changes to the way we play here at the library. In addition to the "classic" summer reading game, players can earn points for writing reviews, adding comments and finding game codes at events and locations. Players also earn badges for special accomplishments. We just passed player ID #4000 and we still have weeks to go for even more players to join and earn points and prizes. The pieces that make up the Summer Game are diverse but by adding custom code to the solid foundations provided by these open tools we've been able to concentrate our efforts on adding new content and functionality rather than chasing bugs and putting out fires. Here's some of the tools and technologies that make up the Summer Game:

Drupal: The aadl.org websites run on the Drupal Content Management System. In addition to giving us a framework for writing blogs, creating user accounts and writing comments, it has a extensive API which allows us to leverage those pieces to add our own functionality. A drupal module for Summer Game was created that keeps track of player data, lets players add points through multiple activities, and displays a leaderboard. Players are attached to user accounts, and a simple function which could be placed in any code that runs the site allows us to award points for any website action. The summer game module is available through github: Summer Game module.

Ubercart: The Summer Game shop runs on this Drupal module that provides a simple shop interface for your Drupal site. Again, it has a extensive API which allowed us to use Summer Game points as a custom payment type. We also added a hook into the order process to send data to our custom label printing function, printing labels for the items at the time of order, and creating custom order emails. By leveraging the ubercart module, we were able to create a complete online shop and order fulfillment process in about 3 weeks, start to finish.

FPDF/ FPDI: The core of the Summer Game is still the "classic" summer reading game, where you read books, fill out a score card, bring it to a library location and get a prize. This year we decided to track all our score cards with unique identifier numbers to see where and when people picked them up. We also wanted to allow players to print their score cards on demand as PDF files. The FPDF library allows us to dynamically create each score card PDF with a unique number. We also use the FPDF library to create easily-printable Game Code signs so staff can post a points-accruing Game Code at their events. The FPDI plugin for FPDF allows you to import an existing PDF as a template for your FPDF document.

Redis: Redis provides a persistent data store, similar to a database, but as key-value pairs rather than tables. We used Redis to store the score card identification numbers because it allowed us to do an atomic increment operation. We don't want two people printing score cards at the same time with the same ID number. In a single call we can get the next number in the sequence without worrying about holding other people up or both grabbing the same number. We also use Redis to store our shop email notification data in a processing queue which allows us to delay sending them out. We currently use the Redisent PHP library to talk to our Redis install.

Twilio: Twilio provides an easy API to interact with users via cell phone text messages. By creating a simple drupal module that utilizes the Twilio API we allowed players at an event to easily sign up for the game and start earning points using their cell phones. We also use twilio to send prize pickup reminder text messages when we fill orders from the Summer Game shop.

AADL is happy to share source code. View the rest of our shared code on our github page. Code monkeys not included. Your mileage may vary.