Skip to content

Instantly share code, notes, and snippets.

@kenny-evitt
kenny-evitt / prepare-commit-msg
Created October 27, 2016 19:40
Add `git diff --cached` output as a comment to commit messages
#!/bin/bash
commit_message_file="$1"
commit_type="$2"
commit_hash="$3" # This is empty if an existing commit is not being amended
diff_cached_output=$(git diff --cached)
diff_cached_output=$(echo "$diff_cached_output" | sed 's/^/# /')
diff_cached_message="# \`git diff --cached\` output:
@kenny-evitt
kenny-evitt / Bash commands
Last active December 5, 2019 17:29
Bash commands
# Print variables
#
# From [this answer](http://unix.stackexchange.com/a/118050/56148) to the Unix & Linux SE question:
# - [How to print only defined variables (shell and/or environment variables) in bash - Unix & Linux Stack Exchange](http://unix.stackexchange.com/questions/3510/how-to-print-only-defined-variables-shell-and-or-environment-variables-in-bash)
(set -o posix; set)
# Open Vim with a new buffer containing the output of a command
@kenny-evitt
kenny-evitt / Common T-SQL fragments for Vim registers
Created September 12, 2016 14:37
For use with the ViEmu SQL Server Management Studio { add-in / add-on / extension }
-- Template block to execute a test stored procedure
-- a:
EXEC tSQLt.Run '';
--
@kenny-evitt
kenny-evitt / Common Vim regex searches
Last active October 11, 2018 14:49
Common Vim regex searches
" Git merge conflict markers
^<<<<<<<\|^=======\|^>>>>>>>
" Git merge conflict markers for ViEmu in SQL Server Management Studio
^<<<<<<<\|=======\|>>>>>>>
" "WARNING" or "ERROR"
\<WARNING\>\|\<ERROR\>
@kenny-evitt
kenny-evitt / Generate random string.bash
Last active May 30, 2021 19:05
Generate a random string, e.g. for passwords, using specific characters only, from a Unix/Linux command line shell using the *head* and *tr* programs
head /dev/urandom | tr -dc 'A-Za-z0-9!@#$%^&*()' | head -c 32 && echo
# With all of the OWASP password special characters, based on [this comment](http://unix.stackexchange.com/questions/230673/how-to-generate-a-random-string/230676#comment525492_230676) from the U&L SE question answer referenced below:
head /dev/urandom | tr -dc 'A-Za-z0-9!"#$%&'\''()*+,-./:;<=>?@[\]^_`{|}~' | head -c 32 && echo
# This was adapted from [this answer](http://unix.stackexchange.com/a/230676/56148) to the Unix & Linux Stack Exchange question [password - How to generate a random string? - Unix & Linux Stack Exchange](http://unix.stackexchange.com/questions/230673/how-to-generate-a-random-string).
# The original command:
head /dev/urandom | tr -dc A-Za-z0-9 | head -c 13
@kenny-evitt
kenny-evitt / Bash shell function
Created August 9, 2016 21:01
Bash shell function that can be defined at a command line
# Enter the following line at a Bash command prompt
stage_ours () { git checkout --ours "$1" && git add "$1"; }
# Note that the trailing `;` above is required for function definitions on a single line.
# See [Bash Reference Manual - Shell Functions](https://www.gnu.org/software/bash/manual/bash.html#Shell-Functions) for more info.
# Run the function like `stage_ours Stored\ Procedures/dbo.Batch_Detail_GL_Journal_Export_bak.sql`
@kenny-evitt
kenny-evitt / save-ours-theirs
Last active September 12, 2016 20:03
Git alias to save 'ours' and 'theirs' versions of a merge-conflicted file
# Because Git has really good Bash completion support, naming the alias `save-ours-theirs` is just as easy to type but a *lot* more readable.
# Add to Git config file, e.g. *~/.gitconfig*
# Example: `git sot Static\ Data/dbo.TABLE.sql`
[alias]
sot = "!f(){ git show :2:\"$1\" > ours && git show :3:\"$1\" > theirs; }; f"
@kenny-evitt
kenny-evitt / add-dynamic-group-var.bash
Last active August 16, 2021 11:11
Files for Ansible for supporting dynamic host variables retrieved from a local SQLite database
#!/usr/bin/env bash
group_name="$1"
var_name="$2"
var_value="$3"
./create_dynamic_vars_db.py
sqlite3 dynamic_vars.db "INSERT OR REPLACE INTO group_vars ( group_name, var_name, var_value ) VALUES ( '${group_name}', '${var_name}', '${var_value}' );"
# Find the first instance of text like "[something]" on each line in a visual selection and replace each line with "something"
'<,'>s/^\s\+\[\(\w\+\)\].\+$/\1/g
# Replace `div` tags with `p` tags
%s/<\(\/\=\)div>/<\1p>/g
# On Mac OS X, the default Vim when run from Terminal can't access the clipboard ("pasteboard"). This command will run the `pbcopy` program to copy the current visual selection:
w !pbcopy
# Generate a 32 character password by calling `pwgen`:
// Outputting HTML
Util.RawHtml(String.Format("<h2>Testing worksheet '{0}'</h2>\n", worksheetName)).Dump();