Skip to content

Instantly share code, notes, and snippets.

@deviationist
deviationist / ffmpeg-audio-helpers.sh
Last active October 11, 2024 10:24
Useful FFMPEG Audio bash functions
function flactoaiff() {
if [[ $1 != *.flac ]]; then
echo "Please provide a FLAC-file"
return 1
fi
newFilePath="${1/%.flac/.aiff}"
ffmpeg -y -nostdin -i $1 -write_id3v2 1 -c:v copy $newFilePath
}
function downsample() {
@deviationist
deviationist / file.md
Created October 7, 2024 14:00
Revert recently deleted files on Ubuntu/Debian
@deviationist
deviationist / Sanity-RichDate-example-object.js
Last active August 23, 2024 06:48
An example of how a value for a richDate-field looks like in Sanity.
{
exampleField: {
_type: 'richDate',
local: '2024-03-12T00:00:00+01:00',
offset: 60,
utc: '2024-03-11T23:00:00.000Z',
timezone: 'Europe/Oslo'
}
}
@deviationist
deviationist / laravel-console-symfony-progress-indicator.php
Created July 8, 2024 17:35
How to use Symfony's ProgressIndicator-class in a Laravel Console command.
$indicator = new \Symfony\Component\Console\Helper\ProgressIndicator($this->output);
$indicator->start('Starting the process...');
foreach (range(0, 10) as $i) {
usleep(5 * 10000);
$indicator->advance();
}
$indicator->finish('Process complete!');
@deviationist
deviationist / TextFit.tsx
Last active April 7, 2024 12:49
A function-based React-component that will scale font size up/down to use all available space inside a container. Uses Tailwind CSS.
import React, { useEffect, useState, useRef, useCallback } from 'react';
type Props = {
text: string
maxSize?: number
minSize?: number
maxHeight?: number
fontStepSize?: number
containerWidthMargin?: number
initialHidden?: boolean
@deviationist
deviationist / heic2jpeg.ts
Last active March 12, 2024 17:27
A simple HEIC to JPEG-implementation for Node using libheif-js (https://www.npmjs.com/package/libheif-js) and canvas (https://www.npmjs.com/package/canvas). Not type safe, should be refined. Based of catdad-experiments/heic-convert.
import libheif from 'libheif-js';
import { ImageData, Canvas, createCanvas } from 'canvas'
type Props = {
buffer: Buffer;
quality: number;
};
const processSingleImage = (image: any): Promise<any> => {
return new Promise((resolve, reject) => {
@deviationist
deviationist / useDebounce.ts
Created March 7, 2024 18:35
A simple debouce use-hook for React and TypeScript
import { useEffect, useRef } from 'react';
export const useDebounce = (callback: Function, delay: number) => {
const timeoutRef = useRef<null|NodeJS.Timeout>(null);
useEffect(() => {
return () => {
if (timeoutRef.current) {
clearTimeout(timeoutRef.current);
}
};
}, []);
@deviationist
deviationist / unique-email-field.ts
Last active February 9, 2024 23:16
Sanity unique e-mail field
defineField({
name: 'email',
title: 'Email',
type: 'string',
readOnly: ({document}) => document?.origin === 'Checkin',
description: 'Can only be changed in Checkin if the origin is "Checkin".',
validation: Rule => Rule.required().email().custom(async (email: any, context: any) => {
const response = await client.fetch(`*[_type == "user" && email == $email && !(_id in [$draftId, $id])]`, {email, draftId: context.document._id, id: context.document._id.replace('drafts.', '')});
if (response?.length > 0) {
return 'Email already in use';
@deviationist
deviationist / macos-bootable-usb.txt
Created January 12, 2024 18:13
Create macOS bootable USB on a M1 Macbook (High Sierra in this example)
You might need to format the USB-stick with Mac Extended (Journaled) before starting this process.
This guide is primarily based on Apple's own guide (https://support.apple.com/en-us/101578), but it solves other issues which is not adressed by Apple.
1. Download Mist: https://github.com/ninxsoft/Mist
Go the the release-page and download the latest "dmg"-file.
https://github.com/ninxsoft/Mist/releases
2. Extract the app-file and place it in your Applications-folder
3. Open the app-file (you might need to right click it and click "Open"), then click "Open" again to proceed.
@deviationist
deviationist / gist:51cf2caf8d8e7db117d87cb2a1a5d23a
Created November 12, 2023 12:16
Downsample an AIFF-file using FFMPEG.
ffmpeg -y -nostdin -i a.aiff -ar 44100 -write_id3v2 1 -c:v copy b.aiff