Skip to content

Instantly share code, notes, and snippets.

View Voldrix's full-sized avatar

Ben Goriesky Voldrix

View GitHub Profile
@Voldrix
Voldrix / signal_template.c
Last active January 31, 2024 16:13
multithreaded signal driven IO without multiplexing template in C
#include <string.h>
#include <unistd.h>
#include <pthread.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <signal.h>
#define THREADS 4
#define QUEUE_DEPTH 32 //power of 2
#define BUFFER_SIZE 2048
@Voldrix
Voldrix / ip_to_str.c
Created January 8, 2024 21:21
IP Address to String Conversion in C
//convert an integer IPv4 address to a string OR a string to an integer IPv4 address
//STR to IP
static unsigned int str_to_ip(char *str) {
//assumes str is properly formatted IPv4 address
register unsigned int ip, octet;
register char *tail = str;
while(*tail++)
; //work backwards to track decimal position
@Voldrix
Voldrix / base64.c
Last active January 29, 2024 03:49
Simple Base64 Encoder / Decoder in C
static const unsigned char digits[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
//if you trust your input only has valid characters (defined above), you can cut this in half (123 instead of 256)
//probably not recommended, just in case, as invalid characters could cause a seg fault
unsigned char digitsDecode[256] = {0};
for(int i = 0; i < 64; i++)
digitsDecode[digits[i]] = i;
int base64_encode(register unsigned char *buff, unsigned char* str, int len) {
@Voldrix
Voldrix / bif_generator.sh
Created March 11, 2023 16:23
Generate .BIF media preview thumbnails (trick play)
#!/bin/bash
#Generate .BIF media preview thumbnails
#REQUIRES: ffmpeg, mediainfo, and roku's biftool
if [ -z "$1" ]; then echo -e "\nGenerate .BIF media preview thumbnails\nFiles are stored in source folder\n\nUsage: ${0##*/} [video files/directories...] <Absolute or Relative paths. Recursive>\n";exit 1;fi
tmpdir="/tmp/bifgen"
[ -d "$tmpdir" ] && rm -f "$tmpdir"/* || mkdir -p "$tmpdir"
IFS=$'\n'
@Voldrix
Voldrix / animated_thumbnail_gen.sh
Last active August 2, 2023 09:26
Create animated thumbnail with ffmpeg in bash
#!/bin/bash
#Creates an animated thumbnail of a video clip
#This script uses scene cuts instead of fixed time intervals, and does not work well for videos with few/infrequent scene cuts
if [ -z "$1" ];then echo "Usage: <Video Files...> [outputs to same dir as input]" &>2;exit 1;fi
numOfScenes=8 #max number of scenes
sceneLength=1.5 #length of each scene in seconds
sceneDelay=1.7 #time (seconds) after a frame cut to start scene (to avoid transition effects)
for i;do