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
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");
<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") => {
@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
@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>
class JSX {
static _indent = 0;
static createElement(type = '', props = null, ...child) {
return {
type,
props,
child
};
}
static render({type, props, child}) {
@tripolskypetr
tripolskypetr / mario.html
Created January 2, 2020 21:28
Mario soundtrack (JavaScript AudioContext API) https://jsfiddle.net/tripolskypetr/cakLrzp2/
<!DOCTYPE html>
<html>
<head>
<title>Mario</title>
</head>
<body>
<button>Play sound</button>
<script>
<!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() {