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 geodistance(lat1,lon1,lat2,lon2){
const R = 6371e3; // in metres
const φ1 = lat1 * Math.PI/180; // φ, λ in radians
const φ2 = lat2 * Math.PI/180;
const Δφ = (lat2-lat1) * Math.PI/180;
const Δλ = (lon2-lon1) * Math.PI/180;
const a = Math.sin(Δφ/2) * Math.sin(Δφ/2) +
Math.cos(φ1) * Math.cos(φ2) *
Math.sin(Δλ/2) * Math.sin(Δλ/2);
function detab(str) {
return str.replaceAll(/^\s*|\s*$|(?<=(?:\n(\s*).*?)+)\1/g, "");
}
// Test
let query = `
SELECT
'table'.*
FROM
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