<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Programming on Bhaak&#39;s Blog</title>
    <link>https://bhaak.net/blog/categories/programming/</link>
    <description>Recent content in Programming on Bhaak&#39;s Blog</description>
    <generator>Hugo</generator>
    <language>en-us</language>
    <lastBuildDate>Thu, 14 May 2026 15:23:13 +0200</lastBuildDate>
    <atom:link href="https://bhaak.net/blog/categories/programming/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Accessing ActiveRecord attribute slower than local variable</title>
      <link>https://bhaak.net/blog/posts/2026-05-14-accessing-activerecord-attribute-slower-than-local-variable/</link>
      <pubDate>Thu, 14 May 2026 15:23:13 +0200</pubDate>
      <guid>https://bhaak.net/blog/posts/2026-05-14-accessing-activerecord-attribute-slower-than-local-variable/</guid>
      <description>&lt;p&gt;I was deep in a performance optimization flow when I stumbled upon this part in&#xA;&lt;a href=&#34;https://github.com/ruby-prof/ruby-prof&#34;&gt;a ruby-prof graph&lt;/a&gt;:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-text&#34; data-lang=&#34;text&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;- 17.59% (73.45%) SomeTable::GeneratedAttributeMethods#some_attribute [30263106 calls, 44665545 total]&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  - 15.24% (86.62%) ActiveRecord::AttributeMethods::Read#_read_attribute [30263106 calls, 49437307 total]&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    - 11.82% (77.58%) ActiveModel::AttributeSet#fetch_value [30263106 calls, 49068748 total]&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      - 5.44% (46.06%) ActiveModel::AttributeSet#[] [30263106 calls, 49303667 total]&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        - 2.32% (42.58%) Hash#[] [30263106 calls, 72892138 total]&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      - 2.05% (17.36%) ActiveModel::Attribute#value [30263106 calls, 49274896 total]&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;ActiveRecord stores attributes internally in a hash, which is more expensive than I expected.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Avoid Integer for File Sizes in Postgres</title>
      <link>https://bhaak.net/blog/posts/2026-03-05-avoid-integer-for-file-sizes-in-postgres/</link>
      <pubDate>Thu, 05 Mar 2026 12:43:14 +0100</pubDate>
      <guid>https://bhaak.net/blog/posts/2026-03-05-avoid-integer-for-file-sizes-in-postgres/</guid>
      <description>&lt;p&gt;Here’s a small bug we recently encountered in production.&#xA;Occasionally, PDF generation jobs would fail, and the cause turned out to be&#xA;a small oversight when designing database tables.&lt;/p&gt;&#xA;&lt;p&gt;The PDF metadata is stored in a table, and the column for file size was defined&#xA;as &lt;code&gt;integer&lt;/code&gt;, also known as &lt;code&gt;int4&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;p&gt;Since this data type is signed in Postgres, those 4 bytes only allow for files&#xA;up to 2.1 GB (2 147 483 647 bytes).&#xA;You might think, 2^31 bytes ought to be enough for everybody &amp;hellip; except&#xA;apparently for our PDFs.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Code Golfing Leap Years in Ruby</title>
      <link>https://bhaak.net/blog/posts/2026-01-20-code-golfing-leap-years-in-ruby/</link>
      <pubDate>Tue, 20 Jan 2026 13:25:01 +0100</pubDate>
      <guid>https://bhaak.net/blog/posts/2026-01-20-code-golfing-leap-years-in-ruby/</guid>
      <description>&lt;p&gt;A work buddy challenged me to a bit of Ruby code golfing.&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;Write a program to print all leap years from 1800 up to and including 2400.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;The website he got the challenge from (&lt;a href=&#34;https://code.golf/leap-years#ruby&#34;&gt;https://code.golf/leap-years#ruby&lt;/a&gt;) has a&#xA;neat feature: it can run your code and verify whether the output matches the&#xA;expected result.&lt;/p&gt;&#xA;&lt;p&gt;I’m usually not much of a code golfer, I generally prefer writing code that’s&#xA;performant and readable rather than short and cryptic, but this turned out to be&#xA;a fun little challenge and even somewhat educational.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Simulating candle flickering with a simple RNG</title>
      <link>https://bhaak.net/blog/posts/2023-11-23-candle-flickering-with-a-simple-rng/</link>
      <pubDate>Thu, 23 Nov 2023 12:48:00 +0100</pubDate>
      <guid>https://bhaak.net/blog/posts/2023-11-23-candle-flickering-with-a-simple-rng/</guid>
      <description>&lt;style&gt;&#xA;  #candle {&#xA;    background-color: black;&#xA;    color: #eee;&#xA;    width: fit-content;&#xA;    margin-left: 2vw;&#xA;    text-align: center;&#xA;    line-height: 0.9;&#xA;    font-size: 250%;&#xA;    margin-top: 0;&#xA;  }&#xA;&lt;/style&gt;&#xA;&lt;p&gt;While preparing to attach the electrical candles to the Christmas tree,&#xA;a question popped into my mind.&lt;/p&gt;&#xA;&lt;p&gt;There are electrical candles that simulate the flickering of real&#xA;candles. How complex would an algorithm have to be to be convincing?&lt;/p&gt;&#xA;&lt;p&gt;I wrote a quick proof of concept in Ruby for a script running in the terminal&#xA;which just randomly chooses a grey value to display.&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
