<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Blog Posts on Shreve Labs</title><link>https://shreve.io/posts/</link><description>Recent content in Blog Posts on Shreve Labs</description><generator>Hugo</generator><language>en-us</language><atom:link href="https://shreve.io/posts/feed.xml" rel="self" type="application/rss+xml"/><item><title>Finding the current Git branch in CodeBuild</title><link>https://shreve.io/posts/finding-the-git-branch-in-codebuild/</link><pubDate>Sat, 26 Feb 2022 00:00:00 +0000</pubDate><guid>https://shreve.io/posts/finding-the-git-branch-in-codebuild/</guid><description>&lt;p>&lt;a href="#the-code">Skip to the code&lt;/a>&lt;/p>
&lt;p>I want to use the name of the current git branch in nearly every automated build
I run on CodeBuild, usually for tagging docker images. CodeBuild doesn&amp;rsquo;t make
this value available, just the commit hash it fetched.&lt;/p>
&lt;p>No problem! There&amp;rsquo;s a command that&amp;rsquo;s pretty commonly seen for grabbing the
branch name yourself:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-shell" data-lang="shell">&lt;span class="line">&lt;span class="cl">git rev-parse --abbrev-ref HEAD
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>The command &lt;code>rev-parse&lt;/code> fetches information about a revision, the parameter
&lt;code>HEAD&lt;/code> means where we are now, and the option &lt;code>--abbrev-ref&lt;/code> asks for a
non-ambiguous name for the revision in question. This typically results in the
name of the current branch.&lt;/p></description></item><item><title>Creating a generic set type in Go</title><link>https://shreve.io/posts/creating-a-generic-set-type-in-go/</link><pubDate>Wed, 11 Nov 2020 00:00:00 +0000</pubDate><guid>https://shreve.io/posts/creating-a-generic-set-type-in-go/</guid><description>&lt;p>&lt;strong>tl;dr:&lt;/strong> &lt;code>map[interface{}]struct{}&lt;/code> gives us the properties we want with a low
memory overhead. There&amp;rsquo;s a great implementation of this idea (including thread
safety) at &lt;a href="https://github.com/deckarep/golang-set">dekarep/golang-set&lt;/a>.&lt;/p>
&lt;p>First things first, if you&amp;rsquo;re not familiar, a set is a data structure that
maintains a unique collection of elements. They work similarly to other
collection types like vectors, but with a few special properties: In order to
maintain uniqueness, inserting an element that&amp;rsquo;s already in the set does
nothing, and in order to make this check reasonable to do often, the
&lt;code>Contains(el)&lt;/code> algorithm is as fast as possible. This is typically achieved by
arranging the elements in a way that they can be looked up, rather than
searching the list from start to finish, which yields a complexity of O(log n)
or even O(1) rather than O(n).&lt;/p></description></item><item><title>Obfuscating your email on the web</title><link>https://shreve.io/posts/obfuscating-your-email-on-the-web/</link><pubDate>Thu, 06 Aug 2020 00:00:00 +0000</pubDate><guid>https://shreve.io/posts/obfuscating-your-email-on-the-web/</guid><description>&lt;p>I really like having my email address publicly available on my website. Email is
a great medium for feedback or discussions about the articles I post here, and
making it accessible increases the chance readers will think to reach out with
it. The problem is, I don&amp;rsquo;t like getting email from robots, and that is an
inevitable consequence of this publicity.&lt;/p>
&lt;p>The solution to this is to not include my email address in the plaintext of the
page, but to instead dynamically provide it to the user when they ask for
it. Cloudflare has a tool for this called &lt;a href="https://support.cloudflare.com/hc/en-us/articles/200170016-What-is-Email-Address-Obfuscation-">Scrape
Shield&lt;/a>,
which hides sensitive info in the HTML of the page and injects it back in after
it&amp;rsquo;s loaded in the visitor&amp;rsquo;s browser using javascript. This prevents basic bots
from scraping one&amp;rsquo;s website for contact information. The problem with this
solution is that their scheme is easily broken, and it&amp;rsquo;s widespread use makes
breaking it valuable. I&amp;rsquo;ll show you.&lt;/p></description></item><item><title>Creating a website theme that respects user preference</title><link>https://shreve.io/posts/user-preference-respecting-website-theme/</link><pubDate>Sat, 27 Jun 2020 00:00:00 +0000</pubDate><guid>https://shreve.io/posts/user-preference-respecting-website-theme/</guid><description>&lt;p>A neat website theming option I&amp;rsquo;ve seen used more frequently lately is the use
of the &lt;code>prefers-color-scheme&lt;/code> media query. It allows the user&amp;rsquo;s browser to
specify if they want a &lt;code>light&lt;/code> or a &lt;code>dark&lt;/code> theme, or if they have
&lt;code>no-preference&lt;/code>. If the user went through the trouble of requesting a theme, you
might as well give it to them, right? Here&amp;rsquo;s what I came up with to do that.&lt;/p>
&lt;p>The starting point for this was honestly some really bad Sass written years ago,
but for the sake of explanation, let&amp;rsquo;s say it was some plain CSS with a theme
class. Everything gets some default styles, then descendents of a &lt;code>.dark-theme&lt;/code>
class get some different colors.&lt;/p></description></item><item><title>The Juice</title><link>https://shreve.io/posts/the-juice/</link><pubDate>Wed, 20 Feb 2019 00:00:00 +0000</pubDate><guid>https://shreve.io/posts/the-juice/</guid><description>&lt;p>A former coworker of mine used to talk about &amp;ldquo;the juice&amp;rdquo; and &amp;ldquo;juicing up&amp;rdquo; our
work. What he meant was making sure all our individual interests were aligned
along our work.&lt;/p>
&lt;p>Having a job means you&amp;rsquo;re getting paid and that&amp;rsquo;s at least one interest being
fulfilled, but what else could your work be doing for you? Do you enjoy working
on what you&amp;rsquo;re working on? Are you learning from it? Could you be writing open
source code which could gain you some degree of prestige? Is it helping you get
where you want to be in life?&lt;/p></description></item><item><title>IEEE-754 Floating Point Numbers</title><link>https://shreve.io/posts/ieee-754-float-point-numbers/</link><pubDate>Thu, 04 Oct 2018 00:00:00 +0000</pubDate><guid>https://shreve.io/posts/ieee-754-float-point-numbers/</guid><description>&lt;p>Many programmers are aware of floating point numbers, typically called floats, and their value for storing decimal values.
Most of them are also aware of some vague danger in using them which can cause some really bizarre-seeming results.&lt;/p>
&lt;p>For example, in Ruby,&lt;/p>
&lt;pre tabindex="0">&lt;code>0.1 + 0.2 = 0.30000000000000004
&lt;/code>&lt;/pre>&lt;p>This is due to the way we store these decimal values.&lt;/p>
&lt;p>Floats use scientific notation in binary format, meaning they use 2 as a base instead of 10.
These rounding errors occur because we can&amp;rsquo;t quite represent the exact correct answer within our limits of efficient time or memory usage.&lt;/p></description></item><item><title>Calculating current CPU usage on Linux</title><link>https://shreve.io/posts/calculating-current-cpu-usage-on-linux/</link><pubDate>Thu, 28 Sep 2017 00:00:00 +0000</pubDate><guid>https://shreve.io/posts/calculating-current-cpu-usage-on-linux/</guid><description>&lt;p>&lt;strong>tl;dr:&lt;/strong> &lt;a href="#the-code">The code&lt;/a>&lt;/p>
&lt;p>I use a tool called i3blocks to script my own status bar, which includes a CPU usage indicator.
Recently, I noticed something odd about it. The output would change for a while, but eventually
stick right around 41%. I had previously just copied this script from Stack Overflow, so I decided
it was time to dig in and learn about this in order to fix it.&lt;/p>
&lt;p>I was able to relocate the Stack Overflow question I had taken the script from:
&lt;a href="https://stackoverflow.com/questions/9229333/how-to-get-overall-cpu-usage-e-g-57-on-linux">How to get overall CPU Usage (e.g. 57%) on Linux&lt;/a>
The answer I had chosen is the highest rated, and relies on &lt;code>/proc/stat&lt;/code>.&lt;/p></description></item><item><title>A Gentle Introduction to Kubernetes</title><link>https://shreve.io/posts/a-gentle-introduction-to-kubernetes/</link><pubDate>Thu, 17 Aug 2017 00:00:00 +0000</pubDate><guid>https://shreve.io/posts/a-gentle-introduction-to-kubernetes/</guid><description>&lt;p>Manually managing servers is a pain. Setting up a server you already know the
desired configuration for feels like a huge waste of time. There are tools
available to help automate this process, like capistrano, puppet, and chef,
but they don&amp;rsquo;t solve the whole problem, and to me felt quite brittle.
There has to be A Better Way™.&lt;/p>
&lt;p>That&amp;rsquo;s where Docker and Kubernetes come in. Docker makes your application
environment portable, and Kubernetes allows you to easily reproduce and deploy
your application.&lt;/p></description></item><item><title>Hex Color Scales</title><link>https://shreve.io/posts/hex-color-scales/</link><pubDate>Sat, 15 Apr 2017 00:00:00 +0000</pubDate><guid>https://shreve.io/posts/hex-color-scales/</guid><description>&lt;p>I recently created a &lt;a href="https://github.com/shreve/dotfiles/blob/master/i3/_blocks/battery">battery
module&lt;/a> for
my i3blocks bar. For this project, I wanted the icon to have a color
representing the fullness of the battery &amp;mdash; 100% green for full, 100% red for
empty, and gradients in-between. i3blocks renders text using
&lt;a href="http://www.pango.org/">pango&lt;/a> so it supports hexadecimal colors codes via an
HTML-like markup. The desired process can be outlined as:&lt;/p>
&lt;ol>
&lt;li>Calculate the battery percentage (outside the scope of this article)&lt;/li>
&lt;li>Calculate the desired level of red, green, and blue based on that percentage&lt;/li>
&lt;li>Combine that rgb color into a hexadecimal color&lt;/li>
&lt;/ol>
&lt;h2 id="calculating-the-rgb-color">Calculating the RGB color&lt;/h2>
&lt;p>In my first attempt, I decided to try grading from 100% to 0% green, and 0% to
100% red as the battery percentage declined. This did result in the desired
bright green at full and bright red at empty, but the middle was a less
satisfying color.&lt;/p></description></item><item><title>Fixing xbacklight</title><link>https://shreve.io/posts/fixing-xbacklight/</link><pubDate>Thu, 16 Mar 2017 00:00:00 +0000</pubDate><guid>https://shreve.io/posts/fixing-xbacklight/</guid><description>&lt;p>I recently decided to upgrade from Ubuntu 16.04 LTS to 16.10. This was
unfortunate for a couple reasons: 1. The upgrade broke some dependencies
leading to &lt;code>apt&lt;/code> no longer working and 2. I made the decision at midnight on a
worknight.&lt;/p>
&lt;p>I ended up reinstalling 16.04 and trying to restore a backup of my home folder.
In this process, I ended up breaking plenty of my configuration. The most
frustrating of which was the breaking of &lt;code>xbacklight&lt;/code> for backlight control.
Before the reinstall, &lt;code>xbacklight&lt;/code> worked perfectly. Now, it returned a
frustrating error: &lt;strong>&amp;ldquo;No outputs have backlight property&amp;rdquo;&lt;/strong>&lt;/p></description></item><item><title>How to download large files on crappy connections with bash and curl</title><link>https://shreve.io/posts/downloading-large-files-on-crappy-connections/</link><pubDate>Thu, 12 Jun 2014 00:00:00 +0000</pubDate><guid>https://shreve.io/posts/downloading-large-files-on-crappy-connections/</guid><description>&lt;p>For some reason, my home internet connection has always been terrible, and
seems like it always will be. That doesn&amp;rsquo;t change the fact that I like the
internet, and downloading things from it, like video games I purchased from
&lt;a href="https://www.humblebundle.com/">The Humble Bundle&lt;/a>. Until recently, I just
dealt with the fact that I&amp;rsquo;d need to pay a visit to my local library or
McDonald&amp;rsquo;s to use their WiFi. No More!&lt;/p>
&lt;p>Most of the time when a download interrupts in any of the major browsers, it
cannot be resumed. You can use a download manager like
&lt;a href="http://mac.eltima.com/download-manager.html">Folx&lt;/a> to get
interruption-tolerant downloading, but I really like to avoid 3rd party
software when possible. It turns out, the best downloading software was already
installed in my terminal. The answer is &lt;code>curl&lt;/code>!&lt;/p></description></item></channel></rss>