Skip to content

Instantly share code, notes, and snippets.

View lyquix-owner's full-sized avatar

Lyquix lyquix-owner

View GitHub Profile
@lyquix-owner
lyquix-owner / do-the-harlem-shake.js
Created April 2, 2023 21:54
Do The Harlem Shake
(function () {
function addStyleSheet() {
var e = document.createElement("link");
e.setAttribute("type", "text/css");
e.setAttribute("rel", "stylesheet");
e.setAttribute("href", styleSrc);
e.setAttribute("class", markerClass);
document.body.appendChild(e)
}
@lyquix-owner
lyquix-owner / unitConv.js
Created April 23, 2020 20:15
Javascript function to convert length, weight, area, and volume units with ease
/**
* unitConv - converts length, weight, area and volume units
*
* Usage: unitConv.type(value, unitIn, unitOut)
* type: length | weight | area | volume
* v: numeric value
* unitIn: name of the input unit
* unitOut: name of the output unit
*
* Supported units:
@lyquix-owner
lyquix-owner / utf8_hex.js
Created April 15, 2020 11:43
JavaScript functions to convert UTF-8 string to hexadecimal string, and back. Correctly handle multi-byte. Demo https://jsfiddle.net/lyquix/k2tjbrvq/
function utf8_hex(str) {
return Array.from(str).map(c =>
c.charCodeAt(0) < 128 ? c.charCodeAt(0).toString(16).padStart(2, '0') :
encodeURIComponent(c).replace(/\%/g,'').toLowerCase()
).join('');
}
function hex_utf8(hex) {
return decodeURIComponent('%' + hex.match(/.{1,2}/g).join('%'));
}
@lyquix-owner
lyquix-owner / lorem-ipsump-utf8-multibyte.txt
Created April 15, 2020 11:05
Test text string (lorem ipsum) in multiple languages and containing UTF-8 multi-byte characters (1 byte, 2 bytes, 3 bytes, and 4 bytes)
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Лорем ипсум долор сит амет, пер цлита поссит ех, ат мунере фабулас петентиум сит. Иус цу цибо саперет сцрипсерит, нец виси муциус лабитур ид. Ет хис нонумес нолуиссе дигниссим.
Λορεμ ιπσθμ δολορ σιτ αμετ, μει ιδ νοvθμ φαβελλασ πετεντιθμ vελ νε, ατ νισλ σονετ οπορτερε εθμ. Αλιι δοcτθσ μει ιδ, νο αθτεμ αθδιρε ιντερεσσετ μελ, δοcενδι cομμθνε οπορτεατ τε cθμ.
側経意責家方家閉討店暖育田庁載社転線宇。得君新術治温抗添代話考振投員殴大闘北裁。品間識部案代学凰処済準世一戸刻法分。悼測済諏計飯利安凶断理資沢同岩面文認革。内警格化再薬方久化体教御決数詭芸得筆代。
旅ロ京青利セムレ弱改フヨス波府かばぼ意送でぼ調掲察たス日西重ケアナ住橋ユムミク順待ふかんぼ人奨貯鏡すびそ。
@lyquix-owner
lyquix-owner / simpleEncryptUtil.js
Last active November 15, 2023 18:55
Super simple UTF-8 safe JavaScript xor encryption, decryption function, with password derivated key, and hash functions - Demo: https://jsfiddle.net/lyquix/dyf05wh3/
/**
* Super simple encryption utilities
* Inspired by https://gist.github.com/sukima/5613286
* Properly handles UTF-8 strings
* Use these functions at your own risk: xor encryption provides only acceptable
* security when the key is random and longer than the message
* If looking for more reliable security use: https://tweetnacl.js.org/
*
* Use passwordDerivedKey function in this file to generate a key from a password, or to generate a random key
*/
@lyquix-owner
lyquix-owner / creditCardValidator.js
Last active March 31, 2020 20:15
JavaScript credit card validator - checks length, prefix numbers, and checksum number
function creditCardValidator(cc) {
/**
* Credit card validator
* Based on: https://www.freeformatter.com/credit-card-number-generator-validator.html
* and this: https://en.wikipedia.org/wiki/Payment_card_number
*/
// Remove all non-numeric characters
cc = cc.toString().replace(/\D/g,'');
@lyquix-owner
lyquix-owner / .htaccess
Created November 4, 2019 16:59
Redirect to preferred domain, force SSL, and require HTTP Auth
# Redirect domain and force SSL #
RewriteEngine On
RewriteCond %{HTTP_HOST} !^example.com$ [OR,NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]
<If "%{HTTPS} == 'on'">
# Password Protect Directory #
AuthUserFile /srv/www/example.com/.htpasswd
AuthName "Enter username and password"
#!/bin/bash
# Check if script is being run by root
if [[ $EUID -ne 0 ]]; then
printf "This script must be run as root!\n"
exit 1
fi
DIVIDER="\n***************************************\n\n"
@lyquix-owner
lyquix-owner / optimize.php
Created November 12, 2018 19:53
Recursively scans directory for jpg files and saves optimized versions using the same directory structure
<?php
// JPEG quality level
$quality = 85;
// Recursively scan directory and get jpeg images
$sourceDir = __DIR__ . '/original';
$targetDir = __DIR__ . '/optimized';
function getFiles($dir) {
if(is_dir($dir)) {
@lyquix-owner
lyquix-owner / detectFonts.js
Created April 17, 2018 21:10
JavaScript font that detects if a font is installed by measuring its dimensions, and comparing them to the dimensions of the default monospace, sans-serif, and serif fonts. The idea is that if a font is not installed it will be replaced by one of those. A know limitation of this approach is that it returns a false-negative for the actual monospa…
var baseFonts = ['monospace', 'sans-serif', 'serif'];
var testChars = ['M', 'g', 'l', 'i', 'ff', 'fi'];
var b = document.getElementsByTagName('body')[0];
var s = document.createElement('span');
s.style.position = 'absolute';
s.style.left = '-9999px';
s.style.fontSize = '100px';