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
@zazaulola
zazaulola / nano-queue.js
Last active October 11, 2021 22:50
Queue, thread, stack, task, job, flow, stream
const Queue = () => {
let idle = true;
const stack = [],
fx = (...job) => {
stack.push(...job);
if(idle)
(async () => {
idle = false;
while(stack.length)
await stack.shift()();
@zazaulola
zazaulola / calendar.js
Last active September 11, 2024 10:09
Nano-calendar on javascript without elements rendering (data only)
// Calendar for month `m` of the year `y` with Sunday as first day of week
const calS = (y,m) => {
let[r,d,w,l]=[[],1,0,!(y%4)-!(y%1e2)+!(y%4e2)],
c=((0|23*m/9)+(m<3?y--:y-2)+5+(0|y/4)-(0|y/1e2)+(0|y/4e2))%7;
for(;d<29+(0x3bbeecc+16*l>>m*2&3);++d,c=++c%7,w+=!c)
(r[w]||(r[w]=[,,,,,,,]))[c]=d;
return r
}
// Calendar for month `m` of the year `y` with Monday as first day of week
function getSelector(el){
let nodes = [],c,e,d=el.ownerDocument,h=d.documentElement;
do{if (el.id){ nodes.push(`#${el.id}`); break;
}else{ if (el==h) c=0; else for (c=1,e=el;e=e.previousElementSibling;c++);
nodes.push(c?`:nth-child(${c})`:el.tagName.toLowerCase());
} } while ((el=el.parentNode)&&el!=d); return nodes.reverse().join` > `;
}
@zazaulola
zazaulola / point-in-polygon.js
Created October 18, 2021 07:07
check the coordinates of a point in that it is inside a polygon
function inside(point, vs) {
// ray-casting algorithm based on
// https://wrf.ecse.rpi.edu/Research/Short_Notes/pnpoly.html/pnpoly.html
// https://stackoverflow.com/questions/22521982/check-if-point-is-inside-a-polygon/29915728#29915728
// https://github.com/substack/point-in-polygon
var x = point[0], y = point[1];
var inside = false;
for (var i = 0, j = vs.length - 1; i < vs.length; j = i++) {
@zazaulola
zazaulola / stackoverflow-date-outdate-marker.user.js
Created October 20, 2021 03:49
Stackoverflow date outdate marker
// ==UserScript==
// @name Stackoverflow dates
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Stackoverflow dates outdate marker
// @author You
// @include /^https:\/\/(.+\.)?stackoverflow\.com/
// @icon https://www.google.com/s2/favicons?domain=stackoverflow.com
// @grant none
// ==/UserScript==
@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);
@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 / 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 / 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 / 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>