Skip to content

Instantly share code, notes, and snippets.

View yurkimus's full-sized avatar
💞

yurkimus yurkimus

💞
View GitHub Profile
let pathname = new URLPathname({
pathname: '/user/:user/todos/:todo',
search: 'tab=aaa',
hash: 'section',
});
pathname.toString([
['user', 1],
@yurkimus
yurkimus / script.sh
Created July 11, 2024 15:41
Delete all branches except main
# -v --invert-match
git branch -D $(git branch | grep -v main)
@yurkimus
yurkimus / cookie.js
Last active July 16, 2024 18:28
Methods to work with cookies
import { useRouter } from 'next/router';
import { useCallback, useId } from 'react';
import { FilterSegments, FilterTranslations } from '@/components/filters/filters.enumeration';
import { Select } from '@/components/select/select';
import { setSearchParams, stringify } from '@/utilities/methods';
const Filters = Enumeration.of(['First', 'Second'])
@yurkimus
yurkimus / enumeration.d.ts
Last active June 26, 2024 18:23
Implementation of Enumeration Prototype to simplify work with enumerations. Type definitions are included.
interface DoubleEnumeration<const Tuples extends ReadonlyArray<readonly [any, any]>> {
[(Key in Tuples[number]) as Key[0]]: Key[1];
[(Key in Tuples[number]) as Key[1]]: Key[0];
has(key: Tuples[number][number]): boolean;
keys(): IterableIterator<Tuples[number][0]>;
values(): IterableIterator<Tuples[number][1]>;
@yurkimus
yurkimus / mix.js
Created January 5, 2024 17:08
Average of 3-color tuples
const hexs = [
// Karjala
[ '538854', 'be2928', '000000' ],
// Ludic
[ '529f54', 'be2928', '3d3b7b' ],
// Veps
[ '16b370', 'ffff00', '155cdc' ],
// Russian-side Finnish
[ 'ffd301', 'ef2d20', '0167b3' ],
// Izhorian
@yurkimus
yurkimus / source.js
Last active September 2, 2023 14:27
Reactive URLSearchParams with ramda and react-router
const [searchParams, setSearchParams] = useSearchParams({ [searchParam]: defaultValue, })
useEffect(() => {
setSearchParams(
tap(
when(
compose(anyPass([isEmpty, isNil]), invokeGet(tabSearchParam)),
invokeSet(searchParam, defaultValue)
)
)
@yurkimus
yurkimus / url.js
Last active July 14, 2024 02:15
Making URLs
function URLPathname(pathname, search, hash) {
this.pathname = pathname;
this.search = new URLSearchParams(search);
this.hash = hash;
}
URLPathname.prototype.resolve = function (parameters) {
if (this.pathname) {
var resolved = this.pathname;