This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package withcloser | |
import "io" | |
type reader struct { | |
io.Reader | |
close func() error | |
} | |
func (r reader) Close() error { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -eu -o pipefail | |
# This script ensures source code files | |
# have copyright license headers. | |
# | |
# It modifies all source files in place | |
# and avoids adding a license header | |
# to any file that already has one. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package seen | |
type Seen[T comparable] struct { | |
Map map[T]struct{} | |
} | |
func New[T comparable](size int) Seen[T] { | |
return Seen[T]{ | |
Map: make(map[T]struct{}, size), | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func RandomBytes(length int) []byte { | |
const charset = "abcdefghijklmnopqrstuvwxyz" + | |
"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\t\n " | |
b := make([]byte, length) | |
for i := range b { | |
b[i] = charset[rand.Intn(len(charset))] | |
} | |
return b | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package rndstr | |
import ( | |
"crypto/rand" | |
"encoding/base64" | |
) | |
func RndStr(n int) (string, error) { | |
rnd := make([]byte, n + 10) | |
_, err := rand.Read(rnd) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# like surfraw, but not a million fucking lines long. | |
# requires dmenu. | |
# the default search engine is shown at first. | |
# to select another search engine, press enter when | |
# the prompt is empty in dmenu. | |
# name of the default search engine | |
default='Searx' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh -efu | |
# split the given video/audio files by chapters using ffmpeg. | |
for file; do | |
ffprobe -print_format csv -show_chapters -- "$file" | cut -d, -f5,7,8 | | |
while IFS=, read start end chapter; do | |
ffmpeg -hide_banner -nostdin -ss "$start" -to "$end" -i "$file" \ | |
-c copy -map 0 -map_chapters -1 -- "${file%.*}-$chapter.${file##*.}" | |
done | |
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* source: https://stackoverflow.com/questions/29977651/how-can-the-pulseaudio-asynchronous-library-be-used-to-play-raw-pcm-data#29980624 | |
* pcm-playback: pcm-playback.c | |
* gcc -o pcm-playback pcm-playback.c `pkg-config --cflags --libs libpulse` */ | |
#include <stdio.h> | |
#include <assert.h> | |
#include <pulse/pulseaudio.h> | |
#define FORMAT PA_SAMPLE_U8 | |
#define RATE 44100 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* source: https://legacy.imagemagick.org/discourse-server/viewtopic.php?p=80803#p80803 | |
* requires the "opencl-headers" package | |
* compile: | |
* cc ConvertExample.c -o convert $(pkg-config --libs --cflags MagickCore MagickWand) */ | |
/* | |
Bare minimal test of a direct call to ConvertImageCommand() | |
Actually this is basically what the "convert" command does. | |
Compile with... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <glob.h> | |
#include <string.h> | |
#include <stdlib.h> | |
#include <unistd.h> | |
#define LENGTH(X) (sizeof(X) / sizeof(X[0])) | |
void getproccwd(const unsigned int pid, char *cwd, const unsigned int size); | |
void getdesc(const unsigned int pid, int *desc, const unsigned int size); |
NewerOlder