Skip to content

Instantly share code, notes, and snippets.

View UniBreakfast's full-sized avatar
💡
reinventing basic stuff in order to understand it better

Mykhailo "Ninin" Velykoselskyi UniBreakfast

💡
reinventing basic stuff in order to understand it better
View GitHub Profile
@UniBreakfast
UniBreakfast / queue.js
Created June 14, 2025 15:12
Queue data structure implementation with closure
Queue = (function makeQueue() {
const map = new Map
function Queue() {
map.set(this, [])
}
Queue.prototype.enqueue = function (item) {
map.get(this).push(item)
}
@UniBreakfast
UniBreakfast / showDays.js
Last active May 9, 2025 13:59
Improvised calendar to run from console on a blank page
showDays()
function showDays() {
const days = []
const date = new Date
const firstDate = new Date
firstDate.setDate(1)
const firstDateWeekday = firstDate.getDay()
@UniBreakfast
UniBreakfast / console-ball.js
Created March 10, 2025 17:20
Jumping ball. Run from the console.
g = 9.8 / 3000
state = {y: 0, speed: 0}
body = document.body
ball = document.createElement('div')
ball.id = 'ball'
ball.style = `
background: orange;
width: 100px;
@UniBreakfast
UniBreakfast / pronouns.js
Last active February 2, 2025 05:00
If you are going to use pronouns while addressing my humble person you should use only those listed below!
[...new Set([
"I",
"you",
"he",
"she",
"it",
"we",
"they",
"thou",
"ye",
@UniBreakfast
UniBreakfast / bst.js
Created December 16, 2024 10:23
Binary Search Tree rough implementation in console
bst = Object.create({
empty() {
this.value = null
this.left = null
this.right = null
},
show() {
let output = `${this.value}`
@UniBreakfast
UniBreakfast / get-content-size.js
Created December 9, 2024 10:41
A function to get the size of a content part of a DOM element. Without borders or padding.
function getContentSize(el) {
const {
paddingTop, paddingRight, paddingBottom, paddingLeft
} = getComputedStyle(el);
const width = el.clientWidth
- parseFloat(paddingLeft) - parseFloat(paddingRight);
const height = el.clientHeight
- parseFloat(paddingTop) - parseFloat(paddingBottom);
return { width, height };
@UniBreakfast
UniBreakfast / fresh-script.html
Created December 9, 2024 10:19
This will always use fresh script, and will never use cached version.
// closed scope (module)
<script type="module">
import('./script.js?salt='+Date.now())
</script>
// open scope (global)
<script>
document.write('<script src="./script.js?salt='+Date.now()+'" defer></script>')
document.currentScript.remove()
</script>
count = 0
maxDepth = 0
maxWidth = 0
listChildren(document.body)
// console.log({count, maxDepth, maxWidth})
function listChildren(el, depth=0) { //console.log(depth)
if (depth > maxDepth) maxDepth = depth
const tagNames = []
@UniBreakfast
UniBreakfast / get-all-closest-css-value.js
Last active October 21, 2024 09:21
Function getAllClosestCSSValue(element, property) allows to see specific CSS property values starting from the given element and up to the root through the closest DOM tree elements. Use it in console, get array, hover elements in it to highlight them in the page.
getAllClosestCSSValue($0, 'overflow')
function getAllClosestCSSValue(el, property) {
return !el ? [] : [
el,
property + ': ' + getComputedStyle(el)[property],
...getAllClosestCSSValue(el.parentElement, property)
]
}
@UniBreakfast
UniBreakfast / group-by-12-per-page.js
Created September 23, 2024 14:46
Group by 12 per page
const input1 = [1, 12]
const output1 = [
[
[1, 2, 3],
[4, 5, 6],
[7, 8, 9],
[10, 11, 12]
]
]