Skip to content

Instantly share code, notes, and snippets.

@swarminglogic
swarminglogic / git-root
Last active June 14, 2019 08:44
git-root: finds git root directory without using git executable (POSIX compliant shell script)
#!/bin/sh
#$1: Path to child directory
git_root_recurse_parent() {
# Check if cwd is a git root directory
if [ -d .git/objects -a -d .git/refs -a -f .git/HEAD ] ; then
pwd
return 0
fi
@swarminglogic
swarminglogic / SmartObjectPool.h
Last active June 26, 2022 14:18
SmartObjectPool: A RAII-style implementation of the object pool pattern that uses smart pointers to automatically return acquired objects to the pool when deleted.
#include <memory>
#include <stack>
#include <stdexcept>
template <class T, class D = std::default_delete<T>>
class SmartObjectPool
{
private:
struct ReturnToPool_Deleter {
explicit ReturnToPool_Deleter(std::weak_ptr<SmartObjectPool<T, D>* > pool)
@swarminglogic
swarminglogic / info-mode.el
Last active November 18, 2015 08:22
emacs major mode for Boost PropertyTree INFO file format and parser
;;; info-mode-el -- Major mode for editing INFO files
;; Author: Roald Fernandez <[email protected]>
;; Created: 10 Nov 2014
;; Keywords: INFO major-mode
;; Copyright (C) 2014 Roald Fernandez <[email protected]>
;; This program is free software; you can redistribute it and/or
;; modify it under the terms of the GNU General Public License as
@swarminglogic
swarminglogic / vlcopen.sh
Last active December 13, 2018 22:25
Download video URL (youtube-dl supported), and automatically open with VLC as soon as possible. Assign to global hotkey for easy use: (1. Copy URL. 2. Hit hotkey shortcut. 3. Wait a few seconds. 4. Enjoy in VLC)
#!/bin/bash
if [ $# -eq 1 ] ; then
path=$1
else
clipboard=$(xclip -selection clipboard -o)
if [ $(<<<$clipboard grep -P "^http") ] ; then
path=$clipboard
else
if [ -t 1 ] ; then
@swarminglogic
swarminglogic / pngopt.sh
Last active August 29, 2015 14:06
pngopt: A wrapper for pngcrush, that makes it easier to use for overriding images with its optimized output (e.g ./pngopt filea.png fileb.png filec.png). If a file is optimized it outputs the filename with percentage reduction.
#!/bin/bash
# pngopt: A wrapper for pngcrush, that makes it easier to use for overriding
# images with its optimized output.
#
# use: pngopt FILE1 [FILE2] [FILE3] ...
#
# If a file is optimized it outputs the filename with percentage reduction.
#
#
@swarminglogic
swarminglogic / subtlemark.sh
Last active December 1, 2015 21:53
Subtlemark: Tool for adding subtle watermarks to images. Parameter customization: position (TL,TC,TR,BL,BC,BR), font, font-size, caption, textcolor, bgcolor. Also supports predefined styles.
#!/bin/bash
version=0.1.4
versionDate="2014-09-02"
function showHelp() {
echo "subtlemark - add subtle watermarks to images
Usage:
----------------------------------------
@swarminglogic
swarminglogic / enterpass.sh
Last active May 9, 2016 15:55
Fills out username/password. Triggered by global hotkey. Application agnostic. Determines best user/pass match from process information. Requiers userpass.sh (https://gist.github.com/swarminglogic/40922ce92e49aae3b2ca)
#!/bin/bash
# Use this with a global hotkey to the following: gksudo [FULLPATH]/enterpass.sh
if [[ $EUID -ne 0 ]] ; then
notify-send "This script must be run as root"
exit
fi
if ! command -v userpass > /dev/null ; then
@swarminglogic
swarminglogic / userpass.sh
Last active December 1, 2015 21:52
Command-line utility to manage passwords, protected by sudo
#!/bin/bash
file=/home/$SUDO_USER/.local/share/userpass.list
function showHelp {
version=0.0.2
versionDate="2014-06-24"
echo "$0 - manage passwords
@swarminglogic
swarminglogic / ttic.sh
Last active December 28, 2017 11:22
Millisecond resolution tic / toc timer pair utility for linux terminal. Supports id-based tic/toc pairs.
#!/bin/bash
function showHelp {
version=0.0.1
versionDate="2014-07-07"
echo "$0 - tic/toc timer pair
Usage: $0 [id] Stores initial time (w/optional id marker)
$0 [-u|--unique] Creates and returns unique id
@swarminglogic
swarminglogic / watchfile.sh
Last active March 4, 2024 14:44
watchfile - monitor file(s) and execute a command when files are changed
#!/bin/bash
version=1.0.1
versionDate="2014-02-14"
function showHelp() {
echo "watchfile - monitor file(s)/command and perform action when changed
Possible ways of usage
----------------------------------------