Skip to content

Instantly share code, notes, and snippets.

View krystalcampioni's full-sized avatar

Krystal Campioni krystalcampioni

View GitHub Profile
#!/bin/bash
INPUT_DIR="UPLOAD"
OUTPUT_DIR="frames"
MAX_WIDTH=1920
QUALITY=80
FORMAT="webp" # can be webp, jpg, or png
mkdir -p "$OUTPUT_DIR"
for i in *.mp4; do ffmpeg -i "$i" -c:v libvpx-vp9 -b:v 2M -c:a libopus -b:a 128k "${i%.*}.webm"; done
@krystalcampioni
krystalcampioni / get-differences.ts
Last active January 3, 2025 15:42
Get the differences between two similar objects, like a git diff
import {isEqual, transform, isObject} from 'lodash';
interface Diff {
base: any;
comparison: any;
}
/**
* Get the differences between two objects.
* @param base - The base object.
generateTranslationTypes() {
if [ "$#" -ne 1 ]; then
echo "Usage: generateTranslationTypes <json-file>"
return 1
fi
JSON_FILE="$1"
if [ ! -f "$JSON_FILE" ]; then
@krystalcampioni
krystalcampioni / Typescript_enforceMaxLength.ts
Last active November 22, 2024 15:20
Typescript Enforce Array Max Length Type
/**
* Enforces that an array respects a maximum length.
*
* @param {T[] | undefined} array - The array to validate.
* @param {number} maxLength - The maximum length.
* @returns {(T[] & {length: number}) | undefined} - Returns the array if valid, otherwise undefined.
*/
export function enforceMaxLength<T, N extends number>(
array: T[] | undefined,
maxLength: N,
@krystalcampioni
krystalcampioni / conventional-commits.sh
Created January 26, 2024 15:52
Enforcing conventional commit messages
# Enforcing Conventional Commits with a Git Hook
# This gist provides instructions on how to set up a `commit-msg`
# Git hook to enforce [conventional commits](http://www.conventionalcommits.org) in your project.
# The `commit-msg` script checks the commit message against a regex pattern to ensure
# it follows the conventional commit format.
# The `text-styles.sh` script is used to colorize the output of the `commit-msg` script for better readability.
# ----- 1. Copy the hook files to .git/hooks -----
# You need to copy the files from <root>/hooks into <root>/.git/hooks when initializing your project.
@mixin removeDefaultStyles() {
background-color: transparent;
border: none;
margin: 0;
padding: 0;
text-align: inherit;
font-family: inherit;
border-radius: 0;
appearance: none;
}
function useThrottle<T>(value: T, interval = 500): T {
const [throttledValue, setThrottledValue] = useState<T>(value);
const lastExecuted = useRef<number>(Date.now());
useEffect(() => {
if (Date.now() >= lastExecuted.current + interval) {
lastExecuted.current = Date.now();
setThrottledValue(value);
} else {
const timerId = setTimeout(() => {
export interface DataPoint {
key: number | string;
value: number | null;
}
export interface DataSeries {
data: DataPoint[];
color?: Color;
isComparison?: boolean;
name: string;
export function useYScale({
drawableHeight,
integersOnly,
data
}) {
// ...
return { yScale, yTicks }
}