<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://bridgetownrb.com/" version="1.2.0">Bridgetown</generator><link href="https://andrewmcodes.dev/feed/snippets.xml" rel="self" type="application/atom+xml" /><link href="https://andrewmcodes.dev/" rel="alternate" type="text/html" /><updated>2023-02-28T21:54:46-07:00</updated><id>https://andrewmcodes.dev/feed/snippets.xml</id><title type="html">Andrew Mason | Snippets</title><subtitle>Andrew Mason is a senior full stack software engineer, content creator, and Rubyist. Currently a senior product developer at Podia based in Phoenix, Arizona.</subtitle><author><name>Andrew Mason</name></author><entry><title type="html">Kill Process Running on a Specfic Port</title><link href="https://andrewmcodes.dev/snippets/kill-process-on-port/" rel="alternate" type="text/html" title="Kill Process Running on a Specfic Port" /><published>2023-01-01T20:23:33-07:00</published><updated>2023-01-01T20:23:33-07:00</updated><id>repo://posts.collection/_posts/snippets/kill-process-on-port.md</id><content type="html" xml:base="https://andrewmcodes.dev/snippets/kill-process-on-port/">&lt;p&gt;I often have to kill proccesses that weren’t stopped correctly on different ports and can never remember the command.&lt;/p&gt;

&lt;h2 id=&quot;snippet&quot;&gt;Snippet&lt;/h2&gt;

&lt;pre&gt;&lt;code class=&quot;language-sh&quot;&gt;kill -9 $(lsof -ti tcp:4000)
&lt;/code&gt;&lt;/pre&gt;

&lt;h2 id=&quot;usage&quot;&gt;Usage&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Replace &lt;code&gt;4000&lt;/code&gt; in the script above with the port you want to kill the process on.&lt;/li&gt;
  &lt;li&gt;Run the script in your terminal.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;extending&quot;&gt;Extending&lt;/h2&gt;

