TIL: you can flip an image horizontally just via CSS:

<img src='/smurf.gif' height="150px" style="transform: scaleX(-1);">

PS: Yes, I'm using a "Smurf" image for an internal tool on a project which ended up with the acronym "SMRF". 🙂

18 days later

NogDog You could substitute an image of Papa Smurf over the Christmas season.

    12 days later

    TIL: looks like strtotime() ignores fractional seconds when converting an ISO 8601 timestamp:

    $ php -r 'var_dump(strtotime("2021-09-21T22:19:51.689+00:00"));'
    int(1632262791)
    $ php -r 'var_dump(strtotime("2021-09-21 15:19:52"));'
    int(1632262792)

      Also learned that floor(), ceil(), and round() return floats for some reason:

      $ php -r 'var_dump(ceil("1.1"));'
      float(2)
      $ php -r 'var_dump(floor("1.1"));'
      float(1)
      $ php -r 'var_dump(round("1.1"));'
      float(1)

      And now that you've made me look at the manual, TIL that you can specify a negative precision for round():

      20:29 $ php  -a
      Interactive shell
      
      php > $foo = round(1234.567, -2);
      php > var_export($foo);
      1200.0
      php >
      

      I've had a rule of thumb which is "don't start by assuming the guy before you was totally incompetent". I've got a more concise name for it now; Chesterton's Fence.

      I admit mine is a little more general and spills over into another rule of thumb of mine: "If you think you have to force it you're probably doing it wrong."

      7 days later

      TIL the interesting attribute of the number 6174: https://youtu.be/d8TRcZklX_Q

      For the fun of it, I came up with this PHP script, which I'm sure could be improved/streamlined. 🙂

      <?php
      // Fun with 6174
      
      if(empty($argv[1])) {
        die("Usage: ".basename(__FILE__)." nnnn\n    where 'nnnn' is a 4-digit number\n");
      }
      if(!preg_match('/^[0-9]{4}$/', $argv[1])) {
        die("Usage: " . basename(__FILE__) . " nnnn\n    where 'nnnn' is a 4-digit number\n");
      }
      $digits = str_split($argv[1]);
      $unique = array_unique($digits);
      if(count($unique) == 1) {
        die("The number cannot use the same value for all 4 digits.\n");
      }
      while(true) { // Danger, Will Robinson!
        sort($digits);
        $asc = implode('', $digits);
        rsort($digits);
        $desc = implode($digits);
        $diff = $desc - $asc;
        $diff = str_pad($diff, 4, '0', STR_PAD_LEFT);
        echo "$desc - $asc = $diff\n";
        if($diff == '6174') {
          die("7641 - 1467 = 6174\n");
        }
        $digits = str_split($diff);
      }
      

      Weedpacket Now try and find a number that gives the longest path to 6174.

      My test came up with a max of 7 iterations, and applied to 2184 numbers. A bunch of those are duplicates of a sort, since 1234 will be the same as 4321 or 1432, etc.

      PS: Further coding determined (assuming no bugs) there are 116 unique sets of 4 digits that have 7 iterations.

      5 days later

      TIL: You can use (at least some?) expressions in an SQL order by clause, e.g.:

      select predicate_type_id
      from some_schmea.predicate_type
      order by mod(predicate_type_id, 2), predicate_type_id
      

      Output:

      4
      6
      8
      10
      12
      14
      16
      1
      7
      9
      11
      13
      15
      17
      
      2 months later

      TIL that not sanitizing inputs can have far-reaching and long-lasting effects.

      Maybe I knew that in 2013, even. #WhyDidntTheApacheGuys

      dalecosp Today I learned logging frameworks really shouldn't be given the power to download and run code from off the Internet.

      a month later

      TIL about the PostgreSQL replace() function. (Nothing earth-shaking, just never ran into a situation before that had me searching for how to do what it does -- always did text replacing within the PHP code, I guess.)

        5 days later

        TIL PostgreSQL exposes the physical position of a row in a table by giving each table a hidden ctid column. No, you can't use this as a substitute for a primary key; anything that causes rows to be rearranged will cause their ctids to change.

        Despite this, they remain stable for long enough if you have one of those tables that don't have a proper primary key and end up with duplicate rows where you want to get rid of the duplicates.

        DELETE FROM tablename
        WHERE ctid NOT IN (
            SELECT MIN(ctid)
            FROM tablename
            GROUP BY tablename.*
        )
        

        So, grouping all identical rows together, and selecting the minimum ctid from reach group. Those are the rows in the table that get kept (one for each group of duplicate rows). Delete all the other rows.

        If you have a primary key in your table (as you generally should) then you don't need this; group by the columns other than the primary key, and use max or min or something to pick a representative primary key value. That's assuming you don't mind any dependent rows in other tables being deleted as well. It's more likely you'd want them to repoint to the definitive copy of the row you're keeping.

          13 days later

          PHP 8 removed the each() function. (I'm in the process of updating a PHP5 app to 8. Got the API test suite to pass, but now I have to look at the things not covered by that test. 🙂 )

          3 months later

          TIL: var_export() returns null for a PHP resource (which led me down a false debug path until I realized this).

          php > $context = stream_context_create($test);
          php > print_r($context);
          Resource id #1
          php > var_dump($context);
          resource(1) of type (stream-context)
          php > var_export($context);
          NULL
          
            2 months later
            6 days later

            TIL: the strftime() function is deprecated in PHP 8.1. In order to avoid deprecation warnings in a legacy application that we recently upgraded to 8.1, I opted to use https://gist.github.com/bohwaz/42fc223031e2b2dd2585aab159a20f30 and then included it into the only class that needs it with:

            <?php
            
            namespace Foo\Bar;
            
            use Foo\this;
            use Foo\That;
            
            // Avoid strftime() deprection warnings
            // This approach avoids having to change anything else in this class
            require_once __DIR__ . '/strftime.php';
            use function \PHP81_BC\strftime;
            
            class TheProblemClass {
              // lots of stuff, including one method that does a whole bunch
              // of things with date/time format strings like you use in strftime()
              // but only ever calls strftime() on one line
            }
            

            This seemed better -- at least regarding time/effort on my part -- than trying to figure out what I would need to change in the several places it used the date/time format string. 🙂

              2 months later

              Today I learned Queen Elizabeth II died

              Rest in peace

                3 months later

                sneakyimp

                I fairly recently got the main product I work on updated to 8.1.x (from 5.something!!!). Hopefully I don't have to worry about major updates for a while? 🙂

                My principal recommendation is to go through the relevant Upgrading pages of the manual; all the ones between the "from" version and the "to" version. Skim-read first, then pay a bit more attention to incompatibilities and see if anything there rings a bell.

                sneakyimp Do you have any tips for folks upgrading from 7.4 to 8?

                Hmm...not really, other than it probably would have been easier for me if the old PHP app I was working on was more modular and leveraged compose and such for external modules. The one good thing was that we had a fairly extensive test suite for the main part of the app (it's API endpoints), so a lot of it was run the tests, research the resulting errors, fix them, search for other places in the code we used the offending function, syntax, whatever, then rinse and repeat. 🙂

                The good news is that as part of it, I simplified how the Docker images were built by using an official PHP/Apache image, so at least for the near term I should be able to update the PHP version by modifying the first line of /Dockerfile and then running the tests and seeing what happens.

                FROM php:8.1.9-apache
                

                🙂

                PS: Looks like php:8.1.13-apache is out there now, so maybe it's time to try that before there are too many changes. 😉

                  Weedpacket My principal recommendation is to go through the relevant Upgrading pages of the manual; all the ones between the "from" version and the "to" version. Skim-read first, then pay a bit more attention to incompatibilities and see if anything there rings a bell.

                  I have certainly been reading those, in particular these backward-incompatible changes. The 0 == "" seems like it might be a problem. It's always helpful to hear from folks who have practical experience.

                  NogDog Hmm...not really, other than it probably would have been easier for me if the old PHP app I was working on was more modular and leveraged compose and such for external modules. The one good thing was that we had a fairly extensive test suite for the main part of the app (it's API endpoints), so a lot of it was run the tests, research the resulting errors, fix them, search for other places in the code we used the offending function, syntax, whatever, then rinse and repeat. 🙂

                  Assuming that the composer packages you use would be updated by their maintainers. 🤷 I see the wisdom of the test suite. Did any 7/8 problems seem to be especially common? I'm imagining I'll be examining a lot of equality comparisons in if and switch statements.

                  NogDog The good news is that as part of it, I simplified how the Docker images were built...

                  Interesting to know you are using Docker. I was using virtualbox for virtual machines some time back and it seemed so cumbersome. I need to hone my virtual machine chops.

                  sneakyimp it seemed so cumbersome

                  I won't claim to be a Docker expert, but my boss is. We actually deploy the Docker containers in production, so in theory our development environment is identical to the deployment environment (minus maybe some hardware differences in RAM and such?). We work on MacOS for development, and I think it used to be a PITA to get Docker working on Windows, but supposedly is much better now in the last year or 2?

                  sneakyimp Did any 7/8 problems seem to be especially common

                  The couple of things that come to mind were a number of functions that either fail or warn if you pass null to an argument, and some places where we extended a built-in class and had to add the return type specifier on overridden functions that have such specifiers now.

                  a month later
                  10 days later

                  TIL that PHP 8.2 has deprecated the dynamic creation of object variables. E.g., this will throw a warning:

                  class Foo {
                      public $foo;
                      public function __construct() {
                          $this->foo = 'Foo';
                          $this->bar = 'Bar'; // $bar was not declared
                      }
                  }
                  
                  $test = new Foo();
                  
                  Deprecated: Creation of dynamic property Foo::$bar is deprecated in...
                  

                  (I was looking into upgrading an old app from 8.1 to 8.2, and ran into this in a bunch of places.)

                    TIL there are new SI order-of-magnitude prefixes:
                    ronna- (R) for 10²⁷
                    quetta- (Q) for 10³⁰
                    ronto- (r) for 10`²⁷
                    quecto- (q) for 10`³⁰

                    10 days later

                    hey, laserlight -- saw your avatar, I remember you! You helped me w/ stuff long time ago. I had a different username back then. probably 2005 or so.

                      14 days later

                      Today I learned the true murderous rage your children can give you.

                        18 days later

                        Today I learned that Vinyl de Paris has shipped the 500 vinyl LPs I ordered of my First World War concept record. 👍

                        I started working on ten years ago, and ordered the vinyl pressing in August. It's been a long time coming.

                        I hope it's ok to link it here? If not, please forgive.

                        9 days later

                        TIL....
                        ...that the United States (via NIST) has finally (from the start of this year) retired the "U.S. Survey Foot" as a unit of length, and will use the "international foot" instead for surveying, the way it already uses the "international foot" for everything else (defined as 0.3048 of a metre).

                        a month later

                        On 27 March I learned not to trust the C-Level types to have goodwill, or any understanding of IT....

                        You'd have thought at my age that was already quite obvious...