Skip to content

Instantly share code, notes, and snippets.

@perenstrom
perenstrom / validLuhn.js
Created November 16, 2021 10:23
Short JS function to test Luhn digits
export const isValidLuhn = (input) => {
if (!/^\d+$/.test(input)) {
return false;
}
const arr = input
.split('')
.reverse()
.map((x) => parseInt(x, 10));
const lastDigit = arr.splice(0, 1)[0];
@perenstrom
perenstrom / three-level-sourceset-image.html
Last active February 25, 2021 10:22
Picture element with three sources for different device widths, with support for retina, and fallback
<!--
Source set to choose differently sized images depending on device
This is a scenario where large screens have a 500px wide image,
medium screens a 350px wide image, and small screens a 250px wide
image. It is then up to the browser to select the correct image
based on pixel density (1000w image for the 500px container if on
a 2x retina display, for example).
https://codepen.io/perenstrom/pen/JjbMvMa
-->
<?php
// Define variables
$dbuser = 'user';
$dbpassword = 'pass';
$dbname = 'dbname';
$hostname = 'host';
$port = 8889;
// Open database connection