<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:media="http://search.yahoo.com/mrss/"><channel><title><![CDATA[blog.omri.io]]></title><description><![CDATA[Musings from the mind of a young gentleman.]]></description><link>https://blog.omri.io/</link><generator>Ghost 0.11</generator><lastBuildDate>Sat, 29 Nov 2025 10:57:11 GMT</lastBuildDate><atom:link href="https://blog.omri.io/rss/" rel="self" type="application/rss+xml"/><ttl>60</ttl><item><title><![CDATA[golang: The Sneaky range Pointer]]></title><description><![CDATA[<p>I want to write about an unintuitive phenomenon I encountered today while debugging my code. It has to do with the way memory allocation happens when you <code>range</code> over an array of structs in golang.</p>

<p>Say you have a Deer struct:</p>

<pre><code>type Deer struct {  
    Hooves []Hoof
}
</code></pre>

<p>Deer have four hooves,</p>]]></description><link>https://blog.omri.io/golang-sneaky-range-pointer/</link><guid isPermaLink="false">f6edb9f1-c51d-47a6-898c-82837c90893b</guid><category><![CDATA[golang]]></category><dc:creator><![CDATA[Omri Harel]]></dc:creator><pubDate>Thu, 19 Jan 2017 11:49:00 GMT</pubDate><content:encoded><![CDATA[<p>I want to write about an unintuitive phenomenon I encountered today while debugging my code. It has to do with the way memory allocation happens when you <code>range</code> over an array of structs in golang.</p>

<p>Say you have a Deer struct:</p>

<pre><code>type Deer struct {  
    Hooves []Hoof
}
</code></pre>

<p>Deer have four hooves, so the above representation seems faithful in terms of memory allocation - hooves belong in the deer, they're a part of it.</p>

<p>Now let's consider the case where we'd like to determine whether the deer is currently hopping. We define a hop as any point in time where the deer has two or more hooves in the air.</p>

<p>For the sake of my example, instead of simply counting how many hooves are mid-air, I will want to do more things with those hooves later, so I want to take that subset into a separate array. Since memory has already been allocated previously for the Hooves (when the Deer was adorably constructed), I would prefer to not allocate it again, meaning I will use an array of Hoof pointers: <code>[]*Hoof</code></p>

<p>Here's what this code would look like:  </p>

<pre><code>func (deer *Deer) GetMidAirHooves() []*Hoof {  
    midAirHooves := []*Hoof{}

    for _, hoof := range deer.Hooves {
        if hoof.MidAir() {

            // append the hoof's address
            midAirHooves = append(midAirHooves, &amp;hoof)
        }
    }

    return midAirHooves
}
</code></pre>

<p>This is where it may get confusing: when you <code>range</code> over an array of structs, and then reference the current struct's address (<code>&amp;hoof</code> in our example), you're referencing the <em>address of the memory allocated for the iteration itself</em>. This memory has the iterated structs copied into it one after the other, and once the iteration ends, any reference to it will only give you the <em>last</em> struct in the array. The de-facto result is that <code>midAirHooves</code> will contain as many pointers as there are hooves in the air, all of them pointing to the fourth hoof.</p>

<p>The implications is that if you still want to produce a pointer array from a struct array, you'll need to use the index to correctly point to the struct. In our case the loop would look as such:  </p>

<pre><code>    for i, hoof := range deer.Hooves {
        if hoof.MidAir() {

            // append the real hoof's address
            midAirHooves = append(midAirHooves, &amp;(deer.Hooves[i]))
        }
    }
</code></pre>

<p>Watch out for this tricky behavior when writing your code!</p>]]></content:encoded></item><item><title><![CDATA[Docker Acquires Itself in Industry-Breaking Merger, to Build Corporate HQ in the Cloud]]></title><description><![CDATA[<p>Docker has successfully completed an acquisition of itself, valued at $92B, Docker CEO Timothy Cachinglayers disclosed to The Onion Router earlier today. This acquisition, which Cachinglayers assures us is an industry first, takes Docker's Linux container technology a step further by applying copy-on-write principles to the company's monetary and physical</p>]]></description><link>https://blog.omri.io/docker-merger/</link><guid isPermaLink="false">13b3b390-b630-4a41-aabf-dba33458075c</guid><dc:creator><![CDATA[Omri Harel]]></dc:creator><pubDate>Thu, 18 Feb 2016 09:30:06 GMT</pubDate><content:encoded><![CDATA[<p>Docker has successfully completed an acquisition of itself, valued at $92B, Docker CEO Timothy Cachinglayers disclosed to The Onion Router earlier today. This acquisition, which Cachinglayers assures us is an industry first, takes Docker's Linux container technology a step further by applying copy-on-write principles to the company's monetary and physical assets, effectively doubling its size, revenue and user base. When asked how he expects to deal with this merger's inevitable scale challenges, Cachinglayers stared at me blankly for several seconds and then responded:</p>

