Skip to content

Commit

Permalink
Deploying to gh-pages from @ 492372d 🚀
Browse files Browse the repository at this point in the history
  • Loading branch information
knzai committed Jul 30, 2024
1 parent 65f575b commit b75bfcb
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 36 deletions.
30 changes: 15 additions & 15 deletions index.html

Large diffs are not rendered by default.

Binary file added posts/ruby-frequency-hash.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 4 additions & 5 deletions posts/ruby-frequency-hash/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
<!-- Open Graph Tiles -->
<meta property="og:title" content="Kenzi Connor: Using Ruby&#x27;s #.extend on instances to avoid modifying a base class">
<meta property="og:description" content="Making a Scrabble word-finder by adding subtraction and overloading the subset operator on #.tally supplied frequency hashes">
<meta property="og:image" content="https://knz.ai/assets/images/me.jpg" />
<meta property="og:image" content="https://knz.ai/posts/ruby-frequency-hash.png" />
<meta name="twitter:title" content="Kenzi Connor: Using Ruby&#x27;s #.extend on instances to avoid modifying a base class">
<meta name="twitter:description" content="Making a Scrabble word-finder by adding subtraction and overloading the subset operator on #.tally supplied frequency hashes">
<meta name="twitter:image" content="https://knz.ai/assets/images/me.jpg">
<meta name="twitter:image" content="https://knz.ai/posts/ruby-frequency-hash.png">

<!-- Open Graph Tiles; static -->
<meta property="og:type" content="website">
Expand Down Expand Up @@ -118,7 +118,6 @@ <h2 class="post-title">
<p>From there the exact #select criteria against the dictionary of words got into some longer method-chaining that wasn't so easy to debug. Upon later reconsideration, just extending the returned hash with a few methods makes for an easier testing interface. And by extending the hashes directly you don't have to bother with a wrapping class, delegation, or including the methods into Hash and messing with every other hash in your project. If you do this upon intake of the dictionary, it's even a one time performance hit.</p>
<p>So the logic is I need to come up with a subset that is only true if the rhs has not only the keys, or the exact keys and values, but greater or equal values at all keys for a given word. This seemed logically cleanest to me as two operations, a new subtraction operator that subtracts the values of hashes at corresponding keys and then if that returns an empty hash, it's a match. Well, if by "subtracts the values" we mean "and deletes if the rhs has more of an individual tile than needed" but that's fine for our usage, even if it's not how I'd normally implement subtraction. I guess it's "whole numbers only" subtraction, since a negative frequency count, in this usage, doesn't make sense.</p>
<p>You could also do something clever like #transform_value the rhs by negative 1, zipping them togethe, taking the sum, of each, then selecting the value &lt;= 0 entries, but that gets a little complicated, and is a lot of passes compared to just iterating the list and doing the subtraction and delete if, imo.</p>
<p>Later I saw how to get my select logic for the subset down to a clean(ish) single line (<code>select{ |k, v| (v - rhs[k]) &gt; 0}.empty?</code>). I got there faster by just getting a working implementation first and working down from there, which is what I should have done in the screen.</p>
<pre data-lang="ruby" style="background-color:#2b303b;color:#c0c5ce;" class="language-ruby "><code class="language-ruby" data-lang="ruby"><span style="color:#65737e;">#tests for the subtraction that the subset relies on
</span><span style="color:#96b5b4;">hash </span><span>= { </span><span style="color:#a3be8c;">foo: </span><span style="color:#d08770;">5</span><span>, </span><span style="color:#a3be8c;">bar: </span><span style="color:#d08770;">3</span><span>}.</span><span style="color:#8fa1b3;">extend</span><span>(</span><span style="color:#ebcb8b;">Scrabble</span><span>::FreqHash)
</span><span>assert_equal ({</span><span style="color:#a3be8c;">foo: </span><span style="color:#d08770;">2</span><span>}), (</span><span style="color:#96b5b4;">hash </span><span>- {</span><span style="color:#a3be8c;">foo: </span><span style="color:#d08770;">3</span><span>, </span><span style="color:#a3be8c;">bar: </span><span style="color:#d08770;">3</span><span>, </span><span style="color:#a3be8c;">baz: </span><span style="color:#d08770;">3</span><span>})
Expand All @@ -142,8 +141,6 @@ <h2 class="post-title">
</span><span> </span><span style="color:#b48ead;">end
</span><span> newh
</span><span> </span><span style="color:#b48ead;">end
</span><span>
</span><span>
</span><span> </span><span style="color:#b48ead;">end
</span><span>
</span><span> </span><span style="color:#b48ead;">class </span><span style="color:#ebcb8b;">Dictionary </span><span style="color:#eff1f5;">&lt; </span><span style="color:#a3be8c;">Hash
Expand All @@ -163,6 +160,8 @@ <h2 class="post-title">
</span><span> </span><span style="color:#b48ead;">end
</span><span style="color:#b48ead;">end
</span></code></pre>
<p>Later I saw how to get my select logic for the subset down to a clean(ish) single line. But I got there faster by just getting a working implementation first and working down from there, which is what I should have done in the screen. I put the final shorter solution in this posts open graph preview tile, I'm sure that will cause no confusion. 😇:
<img src="https://knz.ai/posts/ruby-frequency-hash.png" alt="Making a Scrabble word-finder by adding subtraction and overloading the subset operator on #.tally supplied frequency hashes" title="Using Ruby&#39;s #.extend on instances to avoid modifying a base class" /></p>


