Skip to content

Instantly share code, notes, and snippets.

@okhlybov
okhlybov / vintg.sh
Created April 9, 2025 10:34
Recursively scan & perform integrity check on video files
#!/bin/bash
# Recursively scan current directory for video files and check their integrity
# Output names of broken files to the standard error channel
clean() {
rm "$log"
}
trap clean INT
@okhlybov
okhlybov / keybindings.json
Last active May 11, 2021 09:41
VS Code key bindings
[
{
// Run subsequent tasks for simple task-based projects
"key": "f7",
"when": "!inCMakeProject", // Avoid interference with CMakeTools which defines F7 shortcut of its own
"command": "workbench.action.tasks.reRunTask"
},
{
// Close results panel after project compilation/run in a way similar to Sublime Text
"key": "escape",
@okhlybov
okhlybov / fpsort.rb
Created April 18, 2020 19:14
Ruby shell filter to sort space/newline delimited strings based on the floating point values extracted from the strings
#!/usr/bin/env ruby
# Scan space or newline delimited string list read from standard input for
# floating point values and sort it based on to the numbers found
def s2fp(s) ((s =~ /[-+]?[0-9]*\.?[0-9]+(e[-+]?[0-9]+)?/i).nil? ? 0 : $&).to_f end
puts ARGF.readlines.collect{|s| s.split}.flatten.sort{|a,b| s2fp(a) <=> s2fp(b)}
@okhlybov
okhlybov / untar.sh
Created April 10, 2020 12:39
Bash tarball extractor replacing symlinks with real copies for MSYS(2) environments and alike.
# Bash tarball extractor function which replaces symlinks with real copies.
# Useful for platforms which do not handle symlinks well, such as MSYS(2).
untar() {
case "$1" in
*.tar)
u=
;;
*.tar.gz|*.tgz)
u=z
;;
@okhlybov
okhlybov / dropboxfetch.sh
Last active August 26, 2019 15:30
Cron-friendly shell script to fetch changes to the Dropbox folder and make notification on detected changes
#!/bin/bash
# Cron-friendly shell script to fetch changes to the Dropbox folder and make notification on detected changes
# Uses rclone, KDE
{ rclone --verbose copy dropbox: ~/Dropbox 2>&1 | grep -e 'Transferred.*%'; } && kdialog --passivepopup 'Dropbox changes detected'
#
@okhlybov
okhlybov / CMakeLists.txt
Created August 26, 2019 15:27
CMake script template to build milti-language C/C++/Fortran executable with PkgConfig support
# CMake script template to build milti-language C/C++/Fortran executable with PkgConfig support.
# Replace ? with appropriate contents below.
# Set to the project name from which executable name will be deduced
project(?)
# Set to the space-separated list of C, C++ and Fortran sources which constitute the program
set(PROJECT_SOURCES ?)
# Set to the space-separated list of dependent PkgConfig modules
@okhlybov
okhlybov / CMakeLists.txt
Created August 26, 2019 15:26
CMake project template for incremental Vala program build
### CMake project template for building Vala program
### Makes use of the Vala support module https://github.com/nemequ/gnome-cmake/blob/master/modules/FindVala.cmake
### FindVala.cmake is expected to be put alongside this file
# Set to the project name from which executable name will be deduced
project()
# Set to the list of C, C++ and Vala sources which constitute the program
set(PROJECT_SOURCES )
@okhlybov
okhlybov / create-desktop-entry.sh
Created August 26, 2019 15:25
GNOME & friends' file manager script to create .desktop entry for arbitrary executable
#!/bin/bash
# File manager -specific file locations
#
# - GNOME3 (Nautilus): ~/.local/share/nautilus/scripts
# - Cinnamon (Nemo): ~/.local/share/nemo/scripts
# - MATE (Caja): ~/.config/caja/scripts
# Note that this file must be marked as executable with `chmod +x file_name`
@okhlybov
okhlybov / vrescue.sh
Created August 26, 2019 15:23
Script to detect and save uncorrupted video files
#!/bin/bash
# Copy uncorrupted video files found in current directory to the directory $1
IFS=$'\n'
for f in `find . -iregex '.*\(avi\|wmv\|mkv\|mp4\|mov\|mpg\|mpeg\)$'`; do
ffmpeg -xerror -i "$f" -f null - > /dev/null 2>&1
[[ $? = 0 ]] && {
echo "+ $f"
cp -p "$f" "$1"
}
done
@okhlybov
okhlybov / .bashrc
Created August 26, 2019 15:22
(ba)sh function to generate a patch between $dir and $dir.orig subdirectories found in current directory
# (ba)sh function to generate a patch between $dir and $dir.orig subdirectories found in current directory
2diff() {
orig=`find . -maxdepth 1 -type d -and \( -name '*.org' -or -name '*.orig' \) -printf '%P'`
base=`echo $orig | sed 's/\.\(org\|orig\)$//'`
LANG=C diff -urN $orig $base
}