<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Kolton Kulis</title>
    <description>The latest articles on Forem by Kolton Kulis (@kooltone).</description>
    <link>https://forem.com/kooltone</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3364123%2Fee1c766b-bb51-4ebf-9d9d-be1169d290e9.JPG</url>
      <title>Forem: Kolton Kulis</title>
      <link>https://forem.com/kooltone</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/kooltone"/>
    <language>en</language>
    <item>
      <title>Ruby System Calls and Regex</title>
      <dc:creator>Kolton Kulis</dc:creator>
      <pubDate>Mon, 04 Aug 2025 18:03:19 +0000</pubDate>
      <link>https://forem.com/kooltone/ruby-system-calls-and-regex-5h7o</link>
      <guid>https://forem.com/kooltone/ruby-system-calls-and-regex-5h7o</guid>
      <description>&lt;p&gt;Today we will learn about Ruby system calls and regex support by making a simple Bible verse of the day script. &lt;/p&gt;

&lt;p&gt;First we need a verse picker, and the easiest way to do that is to outsource the logic by using a preexisting website. So, I did some web searching and I found this page is fairly easy to parse: &lt;a href="https://www.bible.com/verse-of-the-day" rel="noopener noreferrer"&gt;verse of the day&lt;/a&gt;. A simple &lt;code&gt;curl https://www.bible.com/verse-of-the-day&lt;/code&gt; gets me the HTML. There are a lot of tags, but this a sample of the tags I am interested in.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;meta property="og:description" content="Philippians 2:3 Do nothing from selfish ambition or conceit, but in humility count others more significant than yourselves."/&amp;gt;&amp;lt;meta property="og:image" content="https://imageproxy.youversionapi.com/640x640/https://s3.amazonaws.com/static-youversionapi-com/images/base/105183/1280x1280.jpg"/&amp;gt;&amp;lt;meta property="og:image:height" content="640"/&amp;gt;&amp;lt;meta property="og:image:width" content="640"/&amp;gt;&amp;lt;meta name="twitter:site" content="@YouVersion"/&amp;gt;&amp;lt;meta name="twitter:card" content="summary"/&amp;gt;&amp;lt;meta name="twitter:creator" content="@YouVersion"/&amp;gt;&amp;lt;meta name="twitter:title" content="Verse of the Day"/&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I'm not bothering with learning Ruby's net package right now since I use curl all the time, so the next step was to figure out how to call curl from within Ruby. Turns out it's a breeze! All you have to do to run a system command and save the output is surround your command with backticks.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;html&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sb"&gt;`curl -s "https://www.bible.com/verse -of-the-day"`&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now I have the html, so how do I extract the verse? Enter regular expressions. I'm going to write a regex that extracts the string that comes after "og:description content=". So here is our new Ruby line.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="sr"&gt;/og:description" content="(?&amp;lt;verse&amp;gt;[^"]+)/&lt;/span&gt; &lt;span class="o"&gt;=~&lt;/span&gt; &lt;span class="n"&gt;html&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you are not familiar with regular expressions, they are super powerful but they are also not very readable. Let me explain what is going on. Everything within // is a regex and &lt;code&gt;=~ html&lt;/code&gt; tells Ruby to evaluate the regex against the html string. The first part of the regex says to find a text match that starts with &lt;code&gt;og:description" content="&lt;/code&gt;. Then we create a "capturing group" in the parentheses. In regular expressions, &lt;code&gt;?&amp;lt;name here&amp;gt;&lt;/code&gt; is the way to declare a named variable. I'm telling regex to dump whatever it matches into a var called &lt;code&gt;verse&lt;/code&gt;. The &lt;code&gt;[^"]+&lt;/code&gt; says to match anything that is not a double quote character. To summarize, this regex will grab everything within the double quotes of the the content field, and Ruby magically creates a var named &lt;code&gt;verse&lt;/code&gt; without me explicitly using an assigment expression.&lt;/p&gt;

&lt;p&gt;The contents of &lt;code&gt;verse&lt;/code&gt; looks like this now: "Philippians 2:3 Do nothing from selfish ambition or conceit, but in humility count others more significant than yourselves.". So, all that is left to do is print to the screen.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="n"&gt;verse&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And there you have it. I'm quite shocked at how succinct this is. Most other languanges I've worked with would require a lot more boilerplate. We have a working verse of the day script in only four lines of code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;html&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sb"&gt;`curl -s "https://www.bible.com/verse-of-the-day"`&lt;/span&gt;

&lt;span class="sr"&gt;/og:description" content="(?&amp;lt;verse&amp;gt;[^"]+)/&lt;/span&gt; &lt;span class="o"&gt;=~&lt;/span&gt; &lt;span class="n"&gt;html&lt;/span&gt;
&lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="n"&gt;verse&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Is this going to work in the long term? I don't know. If the website layout changes, I'll have to update the script, but so far it's been working great. I made an alias inside my z shell config, so now I can get the verse of the day by typing &lt;code&gt;verse&lt;/code&gt;. It was quite fun making this!&lt;/p&gt;

</description>
      <category>ruby</category>
      <category>learning</category>
    </item>
    <item>
      <title>Ruby: A New Journey</title>
      <dc:creator>Kolton Kulis</dc:creator>
      <pubDate>Fri, 18 Jul 2025 21:57:39 +0000</pubDate>
      <link>https://forem.com/kooltone/ruby-a-new-journey-3kc8</link>
      <guid>https://forem.com/kooltone/ruby-a-new-journey-3kc8</guid>
      <description>&lt;p&gt;I just listened to this &lt;a href="https://youtu.be/vagyIcmIGOQ?si=W9AkqODjtIdItZ5g" rel="noopener noreferrer"&gt;6 hour long Lex Fridman interview with DHH&lt;/a&gt;, and DHH's enthusiasm inspired me to finally give Ruby a try. So here I am a couple days into learning Ruby, and it has been a lot of fun!&lt;/p&gt;

&lt;p&gt;First things first, Perl used to be my main scripting language. I know. I know. It's a weird one, but you can do so many cool things when a language has first class regex support. I've tried to like Python, but I do not like the syntax and writing in it feels abrasive. I do not like the space/tab formatting of Python, and I often butt up against one of Python's core tenets: &lt;a href="https://peps.python.org/pep-0020/" rel="noopener noreferrer"&gt;"There should be one-- and preferably only one --obvious way to do it."&lt;/a&gt; Eh. No! Give me options! More options may make the language more difficult to learn, but having shortcuts makes the programmer experience more enjoyable as you gain language mastery. I like languages that give me the tools to shoot myself in the foot, and I don't mind a steep learning curve (I use Neovim btw) if the payoff is satisfying.&lt;/p&gt;

&lt;p&gt;I love the flexibility of Perl, but I'm looking for something to replace Perl's acid trip syntax. Ruby is supposedly pleasant, so here we go.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;puts "hello world!"&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;puts "To be continued ..."&lt;/code&gt;&lt;/p&gt;

</description>
      <category>ruby</category>
      <category>learning</category>
    </item>
  </channel>
</rss>
