<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Garett Dunn</title>
    <description>The latest articles on DEV Community by Garett Dunn (@garettmd).</description>
    <link>https://dev.to/garettmd</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F36030%2Fda78974a-ac85-45ff-be1b-f9cfeeb37bae.jpg</url>
      <title>DEV Community: Garett Dunn</title>
      <link>https://dev.to/garettmd</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/garettmd"/>
    <language>en</language>
    <item>
      <title>AWS EC2 - Limit an Instance's Access to its Own Tags</title>
      <dc:creator>Garett Dunn</dc:creator>
      <pubDate>Thu, 20 Aug 2020 00:00:00 +0000</pubDate>
      <link>https://dev.to/garettmd/aws-ec2-limit-an-instances-access-to-its-own-tags-21pg</link>
      <guid>https://dev.to/garettmd/aws-ec2-limit-an-instances-access-to-its-own-tags-21pg</guid>
      <description>&lt;p&gt;Here’s a dynamic way to allow an EC2 instance to modify its own tags, but no other instance’s. Enjoy.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"Version"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"2012-10-17"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"Statement"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"Effect"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Allow"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"Action"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"ec2:CreateTags"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"ec2:DescribeTags"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"Resource"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"*"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"Condition"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"StringEquals"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
          &lt;/span&gt;&lt;span class="nl"&gt;"aws:ARN"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"${ec2:SourceInstanceARN}"&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
    <item>
      <title>Liberate Orphaned OpenStack Volumes</title>
      <dc:creator>Garett Dunn</dc:creator>
      <pubDate>Fri, 28 Jun 2019 19:12:52 +0000</pubDate>
      <link>https://dev.to/garettmd/liberate-orphaned-openstack-volumes-355i</link>
      <guid>https://dev.to/garettmd/liberate-orphaned-openstack-volumes-355i</guid>
      <description>&lt;p&gt;If you delete a server that a volume is attached to, and then quickly try to delete the volume before the server has finished deleting (at least, that’s where I think the problem stems from; it could just be that this happens even if you waited for it to fully delete), the volume can get stuck saying that it’s still attached. You cannot run &lt;code&gt;openstack server remove volume &amp;lt;server id&amp;gt; &amp;lt; volume id&amp;gt;&lt;/code&gt; because it will complain that the server doesn’t exist. The only way I could figure out how to get around this is to use the &lt;code&gt;cinder&lt;/code&gt; tool to remove the attachement ID&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;openstack volume show &amp;lt;volume_id&amp;gt;
&lt;span class="c"&gt;# Grab the attachment ID for use in next step&lt;/span&gt;

cinder &lt;span class="nt"&gt;--os-volume-api-version&lt;/span&gt; 3.50 attachment-delete &amp;lt;attachment_id&amp;gt;
&lt;span class="c"&gt;# For some reason you have to specify at least api version 3.50. Why it can't figure this out on it's own is beyond me&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Hopefully this will help someone out.&lt;/p&gt;

</description>
      <category>openstack</category>
    </item>
    <item>
      <title>Brewlette - Discover homebrew packages</title>
      <dc:creator>Garett Dunn</dc:creator>
      <pubDate>Tue, 11 Jun 2019 14:26:00 +0000</pubDate>
      <link>https://dev.to/garettmd/brewlette-discover-homebrew-packages-4i0d</link>
      <guid>https://dev.to/garettmd/brewlette-discover-homebrew-packages-4i0d</guid>
      <description>&lt;p&gt;I'm kind of OCD about keeping packges updated, maybe to a fault. One result of this obsession is that I run brew update every morning on my Mac. This command updates the list of packages, even ones you don't use, so after running it you're presented with a list of all sorts of packages. If I'm not in a hurry, I'll usually spot 1 or 2 packages that sound interesting, and might end up installing them. After doing this for a while, I decided that it would be cool if I could just issue a command and get a random package at will. Turns out this is actually easy to do.&lt;/p&gt;

&lt;p&gt;Without further ado, I present: brewlette!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;brewlette

Try out a random homebrew package!

flvmeta: stable 1.2.1 &lt;span class="o"&gt;(&lt;/span&gt;bottled&lt;span class="o"&gt;)&lt;/span&gt;, HEAD
Manipulate Adobe flash video files &lt;span class="o"&gt;(&lt;/span&gt;FLV&lt;span class="o"&gt;)&lt;/span&gt;
https://www.flvmeta.com/
Not installed
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/flvmeta.rb
&lt;span class="o"&gt;==&amp;gt;&lt;/span&gt; Dependencies
Build: cmake ✔
&lt;span class="o"&gt;==&amp;gt;&lt;/span&gt; Options
&lt;span class="nt"&gt;--HEAD&lt;/span&gt;
    Install HEAD version

