Jekyll2023-01-31T01:33:23+01:00https://gugsrs.github.io/feed.xmlGustavo SiqueiraHi! I'm a software developer working at Sebratec AB.Gustavo Siqueira[email protected]Sharing dotfiles between computers2020-08-21T10:42:00+02:002020-08-21T10:42:00+02:00https://gugsrs.github.io/sharing-dotfiles-between-pcs<p>Some years ago while I was digging inside Github’s gigantic repositories base, I found Kenneth’s dotfiles and
at the time he did something really interesting. He put his dotfiles inside the iCloud folder, so the folder
would automatically be updated in every MacOS device connected to that iCloud account.</p>
<p>At the time I was using two macbooks(personal/work), so I was eager to try that and see how it does. So here’s
what I did to manage that setup.</p>
<h5 id="link-dotfiles-folder-to-icloud">Link dotfiles folder to iCloud</h5>
<p>First we have to create a symbolic link between the dotfiles folder and the iCloud folder.</p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">ln</span> <span class="nt">-S</span> ~/dotfiles <span class="s1">'~/Library/Mobile Documents/com~apple~CloudDocs'</span>
</code></pre></div></div>
<p>Now the dotfiles will begin to upload and be shared with every computer using the same iCloud account. But now
how to keep every config always updated? Every alias setted? It’s simple, we just have to add some more symbolic
links and then we’ll be all set.</p>
<h5 id="create-the-config-files-symbolic-links">Create the config files symbolic links</h5>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">ln</span> <span class="nt">-S</span> ~/dotfiles/my.conf ~/path/to/conf/.my.conf
<span class="c"># do this for every config you use(zsh, bash, envs, vim, git...)</span>
</code></pre></div></div>
<p>After these steps you shall have your configs properly setted, and after changing some config in one of the
computers it will automatically update the other ones.</p>
<p>Hope this can be helpfull and maybe give some insights in how we can automate small things to improve our productivity
or just for the fun of it, you can also find my dotfiles <a href="https://github.com/gugsrs/dotfiles">here</a>.</p>Gustavo Siqueira[email protected]Some years ago while I was digging inside Github’s gigantic repositories base, I found Kenneth’s dotfiles and at the time he did something really interesting. He put his dotfiles inside the iCloud folder, so the folder would automatically be updated in every MacOS device connected to that iCloud account.Tmux Spotify Plugin2020-08-19T16:40:00+02:002020-08-19T16:40:00+02:00https://gugsrs.github.io/tmux-spotify-mac<p>It’s been about 5 years since I’ve started to use Tmux and I really recommend it to everyone, it’s been a great addition to my set of tools, and it does an amazing job.
I’ll not focus this post on tmux itself, but on how I managed to create a plugin to show my spotify track info in it.</p>
<p>A while back I was searching a way to tweak my tmux status bar for it to show the spotify info, and since I used Mac I discover that the easiest way to do that would be using osascript(AppleScript).
So I endup with something like this:</p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c">#!/usr/bin/env osascript</span>
tell application <span class="s2">"Spotify"</span>
<span class="k">if </span>it is running <span class="k">then
if </span>player state is playing <span class="k">then
</span><span class="nb">set </span>track_name to name of current track
<span class="nb">set </span>artist_name to artist of current track
artist_name & <span class="s2">" - "</span> & track_name
end <span class="k">if
</span>end <span class="k">if
</span>end tell
</code></pre></div></div>
<p>As use can see it’s a simple Apple Script code that tells the Spotify Application what it wants and prints it at the end.</p>
<h2 id="creating-the-plugin">Creating the plugin</h2>
<p>With the track info, now I could go on to the next step, that was create a plugin to set it in tmux statusbar automatically.</p>
<p>Taking a look at some projects like <a href="https://github.com/kristijanhusak/tmux-simple-git-status">tmux-simple-git-status</a>, I was able to identify how to achieve what I wanted. Since it was very similar I ended using some parts of the <code class="language-plaintext highlighter-rouge">tmux-simple-git-status</code> code.</p>
<p>I’ll breakup the plugin in three main parts:</p>
<p><strong>1. Retrieve tmux status bar value</strong></p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>tmux show-option <span class="nt">-gqv</span> <span class="s2">"status-right"</span>
</code></pre></div></div>
<p><strong>2. Replace substring with spotify info</strong></p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">${</span><span class="nv">string</span><span class="p">/</span><span class="nv">$placeholder</span><span class="p">/</span><span class="nv">$spotify_info</span><span class="k">}</span>
</code></pre></div></div>
<p><code class="language-plaintext highlighter-rouge">string</code>: tmux status-right value.<br />
<code class="language-plaintext highlighter-rouge">placelholder</code>: value setted in <code class="language-plaintext highlighter-rouge">.tmux.conf</code> to be setted with the script automatically.<br />
<code class="language-plaintext highlighter-rouge">spotify_info</code>: spotify track info retrieved with osascript.<br /></p>
<p><strong>3. Set tmux new status bar value</strong></p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>tmux set-option <span class="nt">-gq</span> <span class="s2">"status-right"</span> <span class="s2">"</span><span class="nv">$value</span><span class="s2">"</span>
</code></pre></div></div>
<p><code class="language-plaintext highlighter-rouge">value</code>: string generated in step 2 to be setted as new value for the status bar.<br /></p>
<h2 id="final-result">Final Result</h2>
<figure>
<img src="/assets/tmux-spotify-mac.png" alt="Terminal screenshot" />
<figcaption>Fig 1. Spotify info in tmux status bar.</figcaption>
</figure>
<p>With this three steps I was able to succeed in creating the plugin, and now in a very easy way it is possible to show the user’s spotify info on tmux, unfortnatelly it’s only for MacOS by now.</p>
<p>If you are interested in this project you can find it here: <a href="https://github.com/gugsrs/tmux-spotify-mac"><code class="language-plaintext highlighter-rouge">gugsrs/tmux-spotify-mac</code></a></p>Gustavo Siqueira[email protected]It’s been about 5 years since I’ve started to use Tmux and I really recommend it to everyone, it’s been a great addition to my set of tools, and it does an amazing job. I’ll not focus this post on tmux itself, but on how I managed to create a plugin to show my spotify track info in it.Using localstack to test SQS and SNS locally2017-10-22T17:27:00+02:002017-10-22T17:27:00+02:00https://gugsrs.github.io/localstack-sqs-sns<h2 id="summary">Summary:</h2>
<p>Sometimes it’s hard to test locally a microservice architecture with messages flying around.
I’ve found some alternatives to that, <a href="https://github.com/p4tin/goaws">GoAWS</a> and <a href="https://github.com/localstack/localstack">Localstack</a>, and in this post I’ll cover how I manage to run localstack to mock my infrastructure.</p>
<h2 id="setup">Setup:</h2>
<p>Before going into action, make sure you have installed python (I’m currently using Python 3.6.1), pip and aws-cli.</p>
<p>To set up localstack it’s pretty easy:</p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>pip <span class="nb">install </span>localstack
</code></pre></div></div>
<p>Before we start make sure you have set fake aws credentials to not mess with production enviroment.</p>
<p>~/.aws/credentials</p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nv">AWS_ACCESS_KEY_ID</span><span class="o">=</span>foo
<span class="nv">AWS_SECRET_ACCESS_KEY</span><span class="o">=</span>bar
</code></pre></div></div>
<h2 id="starting-localstack">Starting Localstack:</h2>
<p>Since localstack mocks all kind of services from aws, it’s possible to choose which one we would like to run.</p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nv">$ </span><span class="nb">export </span><span class="nv">SERVICES</span><span class="o">=</span>sqs,sns
</code></pre></div></div>
<p>To start localstack just :</p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nv">$ </span>localstack start
</code></pre></div></div>
<p>It’s possible to use with docker too:</p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nv">$ </span>localstack start <span class="nt">--docker</span>
</code></pre></div></div>
<h2 id="using-aws-cli">Using aws-cli:</h2>
<h3 id="create-topic">Create Topic:</h3>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nv">$ </span>aws <span class="nt">--endpoint-url</span><span class="o">=</span>http://localhost:4575 sns create-topic <span class="nt">--name</span> my_topic
</code></pre></div></div>
<h3 id="list-topic">List Topic:</h3>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nv">$ </span>aws <span class="nt">--endpoint-url</span><span class="o">=</span>http://localhost:4575 sns list-topics
</code></pre></div></div>
<h3 id="create-queue">Create Queue:</h3>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nv">$ </span>aws <span class="nt">--endpoint-url</span><span class="o">=</span>http://localhost:4576 sqs create-queue <span class="nt">--queue-name</span> my_queue
</code></pre></div></div>
<h3 id="list-queue">List Queue:</h3>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nv">$ </span>aws <span class="nt">--endpoint-url</span><span class="o">=</span>http://localhost:4576 sqs list-queues
</code></pre></div></div>
<h3 id="subscribe-queue-to-topic">Subscribe Queue to Topic:</h3>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nv">$ </span>aws <span class="nt">--endpoint-url</span><span class="o">=</span>http://localhost:4575 sns subscribe <span class="nt">--topic-arn</span> arn:aws:sns:us-east-1:123456789012:my_topic <span class="nt">--protocol</span> sqs <span class="nt">--notification-endpoint</span> arn:aws:sns:us-east-1:123456789012:my_queue
</code></pre></div></div>
<h3 id="list-subscriptions">List subscriptions:</h3>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nv">$ </span>aws <span class="nt">--endpoint-url</span><span class="o">=</span>http://localhost:4575 sns list-subscriptions
</code></pre></div></div>
<p>After creating our infra we need to start sending messages so that our service can receive and use them.
For that we are going to publish the message to the topic as followed:</p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nv">$ </span>aws <span class="nt">--endpoint-url</span><span class="o">=</span>http://localhost:4575 sns publish <span class="nt">--topic-arn</span> arn:aws:sns:us-east-1:123456789012:my_topic <span class="nt">--message</span> <span class="s2">"Hi"</span>
</code></pre></div></div>
<p>If you want it’s possible to send the content of a file too:</p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nv">$ </span>aws <span class="nt">--endpoint-url</span><span class="o">=</span>http://localhost:4575 sns publish <span class="nt">--topic-arn</span> arn:aws:sns:us-east-1:123456789012:my_topic <span class="nt">--message</span> file://file.json
</code></pre></div></div>
<h2 id="creating-topics-and-queues-automatically">Creating Topics and Queues automatically:</h2>
<p>Since it’s a lot of hardwork to create all of those queues and topics by hand, and Localstack does not have an option to start with a config file(GoAws let you use a .yaml to set things up), I’ve managed to create a <a href="https://gist.github.com/gugsrs/20d90e1f21792a67eb6d27c445aa7a1f">Python script</a> to create them from a .yaml file. You can see the example from the config file <a href="https://github.com/p4tin/goaws/blob/master/app/conf/goaws.yaml">here</a>.</p>
<p>And then just:</p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nv">$ </span>./create_sqs_sns.py my-queues-and-topics.yaml
</code></pre></div></div>gugsrsSummary: