Skip to content

Instantly share code, notes, and snippets.

View M1TKO's full-sized avatar
🐧
Chilin

Dimitar Kalenderov M1TKO

🐧
Chilin
View GitHub Profile
@M1TKO
M1TKO / jsHelperFunctions.js
Last active May 20, 2020 08:38
Range number to range, find min, max and average number of arrays helper functions
var mapNumberToRange = function (num, in_min, in_max, out_min, out_max) {
return (((num - in_min) * (out_max - out_min)) / (in_max - in_min) + out_min) || out_min;
}
var maxNum = function (arr) {
return Math.max.apply(null, arr);
}
var minNum = function (arr) {
return Math.min.apply(null, arr);
}
var sumArray = function (arr, key) {
@M1TKO
M1TKO / gist:d35c75c40313ed79e089e69a4b7ad8db
Created August 6, 2019 07:08
jQuery sortable fix scrolling top when on the bottom of a page
$(".layers-container").sortable({
placeholder: "layer-empty",
containment: "parent",
tolerance: "pointer",
cursor: "grabbing",
})
.disableSelection();
var instance = $(".layers-container").data("ui-sortable");
instance.__createHelper = instance._createHelper;
@M1TKO
M1TKO / calculateBase64Size.js
Created September 11, 2019 08:10
Calculate base64 string size in bytes
var calculateBase64Size = function (base64, mimeType){
var b64Length = base64.length;
var base64Padding = 0;
if (base64.substring(b64Length - 1) === '=') base64Padding = 1;
else if (base64.substring(b64Length - 2) === '==') base64Padding = 2;
b64Length = base64.length - ('data:' + mimeType + ';base64,').length;
return (b64Length / 4) * 3 - base64Padding;
};
@M1TKO
M1TKO / cloudSettings
Last active April 28, 2020 07:31
Visual Studio Code Settings Sync Gist
{"lastUpload":"2020-04-28T07:31:29.315Z","extensionVersion":"v3.4.3"}
@M1TKO
M1TKO / cloudSettings
Created April 28, 2020 07:22
Visual Studio Code Settings Sync Gist
{"lastUpload":"2020-04-28T07:21:57.595Z","extensionVersion":"v3.4.3"}
@M1TKO
M1TKO / dataUrlToFIle.js
Created May 12, 2021 12:38
Base64 (data url) to File functions
function dataUrlToFileSync(dataUrl, fileName) {
var mimeType = dataUrl.substring(
dataUrl.indexOf(":") + 1,
dataUrl.indexOf(";")
);
var arr = dataUrl.split(",");
var b64str = atob(arr[1]);
var n = b64str.length;
var u8arr = new Uint8Array(n);
while (n--) {
@M1TKO
M1TKO / error_logger.php
Created June 11, 2021 15:05
Simple logger for PHP
<?php
# Put this function in the main directory of your project
# Logs the messages in the php error log file
function log_write($logMsg, $printR = false, $useNewLines = true) {
$debug = debug_backtrace();
$file = str_replace(dirname(__FILE__), '', $debug[0]['file'] ?? '');
$line = $debug[0]['line'] ?? 'NULL';
$addition = '';