</div>
Expand Down
28 changes: 14 additions & 14 deletions projects/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -115,43 +115,43 @@ <h2 class="post-title">
</div>


<div class="post cega">
<div class="post zolaction">


<h2 class="post-title">
<a href="https:&#x2F;&#x2F;knz.ai&#x2F;projects&#x2F;cega&#x2F;" id="cega">cega</a>: <span class="post-description">CGA/EGA (graphics formats from 80s games) parsing with png/etc output, colored terminal preview, pre-alpha of wasm front-end</span>
<a href="https:&#x2F;&#x2F;knz.ai&#x2F;projects&#x2F;zolaction&#x2F;" id="zolaction">zolaction</a>: <span class="post-description">A GH Action that install, checks, builds, and deploys a zola site</span>
</h2>



<ul>
<li>Language/Platform: Rust</li>
<li>Github Repository: <a href="https://github.com/knzai/cega">knzai/cega</a></li>
<li>Crate Registry: <a href="https://crates.io/crates/cega">crates/cega</a></li>
<li>Language/Platform: Github Actions (bash and yml)</li>
<li>Github Repository: <a href="https://github.com/zolacti/on">zolacti/on</a></li>
<li>Github Marketplace: <a href="https://github.com/marketplace/actions/zola-action">actions/zola-action</a></li>
</ul>
<p>Full documentation on the GH repo README</p>
<p><img src="https://knz.ai/projects/cega.png" alt="CGA/EGA (graphics formats from 80s games) parsing with png/etc output, colored terminal preview, pre-alpha of wasm front-end" title="cega" /></p>
<p>A <a href="https://docs.github.com/en/actions/creating-actions/creating-a-composite-action">composite action</a> that does an idempotent install of <a href="https://www.getzola.org/">zola</a> and calls its <a href="https://www.getzola.org/documentation/getting-started/cli-usage/">CLI</a> to build and optionally deploy a site to Github Pages. Full documentation on the GH repo README</p>
<p><img src="https://knz.ai/projects/zolaction.png" alt="A GH Action that install, checks, builds, and deploys a zola site" title="zolaction" /></p>


</div>


<div class="post zolaction">
<div class="post cega">


<h2 class="post-title">
<a href="https:&#x2F;&#x2F;knz.ai&#x2F;projects&#x2F;zolaction&#x2F;" id="zolaction">zolaction</a>: <span class="post-description">A GH Action that install, checks, builds, and deploys a zola site</span>
<a href="https:&#x2F;&#x2F;knz.ai&#x2F;projects&#x2F;cega&#x2F;" id="cega">cega</a>: <span class="post-description">CGA/EGA (graphics formats from 80s games) parsing with png/etc output, colored terminal preview, pre-alpha of wasm front-end</span>
</h2>



<ul>
<li>Language/Platform: Github Actions (bash and yml)</li>
<li>Github Repository: <a href="https://github.com/zolacti/on">zolacti/on</a></li>
<li>Github Marketplace: <a href="https://github.com/marketplace/actions/zola-action">actions/zola-action</a></li>
<li>Language/Platform: Rust</li>
<li>Github Repository: <a href="https://github.com/knzai/cega">knzai/cega</a></li>
<li>Crate Registry: <a href="https://crates.io/crates/cega">crates/cega</a></li>
</ul>
<p>A <a href="https://docs.github.com/en/actions/creating-actions/creating-a-composite-action">composite action</a> that does an idempotent install of <a href="https://www.getzola.org/">zola</a> and calls its <a href="https://www.getzola.org/documentation/getting-started/cli-usage/">CLI</a> to build and optionally deploy a site to Github Pages. Full documentation on the GH repo README</p>
<p><img src="https://knz.ai/projects/zolaction.png" alt="A GH Action that install, checks, builds, and deploys a zola site" title="zolaction" /></p>
<p>Full documentation on the GH repo README</p>
<p><img src="https://knz.ai/projects/cega.png" alt="CGA/EGA (graphics formats from 80s games) parsing with png/etc output, colored terminal preview, pre-alpha of wasm front-end" title="cega" /></p>


</div>
Expand Down
Loading

0 comments on commit b75bfcb

Please sign in to comment.