Skip to content

Instantly share code, notes, and snippets.

View zecka's full-sized avatar

Robin Ferrari zecka

  • SQLI Switzerland
  • Geneva
  • 06:23 (UTC +01:00)
View GitHub Profile
@zecka
zecka / kill-css-browser.js
Last active October 31, 2025 15:24
Kill all style and link rel stylesheet in webpage from browser
(() => {
let count = 0;
const removeInRoot = root => {
const styles = root.querySelectorAll('style');
styles.forEach(s => s.remove());
count += styles.length;
const stylesLinks = root.querySelectorAll('link[rel="stylesheet"]');
stylesLinks.forEach(s => s.remove());
@zecka
zecka / scrollParentToChild.ts
Last active October 27, 2025 10:40
scrollParentToChild
export const isElementFullyVisible = (element: HTMLElement, topThreshold = 0) => {
if (window && document) {
const windowHeight = window.innerHeight || document.documentElement.clientHeight;
const rect = element.getBoundingClientRect();
return rect.top > topThreshold && rect.bottom < windowHeight;
}
return false;
};
export function scrollParentToChild(parent: Element, child: Element, threshold = 100): void {
// Where is the parent on page
@zecka
zecka / css-path.ts
Created October 9, 2025 12:52
Css var to css path union type
type CssPath<T extends string> =
T extends `--${infer Rest}` // enlève les "--" du début
? ReplaceDashWithSlash<Rest> // remplace les tirets restants
: never
type ReplaceDashWithSlash<S extends string> =
S extends `${infer Head}-${infer Tail}`
? `${Head}/${ReplaceDashWithSlash<Tail>}`
: S
@zecka
zecka / radio.ts
Created September 30, 2025 12:36
radio group angular
// radio-group.component
import { Component, ContentChildren, QueryList, forwardRef } from '@angular/core';
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
import { RadioItemComponent } from './radio-item.component';
let nextId = 0;
@Component({
selector: 'radio-group',
// src/variants.ts
export type VariantDef = Record<string, readonly string[]>;
export type VariantProps<T extends VariantDef> = {
[K in keyof T]?: T[K][number];
} & { class?: string };
// src/factory.ts
import { cva } from "class-variance-authority";
import type { VariantDef, VariantProps as PublicProps } from "./variants";
@zecka
zecka / tsc.programmatic.ts
Created September 23, 2025 13:02
tsc programmatic
// build.js
import ts from "typescript";
import path from "path";
async function build() {
const projectDir = path.resolve("./packages/ds-tokens");
const configPath = path.join(projectDir, "tsconfig.build.json");
// 1. Charger tsconfig
const configFile = ts.readConfigFile(configPath, ts.sys.readFile);
@zecka
zecka / gist:4a253750211f8150ac423dd2bf7573b6
Last active July 6, 2025 09:58
Run COSMODB locally with data explorer (docker)
[ -f save.json ] || echo '{}' > save.json && docker run --rm \
-e COSMIUM_PERSIST=/save.json \
-e COSMIUM_DISABLETLS=true \
-e COSMIUM_ACCOUNTKEY=C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw== \
-v ./save.json:/save.json \
-p 8081:8081 \
ghcr.io/pikami/cosmium:explorer
@zecka
zecka / swr-without-revalidation.jsx
Created May 26, 2025 19:10
SWR Mutation without api revalidation:
/**
* @see: https://stackoverflow.com/questions/72757228/mutate-useswr-data-local-state-without-revalidating
*/
import React from "react";
import useSWR from "swr";
const fetcher = async (url) => {
await new Promise(resolve => setTimeout(resolve, 1000));
return fetch(url).then((res) => res.json())
};
@zecka
zecka / onetrust.d.ts
Created November 27, 2024 13:10
Onetrust SDK Typescript definition
export {};
/**
* In both methods above, the options parameter provides a way to further manipulate page content
* based on whether consent for a group of cookies has been given.
* This provides a simple mechanism that enables website owners to either incentivize users to opt-in or deliver
* a different user experience to visitors who opt-out.
* @see https://my.onetrust.com/articles/en_US/Knowledge/UUID-518074a1-a6da-81c3-be52-bae7685d9c94
*/
type OneTrustInsertScriptOptions = {
/** Delete all parent container content before inserting the element */
@zecka
zecka / sync-folder.ts
Created August 30, 2024 10:10
Typescript : Sync two folder with watch option
import chalk from 'chalk';
import * as fs from 'fs';
import * as path from 'path';
import * as util from 'util';
const copyFile = util.promisify(fs.copyFile);
interface SyncOptions {
sourceDir: string;
targetDir: string;