This file contains 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
fetch(YOUR_JSON_FILE_URL).then(function(responsive) { | |
return responsive.json(); | |
}).then(function(obj) { | |
console.log(obj); | |
}); |
This file contains 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
[data-before]::before { | |
content: attr(data-before); | |
} | |
[data-after]::after { | |
content: attr(data-after); | |
} |
This file contains 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
// 1234 => 1.234 | |
function splitter(t) { | |
if (t = '' + t, | |
t.length > 3) { | |
var e = t.length % 3, | |
n = e > 0 ? t.substring(0, e) : ''; | |
for (i = 0; i < Math.floor(t.length / 3); i++) n += 0 == e && 0 == i ? t.substring(e + 3 * i, e + 3 * i + 3) : '.' + t.substring(e + 3 * i, e + 3 * i + 3); | |
return n; | |
} |
This file contains 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
// load JSON | |
function loadJSON(url, callback) { | |
var xhr = new XMLHttpRequest(); | |
xhr.open('GET', url, true); | |
xhr.onreadystatechange = function () { | |
if (xhr.readyState === 4) { | |
if (xhr.status === 200) { | |
callback(JSON.parse(xhr.responseText)); | |
} else { | |
// callback([{}]); |
This file contains 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
// source: https://chrisbuttery.com/articles/fade-in-fade-out-with-javascript/ | |
// fadeOut (fade.js) | |
function fadeOut(el) { | |
el.style.opacity = 1; | |
(function fade() { | |
var val = parseFloat(el.style.opacity); | |
if (!((val -= .1) < 0)) { | |
el.style.opacity = val; | |
requestAnimationFrame(fade); |
This file contains 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
// For production use i recommend: https://phuoc.ng/collection/1-loc/shuffle-an-array/ | |
// function | |
function mixArray(array) { | |
let newArray = [], | |
maxRandNbr = array.length; | |
for (let i = 0; i = maxRandNbr; i++) { | |
randNbr = Math.round(Math.random() * (maxRandNbr - 1)); |
This file contains 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
// returns a boolean if the element contains that property | |
const hasCssProperty = (elmt, property) => { | |
const elmtPropertyValue = window.getComputedStyle(elmt, null).getPropertyValue(property); | |
return elmtPropertyValue ? true : false; | |
} | |
// live example | |
const elmt = document.querySelector('#video'); | |
if (hasCssProperty(elmt, 'aspect-ratio')) { |
This file contains 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
<IfModule mod_rewrite.c> | |
RewriteEngine On | |
RewriteBase / | |
RewriteRule ^index\.php$ - [L] | |
RewriteCond %{REQUEST_FILENAME} !-f | |
RewriteCond %{REQUEST_FILENAME} !-d | |
RewriteRule . /index.php [L] | |
</IfModule> |
This file contains 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
/* | |
* source: https://rosettacode.org/wiki/Vigen%C3%A8re_cipher#JavaScript | |
*/ | |
// vigenere | |
function vigenere(text, key, decode) { | |
// helper | |
const ordA = a => a.charCodeAt(0) - 65; | |
// main | |
let i = 0, b; |
This file contains 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 | |
$chars = ''; | |
// 65 - 122 (A-Za-z) | |
// 48 - 122 (0-9A-Za-z) | |
for ($i = 48; $i <= 122; $i++) { | |
// skip 58 - 64 and 91 - 96 | |
if ($i >= 58 && $i <= 64 || $i >= 91 && $i <= 96) | |
continue; |
OlderNewer