Encoding

Developer
Size
3,245 Kb
Views
18,216

How do I make an encoding?

Experiments with some data transformation algorithms, for my own sake.. What is a encoding? How do you make a encoding? This script and codes were developed by Tom on 16 September 2022, Friday.

Encoding Previews

Encoding - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Encoding</title> <link rel='stylesheet prefetch' href='https://fonts.googleapis.com/css?family=Cousine:400,700'> <link rel="stylesheet" href="css/style.css">
</head>
<body> <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script> <script src="js/index.js"></script>
</body>
</html>

Encoding - Script Codes CSS Codes

* { font-family: 'Courier New';
}
body { padding: 0.75em 1em; font-size: 18px; color: #0af; background: #111;
}
.stdout { color: #0af;
}
.stderr { color: #e33;
}

Encoding - Script Codes JS Codes

/** * the list of tags * for the uPerm codec, these tags must never change order */
var Tags = [ /* 2014-11-27T00:33:00 */ 'tag1', /* 2014-11-27T00:34:00 */ 'tag2', /* 2014-11-27T01:36:00 */ 'tag3'
];
var TagCodec = { /** * reversibly compresses a list of tags; inspired by *nix octal permissions * this algorithm supports: *	- 40 unique tags using 3 digits or less * - 130 unique tags using 4 digits or less * - 450 unique tgs using 5 digits or less *	- 4400 unique tags using 6 digits or less *	- 10k unique tags using 7 digits or less * * * @arg {array} tagList - array of strings, each being a single tag * @returns {string} encoding the tags */ 'uPermEncode': function(tagList) { var bits = 0; for(var i = 0, iMax = Tags.length; i < iMax; i++) { if(tagList.indexOf(Tags[i]) >= 0) {	bits += (i * 2) + 1; } } return bits; }, /** * get the tags that are encoded by a cipher; the reverse of uPermEncode * @arg {string} cipher - a string that encodes a set of tags * @returns {array} of strings, each being a tag recovered from cipher */ 'uPermDecode': function(cipher) { var tags = []; var value = parseInt(cipher); for(var i = Tags.length - 1; i >= 0; i--) { var tVal = (i * 2) + 1; if(value >= tVal) { tags.push(Tags[i]); value -= tVal; } } return tags; }
};
/** * THE TEST FUNCTION HOPPER * every function in this array will be executed in order, and provided with mechanisms for * signaling output * * function myTest($stdout, $stderr, console, undefined) * @arg {jquery} stdout - a DOM node to insert your screen output * @arg {jquery} stderr - a DOM node to insert bad screen output * @arg {console} console - a ref to the actual console (or substitute?) * @arg {undefined} undefined - a guaranteed-to-be-genuine undefined value */
[
/** * demonstrates encoding arbitrary set of tags as a number * inspired by Unix-style octal permissions * thought to be the most dense mechanism that doesn't involve storage external to the filesystem */
function test1($stdout, $stderr, console, undefined){ var objs = [ { name: 'thing1', tags: [] }, // --- { name: 'thing2', tags: ['tag1'] }, // x-- { name: 'thing3', tags: ['tag2'] }, // -x- { name: 'thing4', tags: ['tag3'] }, // --x { name: 'thing5', tags: ['tag1', 'tag2'] }, // xx- { name: 'thing6', tags: ['tag1', 'tag3'] }, // x-x { name: 'thing7', tags: ['tag2', 'tag3'] }, // -xx { name: 'thing8', tags: ['tag1', 'tag2', 'tag3'] } // xxx ]; var names = [' name | E | T', '-------+---+-------'].concat(objs.map(function enc(thing) { var enc = TagCodec.uPermEncode(thing.tags); var dec = TagCodec.uPermDecode(enc); return [ thing.name, enc, dec ].join(' | '); })); $stdout.text(names.join('\n'));
}].forEach(function executeTest(fn) { // execute each test, providing it methods of updating the page and doing other output things var $stdout = $('<pre class="stdout"></pre>'); var $stderr = $('<pre class="stderr"></pre>'); fn($stdout, $stderr); $('body').append($stdout, $stderr);
});
Encoding - Script Codes
Encoding - Script Codes
Home Page Home
Developer Tom
Username tomprogers
Uploaded September 16, 2022
Rating 3
Size 3,245 Kb
Views 18,216
Do you need developer help for Encoding?

Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!

Tom (tomprogers) Script Codes
Create amazing love letters with AI!

Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!