Skip to content

Instantly share code, notes, and snippets.

premek /
Last active June 21, 2023 21:36
make an image look like it was scanned
# separate pdf pages
convert -density 400 doc.pdf page-%0d.jpg
# use gimp to insert the signature at the right place at the right page, remove unnecessary pages etc
# scan
for F in page*jpg; do
convert -resize 1800x1800 -density 95 -flatten "$F" -rotate "0.$(( ( RANDOM % 2 ) + 3 ))" +repage -attenuate "0.$(( ( RANDOM % 8 ) + 20 ))" +noise Gaussian -quality 85 -compress JPEG -colorspace gray "$F-scanned.jpg"
premek /
Last active October 29, 2020 22:37
Display raspberry camera video on HDMI screen using Raspberry OS Lite (no desktop, no X Window)
  • sudo nano /boot/cmdline.txt and change console=tty1 to console=tty2
  • sudo nano /etc/rc.local and add /home/pi/ &
chmod a+x
# downloads a page from gemini server
(echo "gemini://"; sleep 1) | openssl s_client -connect
premek /
Last active March 5, 2024 17:43
Rename files in linux / bash using mv command without typing the full name two times
# Put this function to your .bashrc file.
# Usage: mv oldfilename
# If you call mv without the second parameter it will prompt you to edit the filename on command line.
# Original mv is called when it's called with more than one argument.
# It's useful when you want to change just a few letters in a long name.
# Also see:
# - imv from renameutils
# - Ctrl-W Ctrl-Y Ctrl-Y (cut last word, paste, paste)
premek / dmx.ino
Created January 22, 2019 22:37
#include <SoftwareSerial.h>
#include "DMXUSB.h"
#include <FastLED.h>
SoftwareSerial mySerial(10, 11); // RX, TX
#define DMXUSB_BAUDRATE 115200
#define NUM_LEDS 16
premek /
Created December 1, 2018 17:29
A script to read SMSes via kdeconnect DBUS interface
#!/usr/bin/env bash
DEV=`dbus-send --print-reply --dest=org.kde.kdeconnectd /modules/kdeconnect/devices org.freedesktop.DBus.Introspectable.Introspect | sed -n 's/.*node name="\(.*\)".*/\1/p'`
DATE=`date +'%d-%m-%Y'`
SMS="`dbus-send --print-reply --dest=org.kde.kdeconnectd /modules/kdeconnect/devices/$DEV org.kde.kdeconnect.device.conversations.activeConversations | grep -A3 "Operace ze dne $DATE" | sed 's/.*string "\|"$//'`"
echo $SMS
CODE=`echo $SMS | sed -ne 's/.* \([0-9]\{5,\}\) .*/\1/gp'`
#!/usr/bin/env bash
# translates any selection and displays the result in a notification.
# Install:
# - sudo apt install libnotify-bin xsel jq
# - you can copy this file to ~/bin, /usr/local/bin or somewhere and make it executable
# - configure a hotkey to execute it. You can use xbindkeys or your DE settings
in=$(xsel -o | sed "s/[\"'<>]//g")
notify-send --icon=info "$in" "$(wget -U "Mozilla/5.0" -qO - "$in" |jq -r '.[0][0:]|.[]|.[1]')"
Outer window is 0x2800001, inner window is 0x2800002
ButtonPress event, serial 25, synthetic NO, window 0x2800001,
root 0xdf, subw 0x0, time 1502519276, (82,51), root:(884,310),
state 0x0, button 8, same_screen YES
ButtonRelease event, serial 25, synthetic NO, window 0x2800001,
root 0xdf, subw 0x0, time 1502519424, (82,51), root:(884,310),
state 0x0, button 8, same_screen YES
mpv -ao none -fullscreen -loop 0
local lpeg = require "lpeg"
local S,C,Ct,Cc,Cg,Cb,Cf,Cmt,P,V =
lpeg.S, lpeg.C, lpeg.Ct, lpeg.Cc, lpeg.Cg, lpeg.Cb, lpeg.Cf, lpeg.Cmt,
lpeg.P, lpeg.V
local eof = -1
local sp = S" \t" ^0 + eof
local wh = S" \t\r\n" ^0 + eof