Skip to content

Instantly share code, notes, and snippets.

View ezarko's full-sized avatar

Eric Zarko ezarko

View GitHub Profile
@ezarko
ezarko / bootstrap_cfn-init.bash
Last active December 18, 2015 23:58
CloudFormation bootstraping for puppet
# 1) set up EPEL
rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
# 2) install some dependencies
yum install -y pystache python-daemon python-lockfile
# 3) install aws-cfn-bootstrap
rpm -Uvh http://yum_server.example.com/yum/noarch/aws-cfn-bootstrap-1.4-8.3.el6.noarch.rpm
# 4) run cfn-init or signal error
/opt/aws/bin/cfn-init --region <Region> -s <StackId> -r db1 || /opt/aws/bin/cfn-signal -e 1 -r 'Failed to initialize server role using cfn-init' '<WaitHandle>'
@ezarko
ezarko / list_by_size.sh
Created October 22, 2015 22:00
List out the children of a directory in descending size order
du -shx * | perl -e '%x=qw/K 1000 M 1000000 G 1000000000/;print sort {$a=~/^(\d+(?:\.\d+)?)([KMG])\s/ or die $a;my@a=($1,$2);$b=~/^(\d+(?:\.\d+)?)([KMG])\s/ or die $b;my@b=($1,$2);$b[0]*$x{$b[1]} <=> $a[0]*$x{$a[1]}} <>'
@ezarko
ezarko / get_instance_tags.pl
Created October 19, 2015 20:41
Fetch tags for an EC2 instance
#!/usr/bin/perl
use Data::Dumper;
use Digest::SHA;
use JSON;
use URI::Escape;
use XML::Simple;
use constant {
ENDPOINT => 'ec2.us-west-2.amazonaws.com',
@ezarko
ezarko / gist:01fdf47722cb6cd8873f
Last active October 1, 2015 19:51
Search static website generators
# search for Perl based projects updated in the last 3 months (as of 1/1/2015)
perl -MJSON -e '$d=decode_json scalar `curl https://staticsitegenerators.net/list.json 2> /dev/null`;print map {"$_->{name}\n"} grep {$_->{language} eq "Perl" && $_->{updated_at} =~ /^2015-0[789]/} @$d'
@ezarko
ezarko / org.gnu.mailman.plist
Created August 26, 2015 22:27
OSX /Library/LaunchDaemons/
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>org.gnu.mailman</string>
<key>LaunchOnlyOnce</key>
<true/>
<key>Program</key>
<string>/usr/local/mailman/bin/mailmanctl</string>
@ezarko
ezarko / gist:d660d9653fae7a746094
Last active March 14, 2022 16:24
Use vimdiff for git diff
# vim
echo "au! BufRead,BufNewFile /tmp/* setlocal buftype=nofile" >> ~/.vimrc
echo "au! BufRead,BufNewFile /proc/* setlocal buftype=nofile" >> ~/.vimrc
echo "syntax on" >> ~/.vimrc
echo "set laststatus=2" >> ~/.vimrc
echo "set statusline=%f\ %h%w%m%r\ %=%(%l,%c%V\ %=\ %P%)" >> ~/.vimrc
# git
git config --global pager.diff ""
git config --global diff.external "/bin/bash -c 'vimdiff -o \"\$1\" \"\$4\"'"
@ezarko
ezarko / gist:36e32ecbc07b80b8f2e1
Created March 19, 2015 19:22
Add a tag "somekey" with "somevalue" to all EC2 instances that do not have that tag
aws ec2 create-tags --resources $(perl -MJSON -e '$d=[grep{$_->{State}{Name}eq"running"&&!$_->{Tags}{somekey}}map{map{$_->{Tags}={map{($_->{Key}=>$_->{Value})}@{$_->{Tags}}};$_}@{$_->{Instances}}}@{(decode_json scalar `aws ec2 describe-instances`)->{Reservations}}];print join(" ",map{$_->{InstanceId}}@$d)') --tags Key=somekey,Value=somevalue
#!/usr/bin/perl
$_ = join "", @ARGV;
s/^(0105)000000000005([0-9A-F]{40})$/$1$2/
or die "usage: $0 <28 hex pairs>";
print join("-", "S", unpack "c2 V4", pack "H*", $_)."\n"
@ezarko
ezarko / html.pl
Created November 19, 2010 18:25
Just some interesting regular expressions
# match a div with class header_bar
/\<div(?:\s+\w+\=\"[^\"]*\")*\s+class\=\"[\w\-\s]*\bheader_bar\b/;