Skip to content

Instantly share code, notes, and snippets.

View krystxf's full-sized avatar
🦄
I don't even know what am I doing anymore

Kryštof Krátký krystxf

🦄
I don't even know what am I doing anymore
View GitHub Profile
@krystxf
krystxf / index.html
Last active March 27, 2026 23:00
x.ai canvas effect
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>xAI Canvas Effect</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { width: 100%; height: 100%; overflow: hidden; background: #000; }
canvas { display: block; width: 100%; height: 100%; }
@krystxf
krystxf / carousel.tsx
Last active April 8, 2025 18:00
Tailwind infinite horizontal scrolling carousel animation
@krystxf
krystxf / PolymorphicComponent.tsx
Last active April 3, 2025 10:20
Typesafe polymorphic component in React
import type { ComponentPropsWithoutRef, ElementType } from "react"
type PolymorphicComponentProps<TAs extends ElementType, TProps = object> = Omit<
ComponentPropsWithoutRef<TAs>,
keyof TProps | "as" // Prevent prop conflicts between TProps and built-in props
> &
TProps & { as?: TAs }
export const MyComponent = <T extends ElementType = "div">({
as,
@krystxf
krystxf / unzip-file-from-url.js
Last active November 19, 2024 23:21
Unzip file from URL in memory in JS
import { Open as unzipperOpen } from "unzipper";
const response = await fetch("http://example.com/file.zip");
const arrayBuffer = await response.arrayBuffer();
const buffer = Buffer.from(arrayBuffer);
const directory = await unzipperOpen.buffer(buffer);
// print out files and its contents
for (const file of directory.files) {
const fileBuffer = await file.buffer();
@krystxf
krystxf / Typewriter.tsx
Last active November 18, 2024 00:40
framer-motion typewriter effect
import { motion } from "framer-motion";
import { useState } from "react"
const App = () => {
const [value, setValue ] = useState("")
const text = value.split("")
return (
<div>
<input
@krystxf
krystxf / countdown.view.swift
Last active November 16, 2024 23:33
SwiftUI Countdown
import SwiftUI
import Foundation
func getRemainingTime(_ remainingSeconds: TimeInterval) -> String {
let remainingSecondsAbs = abs(remainingSeconds)
let hours = Int(remainingSecondsAbs) / 3600
let minutes = Int(remainingSecondsAbs) % 3600 / 60
let seconds = Int(remainingSecondsAbs) % 60
let isNegative = Bool(remainingSeconds < 0)
@krystxf
krystxf / object-values-deep.js
Created September 30, 2024 12:03
Get object values from nested objects
const deepValues = (obj) => {
return Object.values(obj).flatMap((value) => {
if (typeof value === "object") {
return deepValues(value);
}
return value;
});
};
@krystxf
krystxf / squiggly-line.md
Last active September 30, 2024 09:15
Google inspired squiggly line

@krystxf
krystxf / .bashrc
Last active December 16, 2024 12:56
Detect JS package manager based on the folder contents
#! /bin/bash
# this script is meant for zsh, there might be some fixes needed to run it in bash or other shells
p() {
# Start at the current directory and check up to two directories above
dirs=( "." ".." "../.." )
for dir in "${dirs[@]}"; do
if [ -f "$dir/pnpm-lock.yaml" ]; then
echo "Using pnpm"
pnpm "$@"
@krystxf
krystxf / remove-diacritics.ts
Created August 20, 2024 14:41
Remove diacritics in JS
const removeDiacritics = (str: string): string => {
return str.normalize("NFD").replace(/\p{Diacritic}/gu, "");
};