Skip to content

Instantly share code, notes, and snippets.

@swarminglogic
swarminglogic / git-root
Last active Jun 14, 2019
git-root: finds git root directory without using git executable (POSIX compliant shell script)
View git-root
#!/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 Aug 14, 2018
SmartObjectPool: A RAII-style implementation of the object pool pattern that uses smart pointers to automatically return acquired objects to the pool when deleted.
View SmartObjectPool.h
#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 Nov 18, 2015
emacs major mode for Boost PropertyTree INFO file format and parser
View info-mode.el
;;; info-mode-el -- Major mode for editing INFO files
;; Author: Roald Fernandez <contact@swarminglogic.com>
;; Created: 10 Nov 2014
;; Keywords: INFO major-mode
;; Copyright (C) 2014 Roald Fernandez <contact@swarminglogic.com>
;; 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 Dec 13, 2018
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)
View vlcopen.sh
#!/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 Aug 29, 2015
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.
View pngopt.sh
#!/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 Dec 1, 2015
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.
View subtlemark.sh
#!/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
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)
View enterpass.sh
#!/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 Dec 1, 2015
Command-line utility to manage passwords, protected by sudo
View userpass.sh
#!/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 Dec 28, 2017
Millisecond resolution tic / toc timer pair utility for linux terminal. Supports id-based tic/toc pairs.
View ttic.sh
#!/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 Jan 21, 2021
watchfile - monitor file(s) and execute a command when files are changed
View watchfile.sh
#!/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
----------------------------------------