Skip to content

Instantly share code, notes, and snippets.

@jm3
Last active August 29, 2015 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jm3/21884d5d683a83443c52 to your computer and use it in GitHub Desktop.
Save jm3/21884d5d683a83443c52 to your computer and use it in GitHub Desktop.
#!/bin/sh
blob=$1
git rev-list --all |
while read commit; do
if git ls-tree -r $commit | grep -q $blob; then
echo $commit
fi
done

How to simply tag a file deployed into hostile environments with a token reversible into the mod date and git commit SHA

Sometimes you ship code to someone “in the wild” and later you need to understand which revision they’re running, e.g. during trouble-shooting or when they file a bug report. Doing this with Git is pretty easy:

1. Tell git that you’d like cvs-style ident keywords expanded on checkout for whatever file, e.g. /path/to/foo:

echo "path/to/foo ident" >> .gitattributes;
git ci .gitattributes -m "enable keyword expansion in path/to/foo"

Only do this for text files, by the way, not binaries.

2. Add the string $Id$ somewhere in /path/to/foo, like this:

# current git blob
v = '$Id$'
...

Now, for all revisions checked-out after your telling git that you want $Id$ keywords to be expanded in foo, whenever foo is checked out, git will replace the actual $Id$ in the file with the most-recent blob when foo was changed, e.g.:

# current git blob
v = '$Id: e184834e6757aac77fd0f71344934b1cd774e6d4 $'
...

Now, you can ask the remote customer to send you the value of v to get the blob version they’re running. But we’re not done yet!

3. To turn that blob’s SHA into a commit SHA (which will tell you when that file was committed, what was changed in the commit, and what other files were changed on that commit), use this script:

#!/bin/sh
 
blob=$1
 
git rev-list --all |
while read commit; do
  if git ls-tree -r $commit | grep -q $blob; then
    echo $commit
  fi
done
sudo apt-get install r-base r-base-dev
wget http://download2.rstudio.org/rstudio-server-0.95.265-amd64.deb
sudo dpkg -i rstudio-server-0.95.265-amd64.deb
sudo apt-get install libapparmor1 apparmor-utils
sudo vi /etc/apt/sources.list
append: "deb http://lib.stat.cmu.edu/R/CRAN/bin/linux/ubuntu oneiric/" (no quotes)
sudo R
install.packages("ggplot2")
# install other shit...
<ctl-d>
sudo rstudio-server restart
# done! hit http://localhost:8787
gently wall off code into a contained box. not cryptographically secure, more like a babygate.
#!/bin/sh
# chroot jail creator for OS X 10.6.8-ish. dugsong would be proud.
# by jm3@jm3.net / john manoogian III / 2013
min_version="10.8.4"
chroot_dir=$HOME/chroot
# you shouldn't need to change anything below this line:
# verify os x version:
installed_version=`sw_vers | grep ProductVersion | cut -f2`
if [ "$installed_version" = "$min_version" ]
then
echo "Creating directories, copying binaries and libs, baking donuts..."
else
echo "WARNING! This script was only tested on OS X version $min_version. Proceed with caution!"
exit 1
fi
mkdir -p $chroot_dir/bin
mkdir -p $chroot_dir/usr/lib/system
bins="[ cat chmod cp date dd df domainname echo expr hostname kill link ln ls mkdir mv pax ps pwd rm rmdir sh sleep stty test unlink"
libs=`ls -1 /usr/lib`
syslibs=`ls -1 /usr/lib/system`
for binary in $bins
do
cp /bin/$binary $chroot_dir/bin/
done
for lib in $libs
do
# don't copy through symlinks, so we don't needlessly 5-10x the
# space needed for each of the liba.so.0.dylib liba.so.so.dylib
# links
cp -R /usr/lib/$lib $chroot_dir/usr/lib/
done
# manually copy vim since it's not in /bin with the rest of the binaries we need:
cp /usr/bin/vim $chroot_dir/bin/vim
ln -s /usr/bin/vim $chroot_dir/bin/vi
# create an empty homedir
mkdir -p $chroot_dir/Users/`logname`
echo "changing chroot's ownership down to nobody:nobody"
sudo chown -R nobody:nobody $chroot_dir
echo "Success! Use your new chroot jail like this: sudo chroot $chroot_dir /bin/sh"
exit 0
# self-signed SSL cert
open https://gist.github.com/anonymous/e2e967f8ea3ef86cac1f
# compact an OS X sparse bundle disk image
hdiutil imageinfo image-file.sparsebundle
# show actual free RAM
free -h | awk '{print $3}' | head -n 3 | tail -n 1
# sort lines by length
awk '{print length, $0;}' | sort -nr
# the following seems to fuck with ruby gems in some disturbingly deep way. fucking ruby.
# -DWITH_SSL=yes \
# options for compiling mysql
# more fun @ http://dev.mysql.com/doc/refman/5.5/en/source-configuration-options.html
cmake . \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DMYSQL_DATADIR=/usr/local/mysql/data/ \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DINSTALL_LAYOUT=STANDALONE \
-DENABLED_PROFILING=ON \
-DMYSQL_MAINTAINER_MODE=OFF \
-DWITH_DEBUG=OFF \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_SSL=no \
-DMYSQL_TCP_PORT=3306
#!/bin/sh
src="/volume1/Plex/Library/Application Support/Plex Media Server"
dst="/root"
rsync -vaz \
--exclude 'Cache/' \
--exclude 'Crash Reports/' \
--exclude 'Logs/' \
--exclude 'Plug-in Support/Cache/' \
"$src" \
$dst/plex-backup-$(date +"%Y-%m-%d")
# compress a movie without handbrake or re-encoding it
ffmpeg -i input.mkv -c:v copy -c:a copy output.m4v
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment