Lightbox for Bootstrap 4 and jQuery

Lightbox (or “image preview”) functionality for Bootstrap 4 without additional libraries (apart from jQuery).

Written by Joaquim Homrighausen <joho@webbplatsen.se>
30-May-2019
TEAMYUJO

Do as you wish with this 🙂

This is the Javascript/jQuery code for the Bootstrap 4 modal. You don’t have to use jQuery to accomplish this obviously.

$(document).ready(function($) {

  $(".xslightbox").click(function () {
    if ($(this).attr("data-message") != "undefined") {
      document.getElementById("lightbox_target").src = "";
      document.getElementById("lightbox_target").src = $(this).attr("data-message");
    }
    if ($(this).attr("data-title") != "undefined") {
      document.getElementById("lightbox_title").innerText = $(this).attr("data-title");
      }
    $("#xslightmodal").modal("show");
  });
  /* This will focus the close button, but you don't really need to do this or
     have a close button for that matter since Bootstrap will close the modal
     if you click outside the modal or - in this case - press the Esc key */
  $("#xslightmodal").on("shown.bs.modal", function () {
    $("#lightbox_close").trigger("focus");
  });

});

This is the HTML for the Bootstrap 4 modal. You can style it any which way you want. The key to getting the image to behave as you want it (i.e. to make the image responsive) is adding the “img-fluid” class to the img tag.

You can add the “fade” class to the modal if you want it to be “animated”.

<div class="modal" id="xslightmodal" tabindex="-1" role="dialog" aria-hidden="true" data-keyboard="true">
  <div class="modal-dialog modal-dialog-centered" role="document">
    <div class="modal-content bg-light">
      <div class="modal-header">
        <div class="modal-title text-lowercase text-monospace small" id="lightbox_title">
          placeholder
        </div>
      </div>
      <div class="modal-body text-center">
        <img id="lightbox_target" class="img-fluid border border-secondary rounded" />
      </div>
      <div class="modal-footer">
        <button type="button" tabindex="-1" id="lightbox_close" class="btn btn-primary btn-sm" data-dismiss="modal">'.
          Close
        </button>
      </div>
    </div>
  </div>
</div>

And then, to use the lightbox, you need:

<a class="xslightbox" title="Preview me"
   data-message="https://url/to/image/or/loader/script"
   data-title="Name of image">Preview</a>

This is also available as a gist on GitHub. Knock yourself out 🙂

Simple password construct validator for PHP

/* 
 * Simple password construct validator for PHP 
 * Joaquim Homrighausen <joho@webbplatsen.se>
 * May 30, 2019 
 * TEAMYUJO 
 * 
 * Do whatever you want with this snippet :) 
 * 
 * This may not necessarily agree with the section
 * "Strength of Memorized Secrets" in the document
 * from NIST:
 *
 * NIST Special Publication 800-63B 
 * Digital Identity Guidelines 
 * Authentication and Lifecycle Management 
 * https://pages.nist.gov/800-63-3/sp800-63b.html 
 */

function password_check_construct ($pstr, $min_length = 8)
{
  //Setup pattern and stuff minimum requested length into it
  if ($min_length < 4) {
    //We need at least four characters to satisfy our regexp
    $min_length = 4;
  }

  $match_rules = '/^(?=.{'.(int)$min_length.',})(?=.*[a-z])(?=.*[0-9])(?=.*[A-Z])(?=.*[[:punct:]]).*$/';

  //Require at least one a-z, one A-z, one 0-9, and one punctuation/special character
  if (preg_match ($match_rules, $pstr) === 1) {
    return (true);
  }
  return (false);
}

This is also available as a gist on GitHub. Knock yourself out 🙂

Locating older version of MySQL 4, MySQL 5, source code, binaries, rpm, etc.

Quite some time ago, we needed to move a customer’s MySQL 4 server from one location to another. In the process, we figured we’d update the server to use some moderately modern version like MySQL 5.0 at least. Also, if we were to have any chance of virtualizing and upgrading the actual server environment to something more modern like Ubuntu 10.04.LTS or 12.04.LTS, or Debian 6.0, we’d have to re-compile the sources regardless. Not taking other incompatibilities into account, that line of thinking ran into Chuck Norris because the Windows DLLs supplied with the application using the database were not compatible with anything but MySQL 4.

The particular version of MySQL 4 running on the customer’s server was self-compiled (by us), so I figured I’d at least locate the “most recent” version of MySQL 4. To my surprise, this turned out to be harder than I could possibly imagine. In a world where “nobody” forgets anything, I could not find a single trace of a source distribution for MySQL 4. Google, Facebook, Microsoft, and Apple probably know the size of shoes I wear, but they don’t know where MySQL 4 sources are located. This struck me as very odd as MySQL 4 was a) very popular, b) open source, and c) should at least reside on half a dozen servers on the Internet, or so I thought.

Like a core dump out of the blue skies, someone Skyped me a link today. The person had ran into a mirror archive and remembered that I was looking for this “eons ago”. I have now mirrored most of that archive into/onto my own cloud store. I’ll go through that in a few days and remove the things I don’t need, but this may very well turn out to he a lifesaver.

I wonder if Sun and/or Oracle decided that keeping old MySQL versions around was a bad idea …

If you, like me, need to find some odd version of MySQL, for whatever reason, here are two links that may be of good use to you:

http://www.mirrorservice.org/sites/ftp.mysql.com/Downloads/
http://mirror.provenscaling.com/mysql/