Skip to content

Instantly share code, notes, and snippets.

View kdankov's full-sized avatar

Konstantin Dankov kdankov

View GitHub Profile
import type { Loader } from 'astro/loaders';
import { z } from 'astro:content'
import type { YouTubeLoaderOptions } from "./types/youtube-loader-options.type.ts";
export function youtubeLoader(options: YouTubeLoaderOptions): Loader {
const url = new URL('https://www.googleapis.com/youtube/v3/search');
url.searchParams.append('key', options.apiKey);
url.searchParams.append('channelId', options.channelId);
@kdankov
kdankov / month-printer.js
Created October 31, 2024 09:59
Month Printer
function solve(num) {
if ( num > 0 && num < 13 ) {
console.log(new Date(2000, num-1).toLocaleString('default', { month: 'long' }));
} else {
console.log('Error!');
}
}
@kdankov
kdankov / solution.js
Created November 12, 2024 11:57
Fun with JS
function solve(s, o) {
Object
.entries([...s, ...o].reduce((s, p, i, a) => ( i % 2 === 0 ? { ...s, [p]: (s[p] || 0) + Number(a[i + 1]) } : s), {}))
.forEach(([p, q]) => console.log(`${p} -> ${q}`));
}
@kdankov
kdankov / jquery-alias-selector.js
Created November 14, 2024 21:38
Aliases for querySelector(All)
var $ = document.querySelector.bind(document);
var $$ = document.querySelectorAll.bind(document);
Element.prototype.$ = function() {
return this.querySelector.apply(this, arguments);
};
Element.prototype.$$ = function() {
return this.querySelectorAll.apply(this, arguments);
};
@kdankov
kdankov / app.js
Created November 27, 2024 22:10
Gem Collection - Task 1 from JS Advanced Exam - 05 April 2023
window.addEventListener("load", solve);
function solve() {
const inputElements = ['gem-name', 'color', 'carats', 'price', 'type'];
const previewEl = document.querySelector('#preview-list');
const collectionEl = document.querySelector('#collection');
function getFormInputsAndValues() {
@kdankov
kdankov / tabs.html
Created April 15, 2025 14:05
Semantic Tabs with Details and Summary
<h1>Warp Drive</h1>
<p>A warp drive or a drive enabling space warp is a fictional superluminal (faster than the speed of light) spacecraft propulsion system in many science fiction works, most notably Star Trek, and a subject of ongoing real-life physics research. The general concept of "warp drive" was introduced by John W. Campbell in his 1957 novel Islands of Space and was popularized by the Star Trek series. Its closest real-life equivalent is the Alcubierre drive, a theoretical solution of the field equations of general relativity.</p>
<section class="tabs">
<details name="group" open>
<summary>History and characteristics</summary>
<p>Warp drive, or a drive enabling space warp, is one of several ways of travelling through space found in science fiction. It has been often discussed as being conceptually similar to hyperspace. A warp drive is a device that distorts the shape of the space-time continuum. A spacecraft equipped with a warp drive may travel at speeds greater than that of light by