Skip to content

Instantly share code, notes, and snippets.

View subzey's full-sized avatar

Anton Khlynovskiy subzey

View GitHub Profile
@subzey
subzey / index.html
Last active December 10, 2020 17:50
Svg use & canvas path2d
<html>
<head>
<style>
svg, canvas { outline: black 1px dotted }
</style>
</head>
<body>
<h2>SVG &lt;use&gt;</h2>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" height="100" width="120"><use xlink:href="tv-heart.svg#heart"/></svg>
<h2>Canvas Path2D</h2>
@subzey
subzey / cli.js
Last active October 28, 2020 17:15
cache-control
#!/usr/bin/env node
import { createServer } from 'http';
import { readFile } from 'fs/promises';
import { resolve } from 'path';
import { parse, fileURLToPath } from 'url';
const ALIGNMENT = 60000; // ms
const TTL = 80000; // ms
#!/usr/bin/env node
const { createServer } = require('http');
function serveStatic(req, res) {
res.writeHead(200, {
'Content-Type': 'text/html;charset=utf-8',
});
res.end(`
<!doctype html>
@subzey
subzey / index.html
Last active June 29, 2020 12:04
new window right away
<!doctype html>
<html>
<head>
<title>New window right away open test</title>
</head>
<body>
<button id="openwnd">Open a new window</button>
<script>
const pageTemplate = '<h1>Loading...</h1>';
<!doctype html>
<html>
<head>
<title>New window open test</title>
</head>
<body>
<button id="openwnd">Open a new window</button>
<script>
function openTab(url) {
const a = document.createElement('a');
@subzey
subzey / readme.md
Created June 4, 2020 09:52
Погода на Марсе

Показать погоду на Марсе. Это не оборот речи, это реально погода на Марсе.

Вот свагер-доки https://maas2.apollorion.com/.

Нужно вывести на консоль браузера температуры за последние 5 солов (марсианских дней). Пример вывода:

Sol #2667: -70..-13 C
Sol #2666: -70..-11 C
Sol #2665: -69..-13 C
@subzey
subzey / pipe.wat
Created March 2, 2020 19:00
Writes to stdout what it gets from stdin
(module
;; Expects a https://wasi.dev/ interface
;; Run this module with https://wasmer.io/ or https://wasmtime.dev/
(func $fd_write (import "wasi_unstable" "fd_write") (param i32 i32 i32 i32) (result i32))
(func $fd_read (import "wasi_unstable" "fd_read") (param i32 i32 i32 i32) (result i32))
(func $proc_exit (import "wasi_unstable" "proc_exit") (param i32))
(memory (export "memory") 1)
(func (export "_start")
@subzey
subzey / test.wat
Last active March 2, 2020 13:52
WASI iovec
(module
(func $fd_write (import "wasi_unstable" "fd_write") (param i32 i32 i32 i32) (result i32))
(func $proc_exit (import "wasi_unstable" "proc_exit") (param i32))
(memory (export "memory") 1)
(data (offset (i32.const 65532)) "TEST")
(func (export "_start")
(i32.store (i32.const 0) (i32.const 65532)) ;; iov.iov_base
(i32.store (i32.const 4) (i32.const 4)) ;; iov.iov_len
@subzey
subzey / Debug z-index.js
Created December 25, 2019 13:44
Debug z-index snippet
console.table(
$x('ancestor-or-self::*', $0).reverse().map(el => {
const computedStyle = el.ownerDocument.defaultView.getComputedStyle(el);
return { element: el, 'z-index': computedStyle.zIndex, position: computedStyle.position };
})
);
@subzey
subzey / xorshift.ts
Last active December 11, 2019 13:48
PRNG vs RNG
// Run this file with:
// npx ts-node -T xorshift.ts
const { randomFillSync } = require('crypto');
const enum Hardcode {
IdBytesLength = 4,
GeneratorsInParallel = 32,
TestIterations = 1001,
}