<blockquote>
  <p>"Docker's vision has always been scalability, scalability and scalability. We are going to build a new headquarters up in the Cloud, we truly believe that's where our innovation will be the most secure and we've always been about security, security, security."</p>
</blockquote>

<p><strong>What's in the future for Docker?</strong>
"Well, obviously we're going to do a bunch of Dockers, that <em>is</em> the company's name and we're really all about that at the end of the day. But we're committed to bring new cutting-edge technologies to everyone, and today I'm excited to announce our very own integrated Big Data containers - Bonkers. You can think of Bonkers as your Dockers in the Cloud with Big Data. We're bringing everything to an intuitive UI - you name it, we support it. There's Hadoop, Cassandra and even good ol' MySQL. And yes - we can scale your cluster", and with a very suggestive gawk he added, "and we will."</p>]]></content:encoded></item><item><title><![CDATA[Well then.]]></title><description><![CDATA[<p>It appears that I now have a site. And a blog. That's wonderful! Almost as wonderful as poros! ..Okay, I might be a <em>little</em> bit off. But it's still pretty nice.</p>

<p>So now, equipped with my very own <a href="http://omri.io"><em>.io</em></a> domain name, and an extreme thirst for angryface pun-haters, I embark</p>]]></description><link>https://blog.omri.io/intro/</link><guid isPermaLink="false">40fa5ad5-75fa-415e-a717-004c48fce1c1</guid><dc:creator><![CDATA[Omri Harel]]></dc:creator><pubDate>Thu, 24 Dec 2015 18:23:31 GMT</pubDate><content:encoded><![CDATA[<p>It appears that I now have a site. And a blog. That's wonderful! Almost as wonderful as poros! ..Okay, I might be a <em>little</em> bit off. But it's still pretty nice.</p>

<p>So now, equipped with my very own <a href="http://omri.io"><em>.io</em></a> domain name, and an extreme thirst for angryface pun-haters, I embark on a fresh journey of having <em>absolutely no fucking idea</em> what I am doing. With lots and lots of <a href="http://docker.io">Docker</a>, as I hear that is quite popular nowadays.</p>

<h5 id="architecture">Architecture</h5>

<p>Setting this stack up was relatively simple, especially for a complete web-moron such as myself. This blog runs on <a href="http://ghost.org">Ghost</a>, an open-source blogging platform running on NodeJS. It's hosted on a <a href="https://www.digitalocean.com">DigitalOcean</a> Ubuntu server, and runs on top of Docker containers (one per service, so one for this blog and another one with nginx for the main area, currently).</p>

<p>In addition to that, a main nginx server runs directly on top of the server, and it acts as the gateway to everything. It reverse-proxies requests by their subdomain to their appropriate Docker container's port:</p>

<pre><code>main_nginx  
    ------&gt; omri.io, www.omri.io -&gt; http://localhost:6000
    ------&gt; blog.omri.io -&gt; http://localhost:6001
</code></pre>

<p>In order to keep the docker containers volatile and non-important, their relevant data directories are volumes originating from the server's filesystem.</p>

<p>Keep in mind: doing this isn't enough on its own and you'll also need to create A-records in your domain's DNS settings, for every subdomain that you wish to reach your server.</p>

<p>Should I decide to write any real code and <em>actually</em> do something with this virtual space, it'll be made available in my <a href="http://github.com/omriharel/omri.io">GitHub repository</a> that I opened for this project.</p>

<h5 id="conclusion">Conclusion</h5>

<p>But for now, hello there! And thanks for checking me out, blogboys. I, for one, am excited and also a bit disappointed that we made it so far without any puns. It's only fun if they pun.</p>]]></content:encoded></item></channel></rss>