Skip to content

Instantly share code, notes, and snippets.

View Fornax96's full-sized avatar

Fornax Fornax96

View GitHub Profile
func videoThumbnail(ps *pixelstore.PixelStore, sourceFile pixelstore.FileID) (image.Image, error) {
// To generate thumbnails from video files we use FFMPEG. One challenge is
// that FFMPEG needs to seek to the end of the video to decode the stream
// metadata. Saving the whole file to disk would be inefficient. Luckily
// FFMPEG supports reading (and seeking) videos over HTTP. Here we start a
// HTTP server on a random TCP port, then the address of the listener is
// given to FFMPEG to read the file from. When FFMPEG exits we shut down the
// listener and the HTTP server. The resulting thumbnail image is piped to
// stdout and saved in a buffer. The buffer is then decoded and returned
// from the function

Keybase proof

I hereby claim:

  • I am fornax96 on github.
  • I am fornax96 (https://keybase.io/fornax96) on keybase.
  • I have a public key ASAg6qRo5dRf-RB5DYxujXaF40NXIU96BYzafs1f3a37eAo

To claim this, I am signing this object:

@Fornax96
Fornax96 / execution_limiter.go
Last active May 4, 2020 09:04
The execution limiter limits the execution of a certain task to X concurrent goroutines. This can be used to prevent servers from running out of memory
package util
// ExecutionLimiter is a utility which limits the concurrent execution of a
// function. When it is initialized it creates a channel with x capacity and
// fills it with x booleans. Every time the Lock() function is called a bool is
// removed from the channel. When the channel is empty the function will block
// until the Unlock function is called, which puts a new bool into the channel.
type ExecutionLimiter struct {
channel chan bool
}
@Fornax96
Fornax96 / main.go
Created February 27, 2020 15:10
go zero downtime restarts
package main
import (
"context"
"fmt"
"net"
"net/http"
"os"
"os/exec"
"os/signal"
package main
import (
"bufio"
"fmt"
"os"
"strconv"
"strings"
)