Skip to content

Instantly share code, notes, and snippets.

View zazaulola's full-sized avatar
🏠
Working from home

zazaulola

🏠
Working from home
View GitHub Profile
function koi8rToUtf8 ( buf ) {
if( buf instanceof ArrayBuffer ) {
buf = new Uint8Array ( buf );
}
if( ! Array.isArray ( buf ) ) {
buf = [ ... buf ];
}
const map = new Map ( [
[0x80,0x2500], [0x81,0x2502], [0x82,0x250C], [0x83,0x2510],
[0x84,0x2514], [0x85,0x2518], [0x86,0x251C], [0x87,0x2524],
function cp1251ToUtf8(buf){
if(buf instanceof ArrayBuffer) buf = new Uint8Array(buf);
if(!Array.isArray(buf)) buf = [...buf];
const map = new Map([
[128,1026], [129,1027], [130,8218], [131,1107],
[132,8222], [133,8230], [134,8224], [135,8225],
[136,8364], [137,8240], [138,1033], [139,8249],
[140,1034], [141,1036], [142,1035], [143,1039],
[144,1106], [145,8216], [146,8217], [147,8220],
@zazaulola
zazaulola / crypto-captcha.js
Last active August 4, 2022 14:56
PoW captcha for Node. All code is static - no sessions needed, no cookies needed, no database needed.
/** @format */
/**
*
* The principle of the algorithm is very simple.
*
* The module exports three functions:
*
* getTask()
* The first function does not need any arguments.
function createWorker(callable) {
const code = `onmessage=${callable.toString()}`;
const blob = new Blob([code], { type: 'text/javascript' });
const url = URL.createObjectURL(blob);
const worker = new Worker(url);
URL.revokeObjectURL(url);
return worker;
}
/** @format */
/**
* Функция отчищает JPEG-картинку от метаданных
*
* @param {ArrayBuffer} buf буфер с изображением
* @returns {Blob|null}
*/
function clearJpegMetadata(buf) {
if (!(buf instanceof ArrayBuffer)) {
@zazaulola
zazaulola / glitch.html
Created December 3, 2021 17:47
Glitch effect with CSS
<!-- @format -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>CodePen - CSS Glitched Text</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css" />
<style>
@zazaulola
zazaulola / base64.js
Last active April 26, 2022 07:45
base64 and TypedArray conversion
function arrayToBase64(array) {
let base64 = '';
const encodings = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
const arrayLength = array.byteLength;
const remainder = arrayLength % 3;
const mainLength = arrayLength - remainder;
let a, b, c, d;
let chunk;
@zazaulola
zazaulola / ajax.js
Last active December 3, 2021 17:50
Ajax via XMLHTTPRequest
/** @format */
/**
* @interface
* @name RequestParams
* @property {string} url адрес отправки
* @property {string} method метод
* @property {string} responseType
* @property {array} data
* @property {object} headers
* @property {function} uploadProgress
@zazaulola
zazaulola / cyber-font.svg
Last active April 7, 2022 02:10
cyber font alphabet symbols
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@zazaulola
zazaulola / send.js
Created October 20, 2021 03:53
Send Xhr-request
function send(method, url, headers = {}, data = null) {
return new Promise((resolve, reject) => {
console.log(data);
const xhr = new XMLHttpRequest();
xhr.onload = () => resolve(xhr);
xhr.onerror = error => reject(error);
xhr.open(method, url, true);
console.log(xhr);
Object.entries(headers).forEach(([header, value]) => xhr.setRequestHeader(header, value));
xhr.send(data);