Skip to content

Instantly share code, notes, and snippets.

View tripolskypetr's full-sized avatar
💻
Frontend dev fueled by a passion for UI/UX and art, design

Petr Tripolsky tripolskypetr

💻
Frontend dev fueled by a passion for UI/UX and art, design
View GitHub Profile
class JSX {
static _indent = 0;
static createElement(type = '', props = null, ...child) {
return {
type,
props,
child
};
}
static render({type, props, child}) {
@tripolskypetr
tripolskypetr / fillRect.html
Last active January 2, 2020 21:37
Fill the rectangle colored with ones and stop at the border of zeros https://jsfiddle.net/tripolskypetr/u8nphfa5/
<!DOCTYPE html>
<html>
<head>
<title>Omg</title>
</head>
<body>
<pre contenteditable>
</pre>
<p>X: <input type="number" value="3"></p>
<p>Y: <input type="number" value="5"></p>
@tripolskypetr
tripolskypetr / orientedTree.js
Last active January 2, 2020 21:41
Functional style oriented graph traversal https://jsfiddle.net/tripolskypetr/132am0bL/
// o <- end
// / \ n
// f g \ /
// \ / m n
// e \ /
// | p |
// h d \ /
// \ | l
// i c /
// \ | k
<body>
<script>
(async function() {
const fetchImage = async (url) => {
const data = await fetch(url);
const buffer = await data.arrayBuffer();
const blob = new Blob([buffer], { type: "image/png"});
return blob;
}
const sendImage = (blob, url = "http://foo.com/submitform.php", name = "image.png") => {
export default class ImageFactory {
static _index = 0;
static _colors = ["red", "orange", "yellow", "green", "skyblue", "blue", "cyan"];
static _increment() {
const self = ImageFactory;
return self._index = (++self._index > self._colors.length - 1) ? 0 : self._index;
}
static createImage(height = 100, width = 100) {
const canvas = document.createElement("canvas");
const context = canvas.getContext("2d");
<!DOCTYPE html>
<html>
<head>
<title>Drag and drop</title>
<style>
.red { background-color: red; }
.green { background-color: green; }
.blue { background-color: blue; }
.root { position: fixed; }
.box {
@tripolskypetr
tripolskypetr / draggable.html
Created January 7, 2020 23:52
Multi-draggable
<!DOCTYPE html>
<html>
<head>
<title>Drag and drop</title>
<style>
.ball {
width: 200px;
height: 200px;
position: absolute;
}
<!DOCTYPE html>
<html>
<head>
<title>Drag and drop</title>
<style>
::-webkit-scrollbar {
width: 0;
height: 0;
background: transparent;
}
@tripolskypetr
tripolskypetr / stateReducerPattern.html
Created January 9, 2020 19:08
The State Reducer Pattern between separated windows (window.open)
<!DOCTYPE html>
<html>
<head>
<title>Frame</title>
</head>
<body>
<button>Send message</button>
<script>
(function() {
@tripolskypetr
tripolskypetr / domChanges.js
Last active February 5, 2020 15:57
JavaScript show DOM changes
(function() {
const visualize = (target) => {
const {x, y, height, width} = target.getBoundingClientRect();
const div = document.createElement('div');
[div.style.position, div.style.opacity, div.style.zIndex] = ['fixed', 0.5, 999];
[div.style.backgroundColor, div.style.border] = ['green', '1px solid black'];
[div.style.height, div.style.width] = [`${height}px`, `${width}px`];
[div.style.left, div.style.top] = [`${x}px`, `${y}px`];
div.style.transition = 'opacity 0.5s';
div.className = 'visualizer';