Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
{surrogate pair}

[Alt'tiRi] AlttiRi

💭
{surrogate pair}
View GitHub Profile
@AlttiRi
AlttiRi / ByteString.md
Last active Jun 18, 2022
Binary strings, ByteString [JavaScript]
View ByteString.md

Binary strings

JavaScript strings are UTF-16 encoded strings. This means that each code unit requires two bytes of memory and is able to represent 65535 different code points. A subset of these strings is represented by UTF-16 strings containing only ASCII characters (i.e., characters whose code point does not exceed 127). For instance, the string "Hello world!" belongs to the ASCII subset, while the string "ÀÈÌÒÙ" does not. A binary string is a concept similar to the ASCII subset, but instead of limiting the range to 127, it allows code points until 255. Its purpose however is not to represent characters, but binary data. The size of the data so represented is twice as big as it would be in normal binary format, however this will not be visible to the final user, since the length of JavaScript strings is calculated using two bytes as the unit.

Binary st

@AlttiRi
AlttiRi / background.html
Last active Jun 4, 2022
ReadableStream demo extension
View background.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>background.html</title>
<script src="background.js" type="module"></script>
</head>
<body></body>
</html>
View index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<!-- https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP -->
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'">
<link href="./styles.css" rel="stylesheet">
<title>Hello World!</title>
</head>
<body>
@AlttiRi
AlttiRi / 1.js
Last active Feb 15, 2022
NPM YARN NODE executing start time
View 1.js
console.log(1);
@AlttiRi
AlttiRi / bytesToSizeWinLike.md
Last active Mar 21, 2022
How to format file size bytes into the human readable form like it Windows Explorer does.
View bytesToSizeWinLike.md

How to format file size bytes into the human readable form like it Windows Explorer does

...like it Windows Explorer does.

JavaScript code:

/**
 * Formats bytes mostly like Windows does,
 * but in some rare cases the result is different.