Skip to content

Instantly share code, notes, and snippets.

View predaytor's full-sized avatar
🍁
it's perfect

Dmytro Pushkarchuk predaytor

🍁
it's perfect
View GitHub Profile
@stenuto
stenuto / hls.sh
Created November 7, 2024 16:58
HLS ffmpeg script
#!/bin/bash
# Function to display usage information
usage() {
echo "Usage: $0 /path/to/input.mp4 [ /path/to/output_directory ]"
exit 1
}
# Check if at least one argument (input file) is provided
if [ $# -lt 1 ]; then
@EvanBacon
EvanBacon / skeleton.tsx
Created October 23, 2024 23:38
Animated skeleton component with Expo SDK 52
"use client";
import React from "react";
import { View, StyleSheet, Animated, Easing, ViewStyle } from "react-native";
const BASE_COLORS = {
dark: { primary: "rgb(17, 17, 17)", secondary: "rgb(51, 51, 51)" },
light: {
primary: "rgb(250, 250, 250)",
secondary: "rgb(205, 205, 205)",
import type { EntryContext } from "@remix-run/cloudflare";
import { renderToReadableStream } from "react-dom/server";
import { Hono } from "hono";
import { RemixServer } from "@remix-run/react";
export const handle =
(userApp?: Hono) =>
(
request: Request,
responseStatusCode: number,
@okikio
okikio / constrain-transform-stream-queues.md
Created September 1, 2024 03:21
Queue's via TransformStreams

Using TransformStream in place of traditional queue implementations is an interesting approach that leverages the stream API's natural queuing and backpressure features. Below is a breakdown of how you might implement each queue type using TransformStream, adhering to the constraint of using no more than 2 TransformStreams per queue, and addressing any limitations that arise.

1. Simple Queue (FIFO Queue)

  • Implementation:
    • TransformStream 1: This stream simply passes data from the writable side to the readable side in FIFO order.
    • TransformStream 2: Not necessary in this case, as one TransformStream is sufficient to maintain the FIFO order.
const fifoQueue = new TransformStream({
transform(chunk, controller) {
@rphlmr
rphlmr / index.ts
Last active July 30, 2024 03:11
Link XState and Remix fetcher
import type { ActionFunctionArgs, LoaderFunctionArgs } from '@remix-run/node';
import {
ClientActionFunctionArgs,
ClientLoaderFunctionArgs,
useFetcher,
useLoaderData,
} from '@remix-run/react';
import { enqueueActions, fromPromise, setup } from 'xstate';
import { useActor } from '@xstate/react';
import { useEffect, useRef } from 'react';
#
# See https://fly.io/docs/reference/configuration/ for information about how to use this file.
#
app = "my-app"
primary_region = "cdg"
kill_signal = "SIGINT"
kill_timeout = "5s"
swap_size_mb = 256
@VariableVic
VariableVic / google-analytics.ts
Last active November 11, 2024 19:47
Medusa -> Google Analytics 4 server side tracking example
import { TransactionBaseService } from "@medusajs/medusa";
import {
ConsentSettings,
EventItem,
JSONPostBody,
} from "../types/google-analytics";
const { subtle } = require("crypto").webcrypto;
@pilcrowonpaper
pilcrowonpaper / crypto-random-integer.ts
Last active January 6, 2024 23:21
Generates a random integer between 0 and a max number.
function generateRandomInteger(max: number): number {
if (max < 0 || !Number.isInteger(max)) {
throw new Error("Argument 'max' must be an integer greater than or equal to 0")
}
const bitLength = (max - 1).toString(2).length
const shift = bitLength % 8
const bytes = new Uint8Array(Math.ceil(bitLength / 8))
while (true) {
crypto.getRandomValues(bytes)
// This zeroes bits that can be ignored to increase the chance `result` < `max`.
@nmn
nmn / utilities.stylex.ts
Created December 12, 2023 09:37
Tailwind Utilities in StyleX
import * as stylex from '@stylexjs/stylex'
export default stylex.create({
sr_only: {
position: 'absolute',
width: 1,
height: 1,
padding: 0,
margin: -1,
overflow: 'hidden',
@rphlmr
rphlmr / helpers.ts
Last active October 28, 2024 17:08
Drizzle ORM, deep sub queries
/* -------------------------------------------------------------------------- */
/* More here; */
/* -------------------------------------------------------------------------- */
// https://gist.github.com/rphlmr/0d1722a794ed5a16da0fdf6652902b15
export function distinctOn<Column extends AnyColumn>(column: Column) {
return sql<Column["_"]["data"]>`distinct on (${column}) ${column}`;
}
export function jsonBuildObject<T extends SelectedFields>(shape: T) {