Greg.Randall

Title Case

October 29th 2019

A while back I was working on a WordPress website someone had built where all the titles were all caps, and I needed to fix that.

At first this problem looks pretty simple– just run all the titles through the simple PHP function ucwords. ucwords will take a string like “HELLO WORLD” and convert it to “HELLO WORLD”? Ok so, ucwords only uppercases words not lowercases words? So “HELLO WORLD” apply strtolower which makes “hello world”, then apply ucwords to get “Hello World”. Already this is more complicated than I wanted to get into.

So when you start throwing strings with ‘the’, ‘a’, ‘of’, etc. into the mix things get messier. Our solution of strtolower -> ucwords will make a string like “THE QUICK BROWN FOX JUMPED OVER A LAZY DOG” into “The Quick Brown Fox Jumped Over A Lazy Dog”. Clearly we don’t want “a” capitalized. So we find a list of words that shouldn’t be capitalized:

Alright. Great. Let’s make all of those words not capitalized.

$title = "THE QUICK BROWN FOX JUMPED OVER A LAZY DOG";
$title = strtolower($title);
$title = ucwords($title);
$lowercase_words = array('a ', 'aboard ', 'about ', 'above ', 'across ', 'after ', 'against ', 'along ', 'amid ', 'among ', 'an ', 'and ', 'anti ', 'around ', 'as ', 'at ', 'before ', 'behind ', 'below ', 'beneath ', 'beside ', 'besides ', 'between ', 'beyond ', 'but ', 'by ', 'concerning ', 'considering ', 'despite ', 'down ', 'during ', 'except ', 'excepting ', 'excluding ', 'following ', 'for ', 'from ', 'in ', 'inside ', 'into ', 'like ', 'minus ', 'near ', 'of ', 'off ', 'on ', 'onto ', 'opposite ', 'or ', 'outside ', 'over ', 'past ', 'per ', 'plus ', 'regarding ', 'round ', 'save ', 'since ', 'so ', 'than ', 'the ', 'through ', 'to ', 'toward ', 'towards ', 'under ', 'underneath ', 'unlike ', 'until ', 'up ', 'upon ', 'versus ', 'via ', 'with ', 'within ', 'without ', 'yet');

$title = str_ireplace($lowercase_words, $lowercase_words, $title);

echo $title;

That outputs “the Quick Brown Fox Jumped over a Lazy Dog”. Which is also not what we want. We need the first letter of the first word to be capitalized too. We’ll add in ucfirst to capitalize the first letter.

$title = "THE QUICK BROWN FOX JUMPED OVER A LAZY DOG";
$title = strtolower($title);
$title = ucwords($title);
$lowercase_words = array('a ', 'aboard ', 'about ', 'above ', 'across ', 'after ', 'against ', 'along ', 'amid ', 'among ', 'an ', 'and ', 'anti ', 'around ', 'as ', 'at ', 'before ', 'behind ', 'below ', 'beneath ', 'beside ', 'besides ', 'between ', 'beyond ', 'but ', 'by ', 'concerning ', 'considering ', 'despite ', 'down ', 'during ', 'except ', 'excepting ', 'excluding ', 'following ', 'for ', 'from ', 'in ', 'inside ', 'into ', 'like ', 'minus ', 'near ', 'of ', 'off ', 'on ', 'onto ', 'opposite ', 'or ', 'outside ', 'over ', 'past ', 'per ', 'plus ', 'regarding ', 'round ', 'save ', 'since ', 'so ', 'than ', 'the ', 'through ', 'to ', 'toward ', 'towards ', 'under ', 'underneath ', 'unlike ', 'until ', 'up ', 'upon ', 'versus ', 'via ', 'with ', 'within ', 'without ', 'yet');

$title = str_ireplace($lowercase_words, $lowercase_words, $title);

$title = ucfirst($title);

echo $title;

Finally we get our desired output of “The Quick Brown Fox Jumped over a Lazy Dog”.

We aren’t really catching a whole lot of edge cases here though. What if a title has a hyphenated word in it? The second half of the word won’t be capitalized. What if we have acronyms that should be all uppercase? What happens if the title is in a language that doesn’t follow english rules of capitalization? What if someone’s name is “McDonald”?

I fixed a few more of the edge cases and put the code up on GitHub’s Gist. A quick search of GitHub and Gist reveal many title case functions. It’s a hard problem and I don’t know that mine is the best but it worked on all the titles that I have so far thrown at it.


Single Corn Muffin

October 15th 2019

I took the cornmeal and made a single corn muffin. I only had 32g of cornmeal, so I made a spreadsheet to convert a full cornbread recipe to use all 32g.

I’m pretty pleased with the result — good flavor & good color. Hopefully next year we’ll have enough corn to make more than one muffin.


Home Grown Corn

October 14th 2019

Sarah and I tried to grow corn this year in a 3 sisters setup. The squash was completely destroyed by squash borers, and then the beans pulled all the corn over. At least we got a bunch of beans.

As the beans have begun to lose their leaves we found two tiny dent corn cobs.

Dent Corn

I don’t really have a good way to grind corn, but I found one of the measuring cups fit the immersion blender almost exactly.

After a fair number of grindings and siftings I was left with a little cup of cornmeal. I hope to make one beautiful corn muffin.

Cornmeal

Fuji Rensha Cardia

October 8th 2019

I’ve been looking at weird cameras on Ebay for 15+ years and I’m always amazed there are cameras I’ve never seen or heard of.

Fuji Rensha Cardia, camera with 8 lenses

This camera will take 8 photos across two 35mm frames in quick secession. I assume it’s original purpose was for analyzing your running gait or golf swing. There are several settings for photos from left to right or right to left and how much time there is between the photos.

Camera top with japanese settings

It looks like my camera doesn’t work though. The camera looks nearly new, but the Ebay listing said that it was untested and sold as parts only. Which makes me suspicious that they did test it, and it didn’t work. That’s Ebay, but the camera was really cheap in any case.

I checked the battery voltage, and it seemed ok. I took the case off of the camera and nothing looked mechanically broken, shorting the power switch did not make the camera turn on. I’ll have to dig a bit deeper.

I haven’t take the shutter apart yet, but it looks like the whole camera is run off of a single 6 wire stepper motor. It looks like there’s a switch below and to the right of the stepper; I assume that gives the stepper some positional feedback on where the shutters are. I guess if the electronics are blown I could probably build something myself since it really only looks like I’d need a stepper driver, and a couple of switch inputs. I hope though that I can get it working without too much fiddling around.

Fuji Rensha Cardia disassembly / teardown:

  1. Open the back door
  2. Remove three screws from the left side film canister area
  3. Remove two screws from the right side film take up area
  4. Remove one screw on the bottom of the camera to the right
  5. On the top of the camera flip the film rewind handle open, and remove one screw
  6. Gently flex the camera case and slide it off
The only bit that seemed to fall out was a film canister holder piece; set it aside. When you reassemble the camera after putting the case back on you can slide the film canister holder piece through the film rewind handle hole.


Nishika N8000

October 3rd 2019

One of my buddies gave me two Nishika N8000 cameras. These are odd cameras with four plastic lenses that shoot four small portrait images spread across two 35mm frames.

Sample of four photos scanned

Each of the four images is taken from a slightly different position creating a little bit of parallax between the images.

When the images are split apart and aligned you can create GIFs with some fun movement.

The camera has three aperture settings f/8, f/11, and f/19 and one shutter speed — 1/60th. I don’t really trust either of those numbers. At some point I’ll measure the shutter speed to make sure it’s not way off. I might also try and rig up something to see about the aperture, but that’s a lot harder.


Next Page
1/4