Skip to content

Instantly share code, notes, and snippets.

View milksense's full-sized avatar
🙂

milksense

🙂
  • Decentralized
View GitHub Profile
@milksense
milksense / index.ts
Created July 9, 2025 20:50
Seconds to human readable format
function formatDuration(seconds: number): string {
let m = Math. floor (seconds / 60);
let s = seconds % 60;
return `${m}:${s.toString().padStart(2, "0")}`;
}
@milksense
milksense / timeline.svelte
Created July 2, 2025 06:41
Timeline component inspired from ibelick
<script lang="ts">
import { scale } from 'svelte/transition';
let hoveredIndex = $state(null as number | null);
let selected = $state(null as number | null);
// Create an array of years from 1993 to 2024
let YEARS = Array.from({ length: 2024 - 1993 + 1 }, (_, i) => 2024 - i);
let handleMouseEnter = (index: number) => {
type Options = {
/** The time before the copied status is reset. */
delay: number;
/** Whether to reset the copied status after a delay. */
reset: boolean;
};
/** Use this hook to copy text to the clipboard and show a copied state.
*
* ## Usage
import { FFmpeg } from '@ffmpeg/ffmpeg';
import { toBlobURL } from '@ffmpeg/util';
let ffmpeg: FFmpeg | null = null;
export const initFFmpeg = async (): Promise<FFmpeg> => {
if (ffmpeg) return ffmpeg;
ffmpeg = new FFmpeg();
@milksense
milksense / stars.ts
Created June 25, 2025 05:48
Get stars from GitHub repo
export async function getStars(): Promise<string> {
try {
const res = await fetch(
"https://api.github.com/repos/milksense/milksense",
{
next: { revalidate: 3600 },
}
);
if (!res.ok) {
<script lang="ts">
import { dev } from "$app/environment";
</script>
{#if dev}
<div
data-tailwind-indicator=""
class="fixed bottom-1 left-1 z-50 flex h-6 w-6 items-center justify-center rounded-full bg-gray-800 p-3 font-mono text-xs text-white"
>
<div class="block sm:hidden">xs</div>
@milksense
milksense / index.ts
Created June 16, 2025 08:25
TypeScript tip
type TODO = any
@milksense
milksense / is-mac.svelte.ts
Last active July 9, 2025 18:38
Svelte 5 `isMac` hook
import { browser } from "$app/environment"
export function useIsMac(): { readonly current: boolean } {
const isMac = $derived(browser
? "userAgentData" in navigator
? navigator.userAgentData?.platform.includes("macOS")
: navigator?.platform.includes("Mac")
: false
)
import { tick } from "svelte";
/**
* Svelte action to focus an element after it is rendered.
* Add use:focusOnRender to HTML element to focus it after it is rendered.
* @param elementRef The HTML element to focus.
*/
export function focusOnRender(elementRef: HTMLElement | null) {
async function update() {
await tick(); // Wait for the DOM to update
@milksense
milksense / index.js
Created June 10, 2025 13:00
Max bridge (beta)
var d = Object.defineProperty;
var v = (o, e, t) => e in o ? d(o, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : o[e] = t;
var n = (o, e, t) => v(o, typeof e != "symbol" ? e + "" : e, t);
class w {
constructor({
postBackButtonEvent: e,
onClick: t,
offClick: s
}) {
n(this, "visible", !1);