Command &lt;span class="s2"&gt;"brew install flvmeta"&lt;/span&gt; copied to clipboard
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Really, it's just a simple shell script that I put in /usr/local/bin (where brew usually installs packages). It works by picking a random package from the list of formulas that brew caches. One little nifty addition I made is that it copies the brew commmand to install the package to your clipboard. Just ⌘+v and enjoy the new package. For now the script is on a &lt;a href="https://gist.github.com/garettmd/7731cfd71cbee6e7c891fc94072d05ab"&gt;Github gist&lt;/a&gt;. Feel free to comment/fork if you want to make a contribution. Here's the script:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#!/usr/bin/env bash&lt;/span&gt;
&lt;span class="c"&gt;# Utility to suggest a new package to try from Homebrew&lt;/span&gt;
&lt;span class="c"&gt;# Simply run and it will give you a new package to try out&lt;/span&gt;

&lt;span class="nv"&gt;files&lt;/span&gt;&lt;span class="o"&gt;=(&lt;/span&gt;/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/&lt;span class="k"&gt;*&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
&lt;span class="nv"&gt;total&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="k"&gt;${#&lt;/span&gt;&lt;span class="nv"&gt;files&lt;/span&gt;&lt;span class="p"&gt;[@]&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;
&lt;span class="nv"&gt;rando&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="k"&gt;$((&lt;/span&gt;RANDOM &lt;span class="o"&gt;%&lt;/span&gt; total&lt;span class="k"&gt;))&lt;/span&gt;
&lt;span class="nv"&gt;package&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;basename&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;files&lt;/span&gt;&lt;span class="p"&gt;[rando]&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; .rb&lt;span class="si"&gt;)&lt;/span&gt;
&lt;span class="nb"&gt;printf&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;nTry out a random homebrew package!&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;n&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;n"&lt;/span&gt;
brew info &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;package&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[[&lt;/span&gt; &lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;command&lt;/span&gt; &lt;span class="nt"&gt;-v&lt;/span&gt; pbcopy&lt;span class="si"&gt;)&lt;/span&gt; &lt;span class="o"&gt;]]&lt;/span&gt;
&lt;span class="k"&gt;then
    &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"brew install &lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;package&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; | pbcopy
    &lt;span class="nb"&gt;printf&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;nCommand &lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;brew install %s&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt; copied to clipboard&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;n"&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$package&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;span class="k"&gt;else
    &lt;/span&gt;&lt;span class="nb"&gt;printf&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;nUse &lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;brew install %s&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt; to try it out&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;n"&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$package&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;span class="k"&gt;fi&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>script</category>
      <category>homebrew</category>
    </item>
    <item>
      <title>Unset All Variables Matching a Pattern</title>
      <dc:creator>Garett Dunn</dc:creator>
      <pubDate>Tue, 02 Apr 2019 01:04:30 +0000</pubDate>
      <link>https://dev.to/garettmd/unset-all-variables-matching-a-pattern-158d</link>
      <guid>https://dev.to/garettmd/unset-all-variables-matching-a-pattern-158d</guid>
      <description>&lt;h4&gt;
  
  
  Unset all variables beginning with prefix
&lt;/h4&gt;

&lt;p&gt;When using the Openstack CLI, you typically will get a shell script that you would &lt;code&gt;source&lt;/code&gt;, which will export a bunch of variables to your session. I’ve run into the problem of switching between two different Openstack installs that were on different versions, and needed different variables. I had issues where variables from one instance were still there when trying to use another one. I could go ahead and remove them one by one, but I didn’t get into this line of work to do things by hand. Accordingly, the following example will unset all Openstack variables (all variables that begin with &lt;code&gt;OS_&lt;/code&gt;)&lt;/p&gt;

&lt;p&gt;For &lt;strong&gt;bash&lt;/strong&gt;  it’s&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Bash&lt;/span&gt;
&lt;span class="nb"&gt;unset&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="p"&gt;!OS_@&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Because it’s bash, it’s a cryptic incantation of symbols that only wizened old graybeards can explain. (that's sarcasm)&lt;/p&gt;

&lt;p&gt;For &lt;strong&gt;zsh&lt;/strong&gt;  it’s&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# zsh&lt;/span&gt;
&lt;span class="nb"&gt;unset&lt;/span&gt; &lt;span class="nt"&gt;-m&lt;/span&gt; &lt;span class="s2"&gt;"OS_*"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see, in zsh it’s much simpler. You use the &lt;code&gt;-m&lt;/code&gt; flag (I believe it stands for “match”) then use a glob match. I’m not sure if it supports regex or not, because for some reason the documentation for zsh builtins is not easy to find.&lt;/p&gt;

&lt;p&gt;Obviously, you can use this for a lot of things. I tend to use this a lot with CLI tools (Openstack, AWS, Terraform, etc). Hopefully it’s useful for you!&lt;/p&gt;

</description>
      <category>shell</category>
      <category>bash</category>
      <category>zsh</category>
    </item>
  </channel>
</rss>
