Skip to content

Instantly share code, notes, and snippets.

@premek
premek / mv.sh
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)
# downloads a page from gemini server
(echo "gemini://gemini.circumlunar.space/docs/"; sleep 1) | openssl s_client -connect gemini.circumlunar.space:1965
@premek
premek / scan_pdf.sh
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"
done
@premek
premek / dmx.ino
Created January 22, 2019 22:37
DMX USB, FastLED RGB LED stripe, OP-Z
#include <SoftwareSerial.h>
#include "DMXUSB.h"
#include <FastLED.h>
SoftwareSerial mySerial(10, 11); // RX, TX
#define LED_PIN LED_BUILTIN
#define DMXUSB_BAUDRATE 115200
#define NUM_LEDS 16
@premek
premek / raspberry-camera-mirror.md
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/autostart.sh &
cd
touch autostart.sh
chmod a+x autostart.sh
nano autostart.sh
@premek
premek / mbank-sms.sh
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 - "http://translate.googleapis.com/translate_a/single?client=gtx&sl=auto&tl=en&dt=t&q=$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 https://www.youtube.com/watch?v=pF-3S-HTJSg -ao none -fullscreen -loop 0
local lpeg = require "lpeg"
lpeg.locale(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