Skip to content

Instantly share code, notes, and snippets.

@putnamhill
putnamhill / bash-snippets.md
Last active March 8, 2024 14:17
bash snippets - these are notes for myself; some found and some I've made

git

get the last commit hash in abbreviated form

 git log -n1 --pretty=format:%h

list files in another branch

git ls-files --with-tree=another-branch
@putnamhill
putnamhill / bgrep.sh
Created May 11, 2012 16:06
binary grep
#!/bin/bash
usage() {
cat <<EOT
Usage: ${0##*/} [-l] [-h] pattern [arg2] ...
Prints lines containing a BRE pattern, after stripping binary data.
Sort of like strings command followed by grep, only better.
If no file paths are specified after the pattern, paths are
read from stdin (tip: feed with find).
Options:
@putnamhill
putnamhill / lingo-shell-xtra-snippets.ls
Last active October 5, 2015 08:58
mac shell xtra snippets
on listReadOnlyVolumes
return shell_cmd_list("mount | sed -n 's/^\/dev\/.* on \(\/.*\) (.*read-only.*/\1/p'")
end
on nonEmptyFolderExists atPosixPath
rslt = shell_cmd_list("ls " &qq(atPosixPath) &" 2>/dev/null")
return count(rslt) > 0
end
on directoryExists atPosixPath
@putnamhill
putnamhill / dir-vers.pl
Created June 13, 2012 04:03
This script prints the version of adobe director used to create a file. Now detects director file versions 6, 7, 8, 8.5 (or 9.0), 10.1, 11.5.0r593, 11.5.8.612, and 12.
#!/usr/bin/perl -w
use constant IFFTYPES => qw( RIFX XFIR );
use constant DIRTYPES => qw( MV93 39VM MC95 );
use constant {
INT_SIZE => 4,
VERSION_OFFSET => 40
};
use Getopt::Long;
#use diagnostics;
@putnamhill
putnamhill / genUID.sh
Last active October 8, 2015 08:38
A bash version of the genUID.app CLSID generator for Adobe Director MOA classes.
#!/bin/bash
# genUID.sh - A bash version of the genUID.app CLSID generator for Adobe Director MOA classes.
openssl rand -hex 16 | awk '{
printf "DEFINE_GUID(CLSID(CRegister), 0x%sL, 0x%s, 0x%s, 0x%s, 0x%s, 0x%s, 0x%s, 0x%s, 0x%s, 0x%s, 0x%s);\n",
substr($0, 1, 8), substr($0, 9, 4), substr($0, 13, 4), substr($0, 17, 2),
substr($0, 19, 2), substr($0, 21, 2), substr($0, 23, 2), substr($0, 25, 2),
substr($0, 27, 2), substr($0, 29, 2), substr($0, 31, 2)
}' | \
@putnamhill
putnamhill / notifymail.sh
Created November 1, 2012 14:03
an email notifier that listens for finger connections from the mail server
#/bin/bash
# usage:
# sudo nohup notifymail 2>&1 >/dev/null
# to see if it is already running
# ps ax | egrep ' (sh /Users/colet/bin/[n]otifymail)|([n]c -l 79)$'
[ $(whoami) != 'root' ] && echo must be root && exit
# first clean up any old related processes
@putnamhill
putnamhill / win2003-ntp.txt
Last active December 16, 2015 20:19
Configuring ntp on Windows 2003 using the command prompt. Use stratum two servers if possible: https://support.ntp.org/bin/view/Servers/StratumTwoTimeServers?redirectedfrom=Servers.StratumTwo
net stop w32time
w32tm /unregister
w32tm /register
net time /setsntp:"tick.example.com,0x1 tock.example.com,0x1"
net start w32time
@putnamhill
putnamhill / smtp-test
Last active December 18, 2015 12:19
smtp commands to test email between two servers via telnet
telnet smtp.example.com 25
Trying 203.0.113.1...
Connected to smtp.example.com.
Escape character is '^]'.
220 example.com running My Bitchin Mail Server 1.0.0
HELO example.org
250 example.com hello example.org (198.51.100.1)
MAIL FROM:<postmaster@example.org>
250 2.1.5 sender OK
RCPT TO:<someone@example.com>
@putnamhill
putnamhill / mysql-notes
Last active September 29, 2016 11:45
Creating a new user with the mysql client and set some privileges for all the tables of a database.
CREATE USER 'someuser'@'localhost' IDENTIFIED BY 'cleartext-password';
GRANT SELECT,INSERT,UPDATE,DELETE ON `database`.* TO 'someuser'@'localhost';
@putnamhill
putnamhill / stop-watch.sh
Created July 31, 2013 20:04
A simple bash stop watch.
#!/bin/bash
START=$(date +%s)
read -s -n1 -p $'Press a key when done.\n'
ELAPSED_SECONDS=$(bc <<< "scale=10; ($(date +%s) - $START)")
if [ $ELAPSED_SECONDS -gt 60 ]; then
ELAPSED_MINUTES=$((ELAPSED_SECONDS / 60))
ELAPSED_SECONDS=$((ELAPSED_SECONDS - ELAPSED_MINUTES * 60))
echo -n "$ELAPSED_MINUTES minutes "
fi