Friday, July 1, 2022

quick reminder to self: how to sort array by a field in the map-ish objects in php

Just one of those small things I was surprised I hadn't already noted on my devblog, in PHP, to sort an array of objects / array of maps, based on a field in all the maps, it's the usort command which works in place on the array, and with the second argument being (weirdly) a string version of the function name:


     function sortOnFirstField($a,$b) {

        global $firstkey;

        return strcmp($a[$firstkey],$b[$firstkey]);


The weirdness of using a stringname... definitely oldschool. Javascript is obviously a bit slicker, though I still appreciate how PHP splits the differences with globals that I have to use instead... (YES you can use them, but also YES you have to acknowledge that you are using on in a function)

Oh and while I am at it, replace special characters etc in a string:

function clean($string) {

   $string = str_replace(' ', '-', $string); // Replaces all spaces with hyphens.

   return preg_replace('/[^A-Za-z0-9\-]/', '', $string); // Removes special chars.


Thursday, June 30, 2022

what's new in js

Heh, you know there are two things that tend to clog up my inbox (because I get stressed out and/or feeling like I should get to it later, but then it just sits) -recruiter contacts and Javascript newsletters.

My favorite of the latter are Frontend Focus and Javascript Weekly.

Here's some stuff that came up:

What's new in the 2022 ECMAscript standard...

Object vs Map. The thing is, I'm not sure devs are really willing to give up their syntatic sugar! I think that's why JS + JSON have been so killer, the concise syntax letting you put together arrays an objects with a minimum of fuss...

Defensive CSS seems pretty good and well-presented.

Tuesday, June 28, 2022

making pill tracking sheets in php

Our poor kitty Dean has a touch of small cell lymphoma (on top of his asthma) and his pill schedule has gotten pretty complicated! I decided to make a simple tool that lets me (or anyone) make a printable pill schedule grid, ala:

(You can see Dean's full grid here)

Like my recent quickpoll program, I decided to both keep it as pure PHP as well as relying a rather too geeky by half text-based format for the pill descriptors, each pill name can be followed by an @ sign to say how often (e.g. 2 for every other day, 3 for every third day, etc) and then a + sign and an offset for how many days forward):

everyday pill
every other day pill@2
every week pill@7
every 2 week pill, start in 5 days@14+5

I think I really need to build myself a generic form builder, while this text-block based stuff is cool in a minimalist way (and lets you copy and paste almost all the data in one fell swoop) it's not user friendly...

Anyway, other minor bits of cleverness is setting up the page to submit to itself via GET, so it's always bookmarkable, as well as using CSS media queries so when you print it's just the grid.

Thursday, June 23, 2022

worst java interviewee ever

In 2005 I posted this on my blog, quoted here for posterity:

A friend gave me a photocopy of a worksheet from a programmer job interview, the contents of which I'm transcribing here. Probably the worst interviewee experience I've seen. I've tried to be reasonably fair; arguably I should could be generous and use * in place of ·, since this was handwritten, but given all the absolute conceptual failures and mental disconnects, I'm leaving it as is.

So the interview "challenge" was to write a factorial function. Now, I don't know exactly how well or poorly the problem was described by the interviewer, but given the first line, probably copied from a whiteboard, I'm assuming it was pretty straightforward. Here's what the sheet had on it...most of the strikes are circular scribble-outs:

5! = 1·2·3·4·5

public string access(string 5! a)



    string b = a.substring(0,1);


    Int int c = b String.getValue(b);

    if(c < 2){


    } else if (c < 3){


    } else if (c < 4){



For someone aspiring to a Java development position, and who must've sounded at least possibly decent on the phonescreen...supposedly the person has multiple masters degrees in science-y and computer-science-y fields, both from good local Universities.

For the non-techies on my blog I summarized the issues like this:

1. Returning a string? Already something seems a bit amiss.

2. Why name a function like this "access"?

3. Passing "5!" as a a variable name, even though struck out, is a telling mixup of variable name and content.

4. More string oddness. These two lines seem to indicate he's just trying to parse the first character of the String passed in to an int, ignoring the rest.

5. To the right of "c -", there's NOTHING about Integers...I'm willing to give him a pass in terms of specific function name (Integer.valueOf(String) would have "worked" as a replacement for String.getValue(String)) but he's not even in the ballpark.

6. The use of "if"s here, 3 conditional cases, is just an astounding example of misthink. Logically, only Strings starting with 0-3 will produce any output, and even then if it's a "one digit string" of the values 1-3 could this logic conceivably "work".

7. Finally, the use of "System.err" rather than "System.out" is just... well, wrong. Or maybe so right, a subtle bit of self-commenting on the error-ridden code...

An even half-way decent programmer when given this problem would likely think for a moment and then say "do you care if it's solved recursively or iteratively"? (With the latter being the better bet, performance wise, but that's a small issue). Also, this is kind of an "academic" problem, and the guy seemed to have a strong academic background...besides talking a *great* game about all the latest technologies, and getting some complex stuff about J2EE right. It's just really odd.

Wednesday, June 22, 2022

neumorphism we hardly knew ya

The rise and fall of neumorphism Hm. Never really got into it. I sorta like the way it looked, tho… but understand a11y issues are there. Also, I gotta think, plain old flat design is just easy to make :smile:

Thursday, June 16, 2022

ie, prounced "AIIIIIEEEEE!"

A not too fond farewell to IE, most unlikely member of the "27 Club".

It did have a good feel relative to Netscape when it first came out.