Programming from A to Z
02 — Regular Expressions

Assignment

Design an exercise around regular expressions.

Over the last decade, I've maintained a fairly consistent habit: taking film photos → paying the steep cost of getting them developed → asking the lab to email me scans of the prints → downloading a .zip file full of surprising and wonderful 35mm scans → promptly forgetting about them, only to lose them in the disorganized digital abyss that is my "Downloads" folder.

After learning more about regular expressions last week, I realized that they might be the key to organizing and resurfacing at least a portion of my film scans. I've also been wanting to get more comfortable using the terminal, so this seemed like the perfect opportunity to see how Node.js could assist in this exercise.

A quick scan of my Downloads folder reminded me that, in addition to .jpg and .jpeg formats, many of my film scans were delivered as .tiff files.

It took me a bit of time to figure out how I could use Node.js to read and search through my files, but I found some helpful answers. After experimenting with the logic for directory scanning and configuring my regular expression, this is what I ended up with …

Regex pattern

const photoRegex = /\.(jpg|jpeg|tiff)$/i;

\. = looking for the period before the file extension (.)

(jpg|jpeg|tiff) = groups alts and uses “|” to indicate “or” = will match with .jpg, .jpeg, .tiff

$ = end of the string / nothing after that

i = case-insenitive flag so it will also match .JPG, .JPEG, and .TIFF


Result

The good news: it worked! I was able to log the full path and file names by running the script. The bad news: there are a lot of files to organize now...

01 — "Constrained" Writing / "Algorithmic" Writing

Assignment

Using a source text of your choosing, manually perform one of the "constrained writing" techniques described above (or one of your own invention!) Document your results online in whatever format you like. There is no need for programming for this assignment, it's just about getting set up in an environment and starting to think about creative ways to play with text. However, you may choose to include animated or interactive elements if you like. Think about creative ways for the page to be "self-documenting", i.e. instructions for the text mashup, references, etc.

I really liked the constrained writing rules that my group came up with in class last week, so I decided to keep working with it and commit it to code. I slightly clarified our language to make it more specific before transforming it into javascript.

Class exercise

Rules

  1. Replace each period and commas in the text with first a “?” and then a “!”, alternating between the two from the beginning to the end of the text.
  2. Now put each newly created sentence on its own line. The first line will begin with a “a:”, followed by the first sentence in the text, and the second line with begin with a “b:” in front of the second sentence of text. Repeat this pattern of alternating between adding “a:” and “b:” to the beginning of each line, until you reach the end of the text.
  3. Find a partner, decide who will read “a:” and who will read “b:” and attempt your best dramatic reading!
Original text

Are you sociable? or more of an introvert? Some days I’m quite introverted, but without social contact and exchange my work wouldn’t exist. You need to go out and talk to the guy around the corner, to the caretaker’s daughter, who tells you wonderful stories.

Processed text

Step 1

Some days I’m quite introverted? But without social contact and and exchange my work wouldn’t exist! You need to go out and talk to the guy around the corner? To the caretaker’s daughter! Who tells you wonderful stories?

Step 2

a: Some days I’m quite introverted?

b: But without social contact and and exchange my work wouldn’t exist!

a: You need to go out and talk to the guy around the corner?

b: To the caretaker’s daughter!

a: Who tells you wonderful stories?

Constrained Dialogue + Code / p5.js (click here)

Original text

With the help of a small rope tied around his ankles, Eugenio Sánchez, lithe at age 50, shimmied himself all the way up a towering tree like a human inchworm, his chest heaving from the exertion, just to pick a few leaves. - New York Times

Constrained

a: With the help of a small rope tied around his ankles?

b: Eugenio Sánchez!

a: lithe at age 50?

b: shimmied himself all the way up a towering tree like a human inchworm!

a: his chest heaving from the exertion?

b: just to pick a few leaves!

I wanted to upload my  to Github page to get into that workflow, but I didn't quite succeed in uploading the files properly, as I'm missing some DOM elements. But why??? TBD ...