Skip to content

Instantly share code, notes, and snippets.

View sepastian's full-sized avatar
💭
\_ . |‾‾‾| o-`o

Sebastian Gassner sepastian

💭
\_ . |‾‾‾| o-`o
View GitHub Profile
@sepastian
sepastian / v4l2_set_camera_zoom_level.md
Last active June 29, 2023 07:58
V4L2 set camera zoom level

Environment

$ uname -a
Linux x220 6.3.0-1-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.3.7-1 (2023-06-12) x86_64 GNU/Linux

List Cameras

@sepastian
sepastian / raw_to_ppm_to_jpg.sh
Last active April 3, 2025 13:25
RAW to PPM (dcraw) to JPG (imagemagick)
#!/bin/bash
set -euo pipefail
# Find files created within 1 days (`-ctime -1`);
# convert (Nikon/NEF) RAW images to PPM using dcraw;
# write results to stdout with -c;
# convert stdin to JPG using Imagemagick's convert;
# specify format of input image with 'ppm:-'.
find /path/to/sdcard/ -name '*.NEF' -ctime -1 \
@sepastian
sepastian / ext4_fs_tuning.md
Last active March 10, 2023 16:36
ext4 file system tuning
@sepastian
sepastian / record_left_monitor.zsh
Last active November 2, 2022 11:25
Record left monitor from CLI
# Oh-My-ZSH custom function to record left monitor from CLI.
#
# Place in $ZSH/.oh-my-zsh/custom.
#
# Two monitors at screen 0, the left one connected at DP-1:
#
# xrandr
# Screen 0: minimum 320 x 200, current 3840 x 1200, maximum 16384 x 16384
# DP-1 connected primary 1920x1200+1920+0 (normal left inverted right x axis y axis) 518mm x 324mm
# 1920x1200 59.95*+
@sepastian
sepastian / compress_pdf.zsh
Last active November 2, 2022 11:15
Compress PDF custom Oh-My-ZSH function
# Place in $ZSH/.oh-my-zsh/custom.
#
# The following ZSH function uses GhostScript's `gs` command to reduce the file size of a PDF file.
# The result of compressing `test.pdf` will be written to `test.compressed.pdf`.
# If `test.compressed.pdf` exists, it will only be overwritten after confirmation.
#
# Now, restart/open a new shell and compress PDFs with:
#
# compress_pdf test.pdf
# File exists: test.compressed.pdf, overwrite (Y/n)?
@sepastian
sepastian / determine_dpi.sh
Last active October 14, 2022 09:16
Determine Image DPI
# Based on https://apple.stackexchange.com/a/389067/453491
# In order to calculate DPI, determine units and resolution first.
identify -verbose warc2corpus@2x_300dpi.png | grep -E -i "resolution|units"
# Resolution: 118.11x118.11
# Units: PixelsPerCentimeter
# png:pHYs: x_res=11811, y_res=11811, units=1
# 1 PixelsPerCentimeter corresponds to 2.54 DPI.
# Calculate DPI using the following command.
@sepastian
sepastian / heap.rb
Last active October 3, 2022 13:54
Heap in Ruby
class Heap
def initialize(*elems)
@h= heapify(elems)
end
def inspect
return '(empty)' if @h.empty?
@h
.group_by.with_index{ Math.log2(_2+1).to_i }
.map{ |l,vs| vs.join(' ') }
.join("\n")
@sepastian
sepastian / annotate_images_with_timestamp.sh
Created August 1, 2022 08:13
Annotate images with timestamp, in parallel
#!/bin/bash
# Options to -draw are not well documented;
# see: https://www.imagemagick.org/Usage/fonts/
set -euo pipefail
IFS=$'\n\t'
indir="/media/sebastian/3161-3938/DCIM"
@sepastian
sepastian / extract_pdf_images_in_parallel.sh
Created May 4, 2022 13:16
Extract PDF images in parallel
# For each page in input.pdf,
# generate image(s) in PNG format
# named output_<PAGE>.png
# where PAGE is a 4-digit zero-padded number.
pdfinfo input.pdf \
| grep Pages \
| awk -F'[: ]*' '{print $2}' \
| xargs seq \
| parallel \
'\
1. Download and install the official PPD files
See https://www.konicaminolta.de/de-de/support/download-center
Latest version at time of writting is `BH554ePPDLinux_300000000MU.zip`
2. Find out printer's IP address
On the printer, press