Skip to content

Instantly share code, notes, and snippets.

View grocky's full-sized avatar

Rocky Gray grocky

View GitHub Profile
@grocky
grocky / gif-reduce.sh
Created November 25, 2020 19:45
Reduce a gif down to a desired number of frames
#!/usr/bin/env bash
# Reduce a gif down to a desired number of frames.
# Useful for really large gifs that you'd like to truncate.
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
PROJ_DIR=$(realpath "${DIR}/..")
TEMP_DIR=$(mktemp -d )
REDUCED_DIR=$(mktemp -d)
@grocky
grocky / gallery.html
Last active November 24, 2020 03:42
Hugo photo and video gallery with image processing, Exif rotation, and schema.org metadata
@grocky
grocky / gifs.md
Created October 17, 2020 15:52
Creating gifs and videos from a collection of images

Notes on creating gifs and videos from a colleciton of images

Great notes on this blog: How to create GIFs with FFmpeg

Format filenames

Rename all of the target images to have a sequential naming scheme.

a=1; for i in *.png; do new=$(printf "%04d.png" "$a"); mv -i -- "$i" "$new"; let a=a+1; done
@grocky
grocky / cloudwatch_log_insights_mysql_slow_query_examples.md
Last active April 28, 2023 12:40
CloudWatch Log Insights query examples for MySQL slow query log.

Filtering queries

Find slowest write queries

parse @message /Query_time: (?<queryTime>.*?) Lock_time: (<?lockTime>.*?) Rows_sent: (?<rowsSent>.*?) Rows_examined: (?<rowsExamined>.*?)\s(?<query>.*?)$/
  | filter @message like /(?i)insert/
  | sort queryTime desc
  | limit 10
@grocky
grocky / upload-github-release-asset.sh
Created July 5, 2020 14:47 — forked from stefanbuck/upload-github-release-asset.sh
Script to upload a release asset using the GitHub API v3.
#!/usr/bin/env bash
#
# Author: Stefan Buck
# License: MIT
# https://gist.github.com/stefanbuck/ce788fee19ab6eb0b4447a85fc99f447
#
#
# This script accepts the following parameters:
#
# * owner
@grocky
grocky / main.go
Created June 13, 2020 08:02
mouse-detective
func processResults(results <-chan result) {
for r := range results {
if r.err != nil {
log.Printf("Frame result with an error: %v\n", r.err)
continue
}
log.Printf("Mouse detected! frame: %d, detectors: %v\n", r.frame, r.detectors)
image, err := jpeg.Decode(r.file)
if err != nil {
@grocky
grocky / checker.go
Last active June 13, 2020 08:00
mouse-detective
type result struct {
// the frame number
frame int
// The detected bounds
detectors []objectbox.CheckDetectorResponse
file io.Reader
err error
}
func checker(done <-chan struct{}, frames <-chan frame, results chan<- result) {
@grocky
grocky / frame-extraction.go
Created June 13, 2020 07:58
mouse-detective
func extractFrames(done <-chan struct{}, filename string) (<-chan frame, <-chan error) {
framec := make(chan frame)
errc := make(chan error, 1)
go func() {
defer close(framec)
video, err := gocv.VideoCaptureFile(filename)
if err != nil {
errc <- err
@grocky
grocky / docker-compose.yml
Last active June 13, 2020 07:58
mouse detective
version: '3'
services:
objectbox1:
image: machinebox/objectbox
environment:
- MB_KEY=${MB_KEY}
- MB_OBJECTBOX_ANNOTATION_TOOL=true
ports:
- "8083:8080"
volumes:
@grocky
grocky / IdempotentSQLAlterTableAddColumn.sql
Last active July 16, 2019 17:16 — forked from kmoormann/IdempotentSQLAlterTableAddColumn.sql
Idempotent SQL Alter Table Statements
-- Idempotently add the tasks.id column
SET @table_name = 'tasks';
SET @column_name = 'id';
SET @preparedStatement = (SELECT IF(
(
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
WHERE table_name = @table_name
AND column_name = @column_name
AND data_type = 'BIGINT'
) > 0,