HTML, perl

Generating a School Yearbook or Staff Directory Web Page

We were recently contracted to build a simple yearbook web page for an educational institution. The website was to be in the usual yearbook format of a grid of photos, with the name of the student above the photo, and some brief details of the student below each photo.

The yearbook needed to be responsive so it would work on phones, tablets, and desktops, so we chose Twitter Bootstrap as it was the responsive framework we have the most expertise with, and our clients have been most happy with the results of Twitter Bootstrap over the years.

Because there were so many students it would be impractical and tedious to hand build a web page with hundreds of photos, and the educational institution had already collected all headshot photos and text files containing the details of each student. So we decided to build a small perl script that would generate the yearbook web page from the files the institution had collected.

Each student had a directory on a shared drive, and the each student’s folder contained a headshot photo and a text file containing the details. The perl script read each directory in turn, resized the photo into a web friendly size, copied the photo into the output directory, and pushed the student’s info into a data structure, which a Template::Toolkit template then turned into a HTML page formatted with Bootstrap.

Advertisements
c#, Uncategorized

Ordering in LINQ by alphabetical order except for 1 item!

I wanted to alphabetically order a list of objects containing prices and names for a DropDownList, except I wanted the “No Cost” option (which was in the list with a zero price) to be at the top of the list.

What I needed to do was sort a list first by whether the item’s name was “No Cost”, and then by alphabetical order, so after a bit of Googling I discovered this technique of first ordering by whether the name was “No Cost” or not, and then by alphabetical order:

var items = GetProducts().
    OrderBy(x => x.Name != "No Cost").
    ThenBy(x => x.Name);

ddl.DataSource = items;
ddl.DataBind()