This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
window.addEventListener('DOMContentLoaded', async () => { | |
const fonts = ['Action Man', 'Heaven', 'Weltron Urban'] | |
// First method (if you don't need to know when all fonts are finished loading) | |
fonts.forEach(font => { | |
new FontFace(font, `url(fonts/${encodeURIComponent(font)}.woff)`).load().then(font => { document.fonts.add(font) }) | |
}) | |
// Second method (if you do need to know when all fonts are finished loading) | |
const promises = [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Select single element | |
const $ = (e, parent = document) => parent.querySelector(e); | |
// Select multiple elements | |
const $$ = (e, parent = document) => Array.from(parent.querySelectorAll(e)); | |
// Create element | |
const cE = (tagName, props) => { | |
const el = document.createElement(tagName); | |
for (let prop of ['id','name','value','className','type','href','method','action']) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const commands = { | |
'ctrl+z' => History.undo, | |
'ctrl+y' => History.redo, | |
'escape': () => { alert('esc'); } | |
}; | |
$(window).on('keydown', event => { | |
let label = ''; | |
if (event.ctrlKey) { label += 'ctrl+'; } | |
if (event.altKey) { label += 'alt+'; } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Point2PointDistance = (lat1, lon1, lat2, lon2) => { | |
const toRad = num => num * Math.PI / 180; // Converts numeric degrees to radians | |
const R = 6371000, // earth radius, in m | |
dLat = toRad(lat2 - lat1), | |
dLon = toRad(lon2 - lon1); | |
lat1 = toRad(lat1); | |
lat2 = toRad(lat2); | |
const a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Calculate bearing (in degrees, 0-360) between two lat/lng points. | |
*/ | |
const Point2PointBearing = (lat1, lng1, lat2, lng2) => { | |
const toRad = num => num * Math.PI / 180; | |
const toDeg = num => num * 180 / Math.PI; | |
lat1 = toRad(lat1); | |
lng1 = toRad(lng1); | |
lat2 = toRad(lat2); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Base62 { | |
private $chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; | |
public function base62Encode(int $num): string { | |
$res = ''; | |
do { | |
$res = $this->chars[$num % 62] . $res; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* One liner to convert a base64 string to a binary Uint8Array | |
* | |
* Example: | |
* const dataURL = 'data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2w....'; | |
* console.log(convertDataURIToBinary(dataURL)); | |
*/ | |
const convertDataURIToBinary = dataURI => | |
Uint8Array.from(window.atob(dataURI.replace(/^data[^,]+,/,'')), v => v.charCodeAt(0)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const ColorSteps = (() => { | |
/** | |
* Convert any color string to an [r,g,b,a] array. | |
* @author Arjan Haverkamp (arjan-at-avoid-dot-org) | |
* @param {string} color Any color. F.e.: 'red', '#f0f', '#ff00ff', 'rgb(x,y,x)', 'rgba(r,g,b,a)', 'hsl(180, 50%, 50%)' | |
* @returns {array} [r,g,b,a] array. Caution: returns [0,0,0,0] for invalid color. | |
* @see https://gist.github.com/av01d/8f068dd43447b475dec4aad0a6107288 | |
*/ | |
const colorValues = color => { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Convert any color string to an [r,g,b,a] array. | |
* @author Arjan Haverkamp (arjan-at-avoid-dot-org) | |
* @param {string} color Any color. F.e.: 'red', '#f0f', '#ff00ff', 'rgb(x,y,x)', 'rgba(r,g,b,a)', 'hsl(180, 50%, 50%)' | |
* @returns {array} [r,g,b,a] array. Caution: returns [0,0,0,0] for invalid color. | |
*/ | |
const colorValues = color => { | |
const div = document.createElement('div'); | |
div.style.backgroundColor = color; | |
document.body.appendChild(div); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
#-------------------------------------------------------------------- | |
# This script retrieves a list (in XML format) of connected clients | |
# on a Compal CH7465LG modem/router. | |
# This modem is provided by various ISPs, a.o: | |
# - UPC Connect Box (CH) | |
# - Irish Virgin Media Super Hub 3.0 (IE) | |
# - Ziggo Connectbox (NL) | |
# - Unitymedia Connect Box (DE) |
NewerOlder