Skip to content

Instantly share code, notes, and snippets.

View m3g4p0p's full-sized avatar
💭
waits until idle

m3g4p0p

💭
waits until idle
View GitHub Profile
@m3g4p0p
m3g4p0p / validate_email.js
Created April 26, 2020 19:30
Test if a string is a valid email address using the constraint validation API
/**
* Test if a string is a valid email address
* using the constraint validation API, rather
* than unwieldy regular expressions
*
* @param {string} value
* @returns {boolean}
*/
const validateEmail = value => Object.assign(
document.createElement('input'),
@m3g4p0p
m3g4p0p / loading_lazy_polyfill.js
Created April 25, 2020 11:57
polyfill for the loading="lazy" image attribute
/**
* Simple polyfill for the loading="lazy" image attribute
* based on gandalf458's idea @ https://tinyurl.com/ya2wlg93
*/
document.addEventListener('DOMContentLoaded', function () {
if ('loading' in HTMLImageElement.prototype) {
return
}
var images = Array.prototype.map.call(
@m3g4p0p
m3g4p0p / deprecations.md
Last active January 19, 2020 12:54
Best Of PHP Deprecations

Best Of PHP Deprecations

4 real

  • mbstring.func_overload

    This implies that code using mbstring.func_overload is incompatible with practically all other code, which is written under the assumption that basic string operations work normally.

  • each()

# Hello. This is a commant, and as such
# getting ignored by the interpreter
# Types I -- Primitives
1 # This is an integer (int)
1.1 # This is a float (float)
"blah" # This is a string (str )
True # This is a boolean (bool)
None # This is not anything (NoneType)
{
"name": "transduce",
"version": "0.1.0",
"main": "transduce.js",
"license": "MIT",
"author": {
"name": "m3g4p0p"
}
}
@m3g4p0p
m3g4p0p / validator.js
Created September 27, 2019 21:10
Validate a string according to given HTML validation constraints
export class Validator {
/**
* @param {string|object} constraints
*/
constructor (constraints) {
/**
* @member {HTMLInputElement}
* @private
*/
this.input = Object.assign(
@m3g4p0p
m3g4p0p / lazy-loader.js
Last active July 6, 2019 20:49
A brief introduction to lazy loading with an eye on performance
/**
* This class will encapsulate the lazy loading logic.
*
* We're going to implement it the old-fashioned way using a
* scroll event listener, rather than the new Intersection
* Observer API; however we will take special care of common
* performance issues with this approach.
*
* Feel free to use this piece of code in production. :-)
*
const $ = (selector, context = document) => context.querySelector(selector)
const $$ = (selector, context = document) => context.querySelectorAll(selector)
@m3g4p0p
m3g4p0p / bar.html
Last active December 23, 2019 23:54
Dynamic content test page
<h1>bar</h1>
@m3g4p0p
m3g4p0p / init-standard-project.sh
Created October 12, 2018 20:27
Initialize a project with standard installed
#!/bin/sh
name=$1
if [[ $2 ]]
then
cd $1
name=$2
fi