Skip to content

Instantly share code, notes, and snippets.

View bojidaryovchev's full-sized avatar
🏠
Working from home

bojidaryovchev

🏠
Working from home
View GitHub Profile
@bojidaryovchev
bojidaryovchev / CrossIcon.vue
Created March 17, 2024 15:18
SideModal with TrapFocus built with Vue 3
<template>
<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24">
<path
d="m12 13.4142 4.9498 4.9497 1.4142-1.4142L13.4142 12l4.9498-4.9498-1.4142-1.4142L12 10.5857 7.0503 5.636 5.636 7.0502 10.5859 12l-4.9497 4.9497 1.4142 1.4142L12 13.4142z"
fill="currentColor"
/>
</svg>
</template>
@bojidaryovchev
bojidaryovchev / countries.json
Created September 13, 2023 17:04
Countries with names, codes and flags (ISO3166-2)
[
{
"name": "Afghanistan",
"code": "AF",
"flag": "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"1em\" height=\"1em\" viewBox=\"0 0 512 512\"><mask id=\"a\"><circle cx=\"256\" cy=\"256\" r=\"256\" fill=\"#fff\"/></mask><g mask=\"url(#a)\"><path fill=\"#d80027\" d=\"M144.7 0h222.6l37 257.7-37 254.3H144.7l-42.4-255.2z\"/><path fill=\"#496e2d\" d=\"M367.3 0H512v512H367.3z\"/><path fill=\"#333\" d=\"M0 0h144.7v512H0z\"/><g fill=\"#ffda44\"><path d=\"M256 167a89 89 0 1 0 0 178 89 89 0 0 0 0-178zm0 144.7a55.7 55.7 0 1 1 0-111.4 55.7 55.7 0 0 1 0 111.4z\"/><path d=\"M256 222.6c-12.3 0-22.3 10-22.3 22.3v33.4h44.6v-33.4c0-12.3-10-22.3-22.3-22.3z\"/></g></g></svg>"
},
{
"name": "Åland Islands",
"code": "AX",
"flag": "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"1em\" height=\"1em\" viewBox=\"0 0 512 512\"><mask id=\"a\"><circle cx=\"256\" cy=\"256\" r=\"256\" fill=\"#fff\"/></mask><g mask=\"url(#a)\"><path fill=\"#0052b4\" d=\"M0 0h100.2l68.3 40.7L233.7 0H512v189.2l-45.5 66 45.5 68
@bojidaryovchev
bojidaryovchev / HoverPopup.tsx
Created April 26, 2023 19:58
React HoverPopup - a popup that moves with the mouse
import classNames from 'classnames';
import React, { PropsWithChildren, useEffect, useRef, useState } from 'react';
import { createPortal } from 'react-dom';
export interface HoverPopupComponentProps {
hoverElementRef?: React.RefObject<HTMLElement>;
}
const HoverPopupComponent: React.FC<PropsWithChildren<HoverPopupComponentProps>> = ({ hoverElementRef, children }) => {
const [mouseEvent, setMouseEvent] = useState<MouseEvent>();
@bojidaryovchev
bojidaryovchev / Next.js useRouterHooks
Last active April 6, 2023 07:23
Next.js custom hook to wrap the next/router events so we keep it DRY
import { useRouter } from "next/router";
import { useCallback, useEffect } from "react";
function useRouterHooks({
onRouteChangeStartHandler,
onRouteChangeCompleteHandler,
onRouteChangeErrorHandler,
onBeforeHistoryChangeHandler,
onHashChangeStartHandler,
onHashChangeCompleteHandler,
function amplifyMedia(mediaElem, multiplier) {
var context = new (window.AudioContext || window.webkitAudioContext),
result = {
context: context,
source: context.createMediaElementSource(mediaElem),
gain: context.createGain(),
media: mediaElem,
amplify: function(multiplier) { result.gain.gain.value = multiplier; },
getAmpLevel: function() { return result.gain.gain.value; }
};
@bojidaryovchev
bojidaryovchev / README.md
Last active March 18, 2023 00:29
MongoDB Replica Set docker-compose up (from ChatGPT 4 with ❤️)
  1. Put the docker-compose.yml, initiate-replica.js and mongodb-keyfile in the same directory (e.g. project root)
  2. Run docker-compose up (or docker-compose up -d for detached mode)
  • you might have to modify the permissions on your keyfile, in order to do so you have to run chmod 600 mongodb-keyfile (remember to use Git Bash and not just a regular console)
@bojidaryovchev
bojidaryovchev / improved-split.ts
Last active March 8, 2023 14:45
Inspired by angular-split, made able to handle flex-based areas
import {
AfterViewInit,
Component,
ContentChildren,
ElementRef,
HostBinding,
HostListener,
Input,
QueryList,
} from '@angular/core';
@bojidaryovchev
bojidaryovchev / trap-focus.ts
Created February 3, 2023 11:31
Inspired by cdkTrapFocus, made able to work everywhere
import {
AfterContentInit,
ContentChildren,
Directive,
ElementRef,
HostListener,
Input,
OnDestroy,
OnInit,
QueryList,
@bojidaryovchev
bojidaryovchev / generateHex.js
Last active January 13, 2023 10:48
generate random hex using node.js in one line of code
node -e "console.log(require('crypto').randomBytes(256).toString('base64'));"
@bojidaryovchev
bojidaryovchev / upload-container.component.ts
Created January 12, 2023 21:15
Angular Upload Container component - wrap anything inside, drag and drop a file on top and voila!
import { Component, EventEmitter, HostBinding, HostListener, Input, Output } from '@angular/core';
@Component({
selector: 'upload-container',
template: '<ng-content></ng-content>',
})
export class UploadContainerComponent {
@HostBinding('class.drop-area-active') @Input() dropAreaActive?: boolean;
@Output() dropAreaActiveChange = new EventEmitter<boolean>();