Skip to content

Instantly share code, notes, and snippets.

@sullust
sullust / Bash.sublime-build
Created March 10, 2012 03:23 — forked from typeoneerror/Bash.sublime-build
Bash build system for running currently open script in Sublime Text 2
{
"cmd" : ["$file"],
"selector" : "source.shell",
"shell" : "bash"
}
@sullust
sullust / missing-amis.sh
Created August 14, 2012 06:09
EC2 Snapshots whose AMI has been deleted
echo "AMI's from snapshots which no longer exist";
echo "----------------------------------";
for i in `aws describe-snapshots | grep -o "ami-\([0-9]\|[a-z]\)\+" | sort -u`; do
if [[ -n `aws dim $i | grep requestId` ]]; then
echo "$i"; else echo "";
fi;
done;
@sullust
sullust / gist:3353530
Created August 14, 2012 22:23
pint git commit message from single commit
It's not "plumbing", but it'll do exactly what you want:
$ git log --format=%B -n 1 <commit>
If you absolutely need a "plumbing" command (not sure why that's a requirement), you can use rev-list:
$ git rev-list --format=%B --max-count=1 <commit>
Although rev-list will also print out the commit sha (on the first line) in addition to the commit message.
@sullust
sullust / gist:3354284
Created August 15, 2012 00:43
bash determine base directory of script
#!/bin/bash
BASEDIR=$(dirname $0)
echo $BASEDIR
See the EC2 documentation on the subject.
Run:
wget -q -O - http://169.254.169.254/latest/meta-data/instance-id
If you need programatic access to the instance ID from within a script,
die() { status=$1; shift; echo "FATAL: $*"; exit $status; }
EC2_INSTANCE_ID="`wget -q -O - http://169.254.169.254/latest/meta-data/instance-id || die "wget instance-id has failed: $?"`"
@sullust
sullust / rmdbc.bash
Created August 23, 2012 15:03 — forked from ttscoff/rmdbc.bash
Bash alias to recursively delete Dropbox conflicted files
alias rmdbc="find . -name *\ \(*conflicted* -exec rm {} \;" # recursively delete Dropbox conflicted files
# and/or (smart idea from Gordon Fontenot)
alias rmdbcsafe="find . -name *\ \(*conflicted* -exec mv {} ~/DropboxConflicts/ \;" # recursively move Dropbox conflicted files to temp folder
# or... via TJ Luoma
alias rmdbctrash="find . -name *\ \(*conflicted* -exec mv -v {} ~/.Trash/ \;" # recursively move Dropbox conflicted files to Trash
# More advanced idea combining ideas from @modernscientist and @GFontenot would be
# Hazel or launchd script to move conflicted files to temp folder once a day, and Hazel or launchd script to delete files older than [x]
# Or schedule TJ's idea of moving to Trash and skipping intermediate folder while still maintaining the ability to review
# hmmmm...
@sullust
sullust / gist:3453120
Created August 24, 2012 17:20
BASH combine two data sources into an array
This will do it:
Code:
#!/bin/bash
IFS='
'
xbox_name=($(curl -s http://marketplace.xbox.com/en-US/Promotion/dealoftheweek|grep -i "a class"|grep -i "title="|cut -d""" -f6))
xbox_price=($(curl -s http://marketplace.xbox.com/en-US/Promotion/dealoftheweek|grep -i "mspoints goldprice"|cut -d">" -f3|cut -d"<" -f1))
area[11]=23
area[13]=37
area[51]=UFOs
# Array members need not be consecutive or contiguous.
# Some members of the array can be left uninitialized.
# Gaps in the array are okay.
# In fact, arrays with sparse data ("sparse arrays")
Automating CPAN across a network
CPAN is an excellent tool, but the system has its limitations. One major drawback is that it's a single-system solution, which is fine if you want to manage your Perl installations on a single-computer basis. But if you have a set of Perl modules spread across your Web server farm or even across your lab on a range of platforms, trying to keep up to date across all the computers can be a time-consuming process -- even if you use the automation techniques I discussed above.
CPAN also consumes a lot of Internet bandwidth in that for each computer on which you use CPAN, CPAN expects to download a copy of the files from one of the central CPAN repositories. CPAN also relies on a configuration that has to be tailored to each computer: You can copy a configuration file, which resides in /perlinstalldirectory/CPAN/Config.pm, only if you can configure your platforms identically.
An obvious route to take when using CPAN is to use the autobundle function. This function generates a list
@sullust
sullust / SyntaxDefinition.xml
Created September 5, 2012 19:22
Coda syntax highlighting for bash
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE syntax SYSTEM "syntax.dtd">
<syntax>
<head>
<name>bash</name> <!-- The definitions title -->
<charsintokens><![CDATA[_0987654321abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ@/.]]></charsintokens> <!-- Valid Characters for Variables -->
<!-- <charsdelimitingtokens></charsdelimitingtokens> -->
</head>