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.
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.
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.
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.
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.
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.
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:
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.
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.