&lt;p&gt;We can extract this into a function to make it easier to use.&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;language-sh&quot;&gt;terminate() {
  local port=$1
  local pid=$(lsof -ti tcp:$port)
  if [ -n &quot;$pid&quot; ]; then
    kill $pid
    echo &quot;Killed process $pid on port $port&quot;
  else
    echo &quot;No process found on port $port&quot;
  fi
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Then we can use it like this:&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;language-sh&quot;&gt;terminate 4000
&lt;/code&gt;&lt;/pre&gt;</content><author><name>Andrew Mason</name></author><category term="snippets" /><category term="unix" /><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://og.andrewmcodes.dev/api/page?title=Kill+Process+Running+on+a+Specfic+Port" /><media:content medium="image" url="https://og.andrewmcodes.dev/api/page?title=Kill+Process+Running+on+a+Specfic+Port" xmlns:media="http://search.yahoo.com/mrss/" /></entry><entry><title type="html">Create Repository from Current Directory with the GitHub CLI</title><link href="https://andrewmcodes.dev/snippets/gh-create-repo/" rel="alternate" type="text/html" title="Create Repository from Current Directory with the GitHub CLI" /><published>2022-03-30T01:00:00-07:00</published><updated>2022-03-30T01:00:00-07:00</updated><id>repo://posts.collection/_posts/snippets/gh-create-repo.md</id><content type="html" xml:base="https://andrewmcodes.dev/snippets/gh-create-repo/">&lt;div class=&quot;not-prose &quot;&gt;
  &lt;div x-data=&quot;{ copied: false }&quot; class=&quot;flex flex-nowrap items-center text-sm&quot;&gt;
    &lt;span class=&quot;py-1 px-1 rounded-l-md text-radix-slate12 bg-radix-slate3 &quot;&gt;
      $&amp;nbsp;
    &lt;/span&gt;
    &lt;code class=&quot;py-1 px-2 font-mono bg-radix-slate3&quot;&gt;
      gh repo create your-repo --public --source=. --push
    &lt;/code&gt;
    &lt;button class=&quot;
        py-1
        px-2
        text-sm
        font-medium
        blue-bg-int
        text-radix-blue11
        rounded-r-md
        focus:outline-none
      &quot; x-on:click=&quot;navigator.clipboard.writeText($event.target.previousElementSibling.innerText); copied = true; setTimeout(() =&amp;gt; { copied = false; }, 1000)&quot;&gt;
      &lt;template x-if=&quot;!copied&quot;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/template&gt;
      &lt;template x-if=&quot;copied&quot;&gt;
        &lt;span&gt;Copied!&lt;/span&gt;
      &lt;/template&gt;
    &lt;/button&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;usage&quot;&gt;Usage&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Make sure you have the GitHub CLI installed and you are signed in&lt;/li&gt;
  &lt;li&gt;Run the command above to create a public repo from the current directory and push&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;resources&quot;&gt;Resources&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://cli.github.com/&quot;&gt;GitHub CLI Documentation&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</content><author><name>Andrew Mason</name></author><category term="snippets" /><category term="gh" /><category term="github" /><category term="cli" /><category term="terminal" /><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://og.andrewmcodes.dev/api/page?title=Create+Repository+from+Current+Directory+with+the+GitHub+CLI" /><media:content medium="image" url="https://og.andrewmcodes.dev/api/page?title=Create+Repository+from+Current+Directory+with+the+GitHub+CLI" xmlns:media="http://search.yahoo.com/mrss/" /></entry><entry><title type="html">Enable Repeating Keys in VS Code on macOS</title><link href="https://andrewmcodes.dev/snippets/vscode-enable-repeating-keys-macos/" rel="alternate" type="text/html" title="Enable Repeating Keys in VS Code on macOS" /><published>2022-02-27T00:37:44-07:00</published><updated>2022-02-27T00:37:00-07:00</updated><id>repo://posts.collection/_posts/snippets/vscode-enable-repeating-keys-macos.md</id><content type="html" xml:base="https://andrewmcodes.dev/snippets/vscode-enable-repeating-keys-macos/">&lt;pre&gt;&lt;code class=&quot;language-sh&quot;&gt;# VS Code
defaults write com.microsoft.VSCode ApplePressAndHoldEnabled -bool false

# VS Code - Insiders
defaults write com.microsoft.VSCodeInsiders ApplePressAndHoldEnabled -bool false
&lt;/code&gt;&lt;/pre&gt;

&lt;h2 id=&quot;usage&quot;&gt;Usage&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Run the first command above to enable repeating keys in VS Code&lt;/li&gt;
  &lt;li&gt;If you use VS Code Insiders, run the second command as well&lt;/li&gt;
  &lt;li&gt;You may need to restart VS Code, but repeating keys should now be enabled&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;resources&quot;&gt;Resources&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://code.visualstudio.com/insiders/&quot;&gt;Visual Studio Code Insiders Documentation&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</content><author><name>Andrew Mason</name></author><category term="snippets" /><category term="mac-defaults" /><category term="macos" /><category term="vim" /><category term="vs-code" /><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://og.andrewmcodes.dev/api/page?title=Enable+Repeating+Keys+in+VS+Code+on+macOS" /><media:content medium="image" url="https://og.andrewmcodes.dev/api/page?title=Enable+Repeating+Keys+in+VS+Code+on+macOS" xmlns:media="http://search.yahoo.com/mrss/" /></entry><entry><title type="html">Install Brew on a M1 Mac</title><link href="https://andrewmcodes.dev/snippets/brew-install-m1-mac/" rel="alternate" type="text/html" title="Install Brew on a M1 Mac" /><published>2022-02-25T19:02:01-07:00</published><updated>2022-04-02T16:18:00-07:00</updated><id>repo://posts.collection/_posts/snippets/brew-install-m1-mac.md</id><content type="html" xml:base="https://andrewmcodes.dev/snippets/brew-install-m1-mac/">&lt;pre&gt;&lt;code class=&quot;language-sh&quot;&gt;/bin/bash -c &quot;$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)&quot;
echo 'eval &quot;$(/opt/homebrew/bin/brew shellenv)&quot;' &amp;gt;&amp;gt; ~/.zprofile
eval &quot;$(/opt/homebrew/bin/brew shellenv)&quot;
&lt;/code&gt;&lt;/pre&gt;

&lt;h2 id=&quot;usage&quot;&gt;Usage&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Run &lt;code&gt;uname -m&lt;/code&gt; in the Terminal of your choice and verify it outputs &lt;code&gt;arm64&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;Run the command above&lt;/li&gt;
  &lt;li&gt;If you have not installed the Xcode Command Line Tools, brew will automatically install them for you&lt;/li&gt;
  &lt;li&gt;After the installation completes, run &lt;code&gt;brew doctor&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;If the output of &lt;code&gt;brew doctor&lt;/code&gt; is &lt;code&gt;Your system is ready to brew.&lt;/code&gt;, you are done&lt;/li&gt;
  &lt;li&gt;If &lt;code&gt;brew doctor&lt;/code&gt; returns issues, resolve them according to the provided instructions&lt;/li&gt;
  &lt;li&gt;You may want to set up Homebrew’s shell-completion at this time&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;resources&quot;&gt;Resources&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;If you are not using the M1 chip, &lt;a href=&quot;/snippets/brew-install-intel-mac/&quot;&gt;use this snippet instead&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://docs.brew.sh&quot;&gt;Homebrew Documentation&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://docs.brew.sh/Shell-Completion#configuring-completions-in-zsh&quot;&gt;Homebrew Documentation: Configuring Completions in zsh&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</content><author><name>Andrew Mason</name></author><category term="snippets" /><category term="install" /><category term="macos" /><category term="m1" /><category term="brew" /><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://og.andrewmcodes.dev/api/page?title=Install+Brew+on+a+M1+Mac" /><media:content medium="image" url="https://og.andrewmcodes.dev/api/page?title=Install+Brew+on+a+M1+Mac" xmlns:media="http://search.yahoo.com/mrss/" /></entry><entry><title type="html">Install Brew on an Intel Mac</title><link href="https://andrewmcodes.dev/snippets/brew-install-intel-mac/" rel="alternate" type="text/html" title="Install Brew on an Intel Mac" /><published>2022-02-25T19:02:01-07:00</published><updated>2022-04-02T16:18:00-07:00</updated><id>repo://posts.collection/_posts/snippets/brew-install-intel-mac.md</id><content type="html" xml:base="https://andrewmcodes.dev/snippets/brew-install-intel-mac/">&lt;pre&gt;&lt;code class=&quot;language-sh&quot;&gt;/bin/bash -c &quot;$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)&quot;
echo 'export PATH=&quot;/usr/local/sbin:$PATH&quot;' &amp;gt;&amp;gt; ~/.zshrc
source ~/.zshrc
&lt;/code&gt;&lt;/pre&gt;

&lt;h2 id=&quot;usage&quot;&gt;Usage&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Run the command above in your terminal application of choice&lt;/li&gt;
  &lt;li&gt;If you have not installed the Xcode Command Line Tools, brew will automatically install them for you&lt;/li&gt;
  &lt;li&gt;After the installation completes, run &lt;code&gt;brew doctor&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;If the output of &lt;code&gt;brew doctor&lt;/code&gt; is &lt;code&gt;Your system is ready to brew.&lt;/code&gt;, you are done&lt;/li&gt;
  &lt;li&gt;If &lt;code&gt;brew doctor&lt;/code&gt; returns issues, resolve them according to the provided instructions&lt;/li&gt;
  &lt;li&gt;You may want to set up Homebrew’s shell-completion at this time&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;resources&quot;&gt;Resources&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://docs.brew.sh&quot;&gt;Homebrew Documentation&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://docs.brew.sh/Shell-Completion#configuring-completions-in-zsh&quot;&gt;Homebrew Documentation: Configuring Completions in zsh&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</content><author><name>Andrew Mason</name></author><category term="snippets" /><category term="install" /><category term="macos" /><category term="intel" /><category term="brew" /><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://og.andrewmcodes.dev/api/page?title=Install+Brew+on+an+Intel+Mac" /><media:content medium="image" url="https://og.andrewmcodes.dev/api/page?title=Install+Brew+on+an+Intel+Mac" xmlns:media="http://search.yahoo.com/mrss/" /></entry><entry><title type="html">Alfred Custom Terminal Snippet</title><link href="https://andrewmcodes.dev/snippets/alfred-custom-terminal/" rel="alternate" type="text/html" title="Alfred Custom Terminal Snippet" /><published>2022-01-13T23:49:07-07:00</published><updated>2022-02-07T19:18:35-07:00</updated><id>repo://posts.collection/_posts/snippets/alfred-custom-terminal.md</id><content type="html" xml:base="https://andrewmcodes.dev/snippets/alfred-custom-terminal/">&lt;pre&gt;&lt;code class=&quot;language-applescript&quot;&gt;on alfred_script(q)
  do shell script &quot;open -a Warp ~&quot; -- [tl! highlight]
  set appOpen to false
  set nbrOfTry to 0
  delay 0.5
  repeat
    try
      tell application &quot;System Events&quot;
        if exists (window 1 of process &quot;Warp&quot;) then
          set appOpen to true
          exit repeat
        end if
      end tell
    end try
    set nbrOfTry to nbrOfTry + 1
    if nbrOfTry = 20 then exit repeat
    delay 0.5
  end repeat
  if appOpen then tell application &quot;System Events&quot; to keystroke q &amp;amp; return
end alfred_script
&lt;/code&gt;&lt;/pre&gt;

&lt;h2 id=&quot;usage&quot;&gt;Usage&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Replace &lt;code&gt;Warp&lt;/code&gt; in the script above with the name of your terminal app, e.g., Archipelago, Fig, Warp&lt;/li&gt;
  &lt;li&gt;Open Alfred’s preferences and navigate to the Terminal preferences under “Features”&lt;/li&gt;
  &lt;li&gt;Set &lt;code&gt;Application&lt;/code&gt; to &lt;code&gt;Custom&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;In the text box that appears, paste the script&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;resources&quot;&gt;Resources&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.alfredapp.com/help/kb/access-preferences/&quot;&gt;Accessing Alfred Preferences Documentation&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.alfredapp.com/help/features/terminal/&quot;&gt;Alfred Terminal Documentation&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</content><author><name>Andrew Mason</name></author><category term="snippets" /><category term="warp" /><category term="macos" /><category term="archipelago" /><category term="alfred" /><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://og.andrewmcodes.dev/api/page?title=Alfred+Custom+Terminal+Snippet" /><media:content medium="image" url="https://og.andrewmcodes.dev/api/page?title=Alfred+Custom+Terminal+Snippet" xmlns:media="http://search.yahoo.com/mrss/" /></entry><entry><title type="html">How to Unhide Desktop Icons on macOS</title><link href="https://andrewmcodes.dev/blog/unhide-macos-desktop-icons/" rel="alternate" type="text/html" title="How to Unhide Desktop Icons on macOS" /><published>2021-06-05T11:22:38-07:00</published><updated>2022-02-07T19:18:47-07:00</updated><id>repo://posts.collection/_posts/blog/unhide-macos-desktop-icons.md</id><content type="html" xml:base="https://andrewmcodes.dev/blog/unhide-macos-desktop-icons/">&lt;p&gt;One day I realized all of the desktop icons on my 2019 MacBook Pro were missing, but still visible in Finder. I thought maybe it was a bug in Big Sur 11.4 but I eventually found the solution.&lt;/p&gt;

&lt;p&gt;There is a command to hide the icons on the desktop:&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;defaults write com.apple.finder CreateDesktop FALSE; killall Finder
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;I don’t remember running it, but by setting &lt;code&gt;CreateDesktop&lt;/code&gt; to &lt;code&gt;TRUE&lt;/code&gt; and restarting Finder, all my icons showed back up!&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;defaults write com.apple.finder CreateDesktop TRUE; killall Finder
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;To make this easier in the future, I added a function to my shell:&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;# Pass TRUE or FALSE - toggles desktop icons on and off.
function toggle_desktop_icons()
{
  if [ -z &quot;$1&quot; ]
  then
    echo &quot;You must pass 'TRUE' or 'FALSE' to this function!&quot;
    echo &quot;Try 'toggle_desktop_icons true' or 'toggle_desktop_icons false'&quot;
    echo &quot;&quot;
    echo &quot;Aborting!&quot;
    return 0
  fi

  defaults write com.apple.finder CreateDesktop $1; killall Finder
}
&lt;/code&gt;&lt;/pre&gt;

&lt;h2 id=&quot;references&quot;&gt;References&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://setapp.com/how-to/hide-icons-on-mac&quot;&gt;The Easiest Way To Hide Desktop Icons On Mac – Setapp&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</content><author><name>Andrew Mason</name></author><category term="snippets" /><category term="zsh" /><category term="macos" /><category term="alfred" /><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://og.andrewmcodes.dev/api/page?title=How+to+Unhide+Desktop+Icons+on+macOS" /><media:content medium="image" url="https://og.andrewmcodes.dev/api/page?title=How+to+Unhide+Desktop+Icons+on+macOS" xmlns:media="http://search.yahoo.com/mrss/" /></entry></feed>