<?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[codenamev]]></title><description><![CDATA[Power. Simplicity. Beauty.]]></description><link>https://blog.codenamev.com/</link><image><url>https://blog.codenamev.com/favicon.png</url><title>codenamev</title><link>https://blog.codenamev.com/</link></image><generator>Ghost 2.9</generator><lastBuildDate>Tue, 08 Jun 2021 13:28:38 GMT</lastBuildDate><atom:link href="https://blog.codenamev.com/rss/" rel="self" type="application/rss+xml"/><ttl>60</ttl><item><title><![CDATA[How to Make Colors With Ruby and Bitwise Operations]]></title><description><![CDATA[Using a Raspberry Pi, this tutorial showcases how to leverage Ruby's bitwise operators on hexadecimal primitives to extract colors and light up an LED.]]></description><link>https://blog.codenamev.com/a-simple-ruby-guessing-game/</link><guid isPermaLink="false">Ghost__Post__60b97ee5b2352a001cc5d837</guid><category><![CDATA[Raspberry Pi]]></category><category><![CDATA[ruby]]></category><category><![CDATA[SunFounder Super Kit Series]]></category><dc:creator><![CDATA[Valentino Stoll]]></dc:creator><pubDate>Fri, 11 Oct 2019 21:05:00 GMT</pubDate><media:content url="https://s3.amazonaws.com/blog-codenamev-prod/2021/06/raspberry-pi-color-guess-web.jpg" medium="image"/><content:encoded><![CDATA[<blockquote>This is part 5 in my <a href="https://codenamev-ghost.herokuapp.com/tag/sunfounder-super-kit/">Sunfounder Superkit series</a>.</blockquote><img src="https://s3.amazonaws.com/blog-codenamev-prod/2021/06/raspberry-pi-color-guess-web.jpg" alt="How to Make Colors With Ruby and Bitwise Operations"/><p>In our last lesson, we utilized the badass (P)ulse (W)idth (M)odulation tech to breathe life into a simple LED.  Here, we're going to take this to new levels and apply it to <em>multiple channels</em>.</p><p>Unfortunately, the PWM hardware included with the Raspberry B+ is only capable of communicating over a <em>single channel</em>.  Since we have 3 channels we need to talk to (for each of our three colors), we'll have to go soft and crank this up with software: <strong>softPwm</strong>.</p><h3 id="first-how-the-rgb-led-works">First: How the RGB LED works</h3><p>The RGB LED I'm working with has four pins.  Three of these pins take input that control the brightness level for (R)ed, (G)reen, and (B)lue.  This allows us to take advantage of the <a href="https://en.wikipedia.org/wiki/Additive_color">additive color system</a> to create all kinds of colors by supplying different proportions of these three types of light (e.g. fully bright red and fully bright blue will appear purple).</p><p>Our Problem: How can we easily store color values in RGB format as a percentage of luminance?</p><h3 id="hexadecimal-to-the-rescue-">Hexadecimal To The Rescue!</h3><p>I know what you're thinking:</p><figure class="kg-card kg-image-card"><img src="https://s3.amazonaws.com/blog-codenamev-prod/2021/06/eye-roll.gif" class="kg-image" alt="How to Make Colors With Ruby and Bitwise Operations" loading="lazy" width="200" height="150"/></figure><p>Don't lose me just yet.  There's some hidden gold here!  The magic of bitwise operations.</p><p>The binary <code>11111111</code> is equal to <code>255</code>.  Luckily for us, this binary representation maps perfectly to Hexadecimal, as <code>FF == 255</code>!</p><p><code>11111111 00000000 00000000</code></p><p>    RED        GREEN      BLUE</p><p>What this means is that we can use <a href="https://docs.ruby-lang.org/en/2.6.0/syntax/literals_rdoc.html#label-Numbers">Hexadecimal literals in Ruby</a>, and as a result start to see some serious gains.  First off, Hexadecimal numbers make a lot of sense to us as colors already.  These are the Ruby equivalent of the CSS versions you might be familiar with:</p><!--kg-card-begin: markdown--><table>
<thead>
<tr>
<th>Color</th>
<th>Hexadecimal Representation in Ruby</th>
</tr>
</thead>
<tbody>
<tr>
<td>Red</td>
<td><code>0xFF0000</code></td>
</tr>
<tr>
<td>Green</td>
<td><code>0x00FF00</code></td>
</tr>
<tr>
<td>Blue</td>
<td><code>0x0000FF</code></td>
</tr>
<tr>
<td>Purple</td>
<td><code>0xFF00FF</code></td>
</tr>
</tbody>
</table>
<!--kg-card-end: markdown--><p>The real value here comes with the calculations we can make.  Using hexadecimal literals makes some things easier.  We can extract each red, green, or blue value from any given hexadecimal color by AND'ing the bits of the maxed out version of our target.</p><p>Let's say we have the color <code>0xFF1133</code> .  This has a binary form of:</p><p><code>11111111 00010001 00110011</code> </p><p>We can extract the value of just the blue color <code>0x0000FF</code> by using the bitwise AND (<code>&amp;</code>) operator to cancel out all non-blue bits.  So:</p><p><code>0xFF1133 &amp; 0x0000FF == 0x000033</code></p><p>This is because all the <code>0</code> bits in our pure blue color <code>0x0000FF</code> override any bits set in any of the other color positions, and any <code>0</code> bits in our <code>0xFF0033</code> color override any <code>1</code> bits in our pure blue.</p><pre><code>  11111111 00010001 00110011
&amp; 00000000 00000000 11111111
               ⇣
  00000000 00000000 00110011</code></pre><p>This works great for our blue value, but for the others we have to take this one step further.  If we were to perform this same bitwise AND on the pure green color <code>0x00FF00</code> then we will get what we want, except with a lot of trailing zeros.</p><pre><code>  11111111 00010001 00110011
&amp; 00000000 11111111 00000000
               ⇣
  00000000 00010001 00000000</code></pre><p>In order to target that middle section of the resulting bitwise operation, we need to shift the bits to the right to get rid of the extra zeros.  To do this, we can use the bitwise right shift operator <code>&gt;&gt;</code> and push them eight places to the right.</p><pre><code>00000000 00010001 00000000 &gt;&gt; 8
             ⇣
00000000 00000000 00010001</code></pre><p><strong>Bingo! Unity.</strong>  With this in mind, we can translate it to Ruby and apply these lightning fast calculations to extract percentages of each RGB color value from a hexadecimal numeric:</p><pre><code class="language-ruby"># Given the folowing color
color = 0x6495ED
percentage_blue = (color &amp; 0x0000FF) * 100 / 255 # =&gt; 92%
percentage_green = ((color &amp; 0x00FF00) &gt;&gt; 8) * 100 / 255 # =&gt; 58%
percentage_red = ((color &amp; 0xFF0000) &gt;&gt; 16) * 100 / 255 # =&gt; 39%</code></pre><h3 id="all-together-now">All Together Now</h3><p>Since the duty cycle value is essential the percentage that the signal will be ON, we can just extract the RGB color percentages from a hexadecimal color value and set these to the duty cycle of each RGB pin of the LED.</p><p>Ok, ok, all this binary mumbo jumbo and all we get is a bunch of flashing colors!?  Let's turn the dial all the way up to eleven and add a simple twist: <em>have a button trigger a random color</em>.</p><p>BOOM!  We have made a game!  Guess what color the LED will be when you press the button?</p><figure class="kg-card kg-image-card"><img src="https://s3.amazonaws.com/blog-codenamev-prod/2021/06/raspberry-pi-color-guess-vid.gif" class="kg-image" alt="How to Make Colors With Ruby and Bitwise Operations" loading="lazy" width="600" height="338"/></figure><!--kg-card-begin: html--><script src="https://gist.github.com/codenamev/33248181037adfee938edf5ecd4f756e.js"/><!--kg-card-end: html--><hr><p>Special thank you to <a href="https://www.calleerlandsson.com/rubys-bitwise-operators/">Calle Erlandsson's fantastic write-up on bitwise operations in Ruby</a>.</p></hr>]]></content:encoded></item><item><title><![CDATA[The Great Breathing Ruby LED]]></title><description><![CDATA[In our last experiment, you were probably bedazzled by the alluring display of LEDs.  This time around, we'll go from bedazzling to mesmerizing and use sweet technological magic to make an LED breathe.]]></description><link>https://blog.codenamev.com/the-great-glowing-ruby-led/</link><guid isPermaLink="false">Ghost__Post__60b97ee5b2352a001cc5d836</guid><category><![CDATA[SunFounder Super Kit Series]]></category><category><![CDATA[Raspberry Pi]]></category><category><![CDATA[ruby]]></category><dc:creator><![CDATA[Valentino Stoll]]></dc:creator><pubDate>Fri, 27 Sep 2019 21:21:23 GMT</pubDate><media:content url="https://s3.amazonaws.com/blog-codenamev-prod/2021/06/raspberry-pi-blinking-led-web.jpeg" medium="image"/><content:encoded><![CDATA[<blockquote>This is part 4 in my <a href="https://codenamev-ghost.herokuapp.com/tag/sunfounder-super-kit/">Sunfounder Superkit series</a>.</blockquote><img src="https://s3.amazonaws.com/blog-codenamev-prod/2021/06/raspberry-pi-blinking-led-web.jpeg" alt="The Great Breathing Ruby LED"/><p>In our last experiment, you were <em>probably</em> bedazzled by the alluring display of LEDs.  This time around, we'll go from bedazzling to mesmerizing and use sweet technological magic to make an LED <strong>breathe</strong>.</p><figure class="kg-card kg-image-card kg-card-hascaption"><img src="https://s3.amazonaws.com/blog-codenamev-prod/2021/06/gob-bluth-magic.gif" class="kg-image" alt="The Great Breathing Ruby LED" loading="lazy" width="245" height="157"><figcaption><a href="https://media.giphy.com/media/11a9K7FLvTD9Kw/giphy.gif">via Giphy</a></figcaption></img></figure><p>Admittedly, not that kind of magic.  Lucky for you, I'm taking big risks, breaking the Magician's Code and revealing the secret behind the trick: <strong><a href="https://en.wikipedia.org/wiki/Pulse-width_modulation">Pulse Width Modulation</a></strong>.</p><h3 id="pulse-width-modulation-pwm-">Pulse Width Modulation (PWM)</h3><p>To get a good understanding of what the heck this bad girl is, let's sprint down history lane and attempt to reproduce our results <em>analog style</em>.  Before the wonderful invention of PWM, most electrical signals<a href="https://en.wikipedia.org/wiki/Analog_signal"> </a>were handled continuously by analyzing voltage over time.  </p><figure class="kg-card kg-image-card"><img src="https://s3.amazonaws.com/blog-codenamev-prod/2021/06/analog-signal.gif" class="kg-image" alt="The Great Breathing Ruby LED" loading="lazy" width="400" height="400"/></figure><p>As you might imagine, this can lead to huge wastes in energy while constantly having to check for changes to the output voltage.  Most electronic applications will likely not need this continuous stream of signal, and to take advantage of this, the GPIO pins on the Raspberry Pi rely on <a href="https://en.wikipedia.org/wiki/Digital_signal"><em>digital</em> signals</a>.  Instead of treating the signal as a continuous stream, digital signals stream a sequence of <em>discrete</em> values.</p><figure class="kg-card kg-image-card kg-card-hascaption"><img src="https://s3.amazonaws.com/blog-codenamev-prod/2021/06/digital-signal.gif" class="kg-image" alt="The Great Breathing Ruby LED" loading="lazy" width="480" height="480"><figcaption><a href="https://media.giphy.com/media/9VkaGX5OKCjrjjNi98/giphy.gif">via Giphy</a></figcaption></img></figure><p>Ok, so where the hell does Pulse Width Modulation come in!?  PWM  takes advantage of these digital signals by rapidly turning the voltage off and then turning them on again to a slightly higher or lower voltage.  In our example, this choppy signal will simulate a smooth increase in voltage (LED getting brighter) or decrease in voltage (LED getting dimmer).</p><figure class="kg-card kg-image-card kg-card-hascaption"><img src="https://s3.amazonaws.com/blog-codenamev-prod/2021/06/fading-led-pwm.gif" class="kg-image" alt="The Great Breathing Ruby LED" loading="lazy" width="470" height="422"><figcaption>Credit: <a href="https://www.instructables.com/id/Fade-LED-Arduino-Analog-Output-Tinkercad/">https://www.instructables.com/id/Fade-LED-Arduino-Analog-Output-Tinkercad/</a></figcaption></img></figure><h3 id="pwm-with-ruby-">PWM with Ruby!</h3><p>Ok, enough with the circuits already, and on to the fun part: <strong>Ruby</strong>!  Luckily for us, the <code>rpi_gpio</code> gem comes with PWM built-in.  With a little elbow grease we can start the mesmerization process.</p><!--kg-card-begin: html--><script src="https://gist.github.com/codenamev/03eff781d73ada3948c7fd1ae3fbaa02.js"/><!--kg-card-end: html--><h3 id="wrap-up">Wrap Up</h3><p>We're really starting to dive into the embedded systems waters here.  PWM is a great way to finely control things we want to... modulate.  I'm out of ideas for alternatives on this one, but next time we'll take LEDs to new colored dimensions and I'll invent the simplest of games :-)</p>]]></content:encoded></item><item><title><![CDATA[Ruby Driven LED Arrays]]></title><description><![CDATA[Join me as I test my patience, and  connect eight LEDs + resistors + wires up to a Raspberry Pi and use Ruby to make a dazzling light show.]]></description><link>https://blog.codenamev.com/ruby-driven-led-arrays/</link><guid isPermaLink="false">Ghost__Post__60b97ee5b2352a001cc5d834</guid><category><![CDATA[Raspberry Pi]]></category><category><![CDATA[ruby]]></category><category><![CDATA[SunFounder Super Kit Series]]></category><dc:creator><![CDATA[Valentino Stoll]]></dc:creator><pubDate>Fri, 20 Sep 2019 21:08:00 GMT</pubDate><media:content url="https://s3.amazonaws.com/blog-codenamev-prod/2021/06/raspberry-pi-led-array-web-1.jpg" medium="image"/><content:encoded><![CDATA[<blockquote>This is part 3 in my <a href="https://codenamev-ghost.herokuapp.com/tag/sunfounder-super-kit/">Sunfounder Superkit series</a>.</blockquote><img src="https://s3.amazonaws.com/blog-codenamev-prod/2021/06/raspberry-pi-led-array-web-1.jpg" alt="Ruby Driven LED Arrays"/><p>We’ve blinked it, hooked it to a button, and now for some serious fun: <em>lots of them</em>! This exercise really tests your patience with the breadboard.</p><p>(1 LED + 1 resistor + 2 wires) * 8 = 24 things to plug in</p><p>Once this was all setup (~15min), it looked great! I was really pumped to start playing around with so many twinkling lights!</p><figure class="kg-card kg-image-card kg-card-hascaption"><img src="https://s3.amazonaws.com/blog-codenamev-prod/2021/06/raspberry-pi-led-array-web.jpg" class="kg-image" alt="Ruby Driven LED Arrays" loading="lazy" width="1500" height="824"><figcaption>Fully wired up LED array</figcaption></img></figure><h3 id="the-ruby-journey-begins">The Ruby Journey Begins</h3><p>So I crack open the python script and start to pipe it into ruby, because Ruby. I get to the line where it sets up the LEDs with <code>rpi_gpio</code> and what do I find? No multi-pin setup support.</p><figure class="kg-card kg-image-card kg-card-hascaption"><img src="https://s3.amazonaws.com/blog-codenamev-prod/2021/06/shocked-baby.gif" class="kg-image" alt="Ruby Driven LED Arrays" loading="lazy" width="295" height="222"><figcaption><a href="http://gph.is/1Gq5LIT">vi Giphy</a></figcaption></img></figure><p>I know what you’re thinking, “Just move on and test it with Python or C already”. Helllllll no! I didn’t make it all this way to have to mangle together some half-baked snake-oil code (in all fairness, the C code is quite nice to work with, and I did try it out before converting this **blush**).</p><p>It’s time to pony it up and ride the open source winds into the sunset.</p><figure class="kg-card kg-image-card kg-card-hascaption"><img src="https://s3.amazonaws.com/blog-codenamev-prod/2021/06/kid-keeps-riding.gif" class="kg-image" alt="Ruby Driven LED Arrays" loading="lazy" width="224" height="231"><figcaption><a href="http://gph.is/1sEBxTv">via Giphy</a></figcaption></img></figure><p>Fortunately, the <a href="https://docs.ruby-lang.org/en/trunk/extension_rdoc.html" rel="noopener">Ruby documentation on creating extension libraries</a> is really spectacular. With a little fiddling, I was able to get a working multi-pin <code>GPIO.setup</code> method, and <a href="https://github.com/ClockVapor/rpi_gpio/pull/18" rel="noopener">PR submitted</a>.  Yay open source!</p><p>Before the PR merged, I had to build the gem locally ( <code>rake compile</code>) and reference it using the <code>gem “rpi_gpio", path: /path/to/local/rpi_gpio</code> in my Gemfile.  I'll float by all the gripes I have with developing Ruby extensions and dive right into the goal: a real-life self-made majestic racing marquee!</p><!--kg-card-begin: html--><script src="https://gist.github.com/codenamev/18a3d26bdcef57e54f33fd47f19a22da.js"/><!--kg-card-end: html--><p>So, that was a fun ride.  The creative corner of my brain came knocking through the wall like the Kool-aid man though.  I just <em>have</em> to spin this drab loop into something a little more fun and, dare I say, <em>practical</em>?</p><h3 id="a-simple-binary-counter">A Simple Binary Counter</h3><p>Ok, not the most amazingly-fantastic-best-idea-ever, but I'm looking for a <em>small twist</em> to my existing example so I can escape the monotony of this textbook tutorial.  With our new lovely Ruby script, we can make some small tweaks and have our <em>LEDs</em> count all the way to <strong>two hundred and fifty five</strong> (<a href="https://github.com/codenamev/ruby-pi/blob/master/binary_counter.rb">code here to save space</a>). </p><figure class="kg-card kg-image-card"><img src="https://s3.amazonaws.com/blog-codenamev-prod/2021/06/raspberry-pi-binary-counter-min.gif" class="kg-image" alt="Ruby Driven LED Arrays" loading="lazy" width="600" height="338"/></figure><p>Impressive, I know, but practical?  Well my creativity was oozing today (with this many twinkling lights how could it not!?) and discovered how I might be able to turn this into my new favorite desk toy.</p><h3 id="to-the-future-and-beyond">To the Future and Beyond</h3><p>I'm a pretty big fan of the <a href="https://francescocirillo.com/pages/pomodoro-technique">Pomodoro Technique</a>, and since I now made something that can count, I'll likely jack this bad girl up and spin this sweet little counter into a meaningful meter for time spent.  A visual Pomodoro Meter if you will.</p><p>Or maybe, instead of counting time, it could count the number of PRs I have open on GitHub.  So many possibilities!  </p><p>Well that's all for now folks.  I hope you enjoyed the sunset.  If you decide to boldly clone this and make something of your own I'd love to hear about it :-)</p><p>Tune in next week, where I venture into mutli-colored LED land and a slowly pulsing light show.</p>]]></content:encoded></item><item><title><![CDATA[Ruby driven Raspberry Pi buttons]]></title><description><![CDATA[Use a Raspberry Pi with Ruby and hook a button up to an LED.]]></description><link>https://blog.codenamev.com/ruby-driven-raspberry-pi-buttons/</link><guid isPermaLink="false">Ghost__Post__60b97ee5b2352a001cc5d835</guid><category><![CDATA[Raspberry Pi]]></category><category><![CDATA[SunFounder Super Kit Series]]></category><dc:creator><![CDATA[Valentino Stoll]]></dc:creator><pubDate>Fri, 13 Sep 2019 21:00:00 GMT</pubDate><media:content url="https://s3.amazonaws.com/blog-codenamev-prod/2021/06/raspberry-pi-button-led-2.jpg" medium="image"/><content:encoded><![CDATA[<blockquote>This is part 2 in my <a href="https://codenamev-ghost.herokuapp.com/tag/sunfounder-super-kit/">Sunfounder Superkit series</a>.</blockquote><img src="https://s3.amazonaws.com/blog-codenamev-prod/2021/06/raspberry-pi-button-led-2.jpg" alt="Ruby driven Raspberry Pi buttons"/><p>Blinking an LED was too easy!  Let's make this piece interactive.  Buttons are exactly the magic I'm looking for.  Push it, and do <em>something.  ANYTHING</em>!  Let's keep it simple and build off of our first simple LED hookup.</p><figure class="kg-card kg-image-card kg-card-hascaption"><img src="https://s3.amazonaws.com/blog-codenamev-prod/2021/06/raspberry-pi-button-led-1.jpg" class="kg-image" alt="Ruby driven Raspberry Pi buttons" loading="lazy" width="1500" height="824"><figcaption>Wiring a button to an LED on a Raspberry Pi B+</figcaption></img></figure><p>With that in place, and a little Ruby script, we can loop in the button to join the LED blinking fun.</p><!--kg-card-begin: html--><script src="https://gist.github.com/codenamev/b19d7f57c3efca3dfdf2090c6dfe73bd.js"/><!--kg-card-end: html--><h2 id="the-great-ruby-takeaways">The Great Ruby Takeaways</h2><p>Ok, so maybe the circuit is not <em>that</em> exciting, but this is just the start!  With this we've gained some exposure to both listening in on and controlling the state of GPIO pins.  Writing this script also introduces us to some great aspects of working with Ruby programs from a lower level.</p><h3 id="io-flush-and-io-sync">IO#flush and IO#sync</h3><p>Firstly, <code><a href="https://ruby-doc.org/core-2.6.4/IO.html#method-i-flush" rel="noopener">STDOUT.flush</a></code>.  This will clear any buffered data to standard out allowing future calls to <code>puts</code> to replace what was there.  Little did I know there is <a href="https://ruby-doc.org/core-2.6.4/IO.html#method-i-sync" rel="noopener">a flag you can set on an IO instance</a> to immediately flush the output after every call with: <code>STDOUT.sync = true</code> .</p><h3 id="kernel-at_exit">Kernel#at_exit</h3><p>Ruby's Kernel comes with some great stuff for working with the command line. The fine folks over at HoneyBadger have <a href="https://www.honeybadger.io/blog/how-to-exit-a-ruby-program/">a great writeup on different ways to exit a Ruby program</a>, and some best practices. In this specific case, we can use the special <a href="https://ruby-doc.org/core-2.6.4/Kernel.html#method-i-at_exit"><code>at_exit</code></a> callback to perform some code to reset the state of our GPIO pins (so we make sure not to set any fires).</p><h3 id="interrupt-and-signalexception">Interrupt and SignalException</h3><p>Lastly, because we want to ensure that our circuit resets itself whenever the program stops running, we need a way to catch both user-initiated interrupts (a.k.a <a href="https://ruby-doc.org/core-2.6.4/Interrupt.html"><code>Interrupt</code></a> caused by a ctrl+c) and system-initiated interrupts (a.k.a. <a href="https://ruby-doc.org/core-2.6.4/SignalException.html"><code>SignalException</code></a>). While it may be more beneficial to <a href="https://www.sitepoint.com/license-to-sigkill/">trap unix signals</a>, I went with the quick and dirty.</p><p>Hopefully you learned something today. I know I did! Tune in next time when I get serious with the breadboard and jam as many LEDs in it as I can (or have patience for).</p>]]></content:encoded></item><item><title><![CDATA[Setting up a Raspberry Pi For Ruby]]></title><description><![CDATA[Get a Raspberry Pi setup for developing with Ruby and a simple circuit to blink an LED.]]></description><link>https://medium.com/@codenamev/setting-up-a-raspberry-pi-for-ruby-4824963246e8</link><guid isPermaLink="false">Ghost__Post__60b97ee5b2352a001cc5d833</guid><category><![CDATA[Raspberry Pi]]></category><category><![CDATA[ruby]]></category><category><![CDATA[SunFounder Super Kit Series]]></category><dc:creator><![CDATA[Valentino Stoll]]></dc:creator><pubDate>Wed, 04 Sep 2019 15:01:00 GMT</pubDate><media:content url="https://s3.amazonaws.com/blog-codenamev-prod/2021/06/raspberry-pi-sunfounder-kit--1-.jpeg" medium="image"/><content:encoded><![CDATA[<blockquote><strong>Updated</strong> 9/6/19: This is part 1 of my <a href="https://codenamev-ghost.herokuapp.com/tag/sunfounder-super-kit/">Sunfounder Superkit Series</a>.</blockquote><img src="https://s3.amazonaws.com/blog-codenamev-prod/2021/06/raspberry-pi-sunfounder-kit--1-.jpeg" alt="Setting up a Raspberry Pi For Ruby"/><p>Ruby comes pre-installed on Raspbian, but unfortunately is not the latest version. After a bit of headache, here’s what I learned and how to make it right.</p><p>My dream is to make a split-flap display, but since I have near-zero experience working with microcontrollers I decided to pick up Sunfounder’s Superkit (v3). To be honest, it was cheap, but also comes with lots of different components to play with. Let’s see what kind of lit experiments we can build.</p><h1 id="flashing-the-sd-card">Flashing the SD card</h1><p>I decided to use the Raspbian OS (with desktop client), just to make the learning curve easier. After downloading <a href="https://www.raspberrypi.org/downloads/">the latest image</a>, I then installed <a href="https://etcher.io/">Etcher</a> (as recommended) and this was incredibly easy to burn the image onto the micro SD.</p><h1 id="booting-up-configuration">Booting Up &amp; Configuration</h1><p>Booting up the Raspberry Pi couldn’t have been easier. Jammed the micro SD card delicately in, plugged the power cable and the HDMI, and ~1minute later I was ready to go.</p><p>First thing’s first, change the system password (because security).</p><pre><code class="language-bash">passwd</code></pre><p>One nice thing about the B+ is that you can remotely control the GPIO (more on this later). Unfortunately, both this feature, and ssh, are turned off by default. So, let’s flip the table on those bad girls.</p><ol><li>Launch <code>Raspberry Pi Configuration</code> from the <code>Preferences</code> menu</li><li>Navigate to the <code>Interfaces</code> tab</li><li>Select <code>Enabled</code> next to <code>SSH</code></li></ol><p><em><em><strong><strong>Update</strong></strong>: I’ve started a <a href="https://github.com/codenamev/ruby-pi">small repo for all my experiments</a> that includes a <a href="https://github.com/codenamev/ruby-pi/blob/master/bin/setup">handy script to automate the remaining setup</a>.</em></em></p><p>For me, the latest <code>gpio</code> software was out of date and was raising hell. Let’s start this puppy up fresh:</p><pre><code class="language-bash">sudo apt-get update &amp;&amp; sudo apt-get upgrade</code></pre><p>Boom. System configured, dependencies updated, and GPIO configured properly. Check out all the wonderful pins we get access to in the GPIO on a B+!</p><figure class="kg-card kg-image-card kg-card-hascaption"><img src="https://s3.amazonaws.com/blog-codenamev-prod/2021/06/raspberry-pi-b-plus-gpio-table--1-.png" class="kg-image" alt="Setting up a Raspberry Pi For Ruby" loading="lazy" width="1610" height="1520"><figcaption>Raspberry Pi B+ GPIO table</figcaption></img></figure><p>Ok, now Ruby time!</p><h1 id="setting-up-ruby">Setting up Ruby</h1><p>As of today (Jun 2018), Raspbian comes with Ruby pre-installed! In order to get some of the gems with native-extensions to build properly, I just <em><em>had</em> </em>to get <code>ruby-dev</code></p><pre><code class="language-bash">sudo apt-get install ruby-dev</code></pre><h1 id="finally-blinking-a-damn-led">Finally Blinking a Damn LED</h1><p>After <em><em>all</em></em> that, you should be ready to use that Pi that’s just been collecting dust all these years. Just for fun, let’s perform the staple of what to do with your shiny new micro-controller: <em><em>blinking an LED</em></em>.</p><p>With a couple jumpers, an LED, and a 220Ω resistor we can safely control the state of the LED:</p><figure class="kg-card kg-image-card kg-card-hascaption"><img src="https://s3.amazonaws.com/blog-codenamev-prod/2021/06/raspberry-pi-blinking-led--1-.jpeg" class="kg-image" alt="Setting up a Raspberry Pi For Ruby" loading="lazy" width="2000" height="1500"><figcaption>Raspberry Pi B+ blinking LED with Ruby!</figcaption></img></figure><p>All wired up, we can get it blinking with a simple ruby script:</p><!--kg-card-begin: html--><script src="https://gist.github.com/codenamev/ed044351e6446bc949052f9a2810f8a1.js"/><!--kg-card-end: html--><h1 id="wrapping-it-up">Wrapping It Up</h1><figure class="kg-card kg-image-card"><img src="https://s3.amazonaws.com/blog-codenamev-prod/2021/06/wrap-it-up.gif" class="kg-image" alt="Setting up a Raspberry Pi For Ruby" loading="lazy" width="260" height="195"/></figure><p>Alright, I get it, not <em><em>too</em></em> exciting. But hey, with this same setup I can see altering the code to, say, light up the LED when my tests fail.</p><p>You get it. Or don’t. Either way I’ll still be here documenting my dope ass crusade of micro-controlling justice.</p>]]></content:encoded></item><item><title><![CDATA[The code behind GitHub's new Code Navigation]]></title><description><![CDATA[A brief overview of how Github's Code Navigation works to help you find definitions and code references.]]></description><link>https://codenamev-ghost.herokuapp.com/the-code-behind-github-code-navigation</link><guid isPermaLink="false">Ghost__Post__60b97ee5b2352a001cc5d832</guid><category><![CDATA[dev tools]]></category><category><![CDATA[github]]></category><category><![CDATA[parsers]]></category><dc:creator><![CDATA[Valentino Stoll]]></dc:creator><pubDate>Thu, 22 Aug 2019 15:00:00 GMT</pubDate><media:content url="https://s3.amazonaws.com/blog-codenamev-prod/2021/06/jump-to-definition-tab.png" medium="image"/><content:encoded><![CDATA[<img src="https://s3.amazonaws.com/blog-codenamev-prod/2021/06/jump-to-definition-tab.png" alt="The code behind GitHub's new Code Navigation"/><p>GitHub <a href="https://help.github.com/en/articles/navigating-code-on-github">recently announced two new code navigation features</a>:</p><ol><li>Jump to definition – quickly view the source for any given method.</li><li>Find all references – Identify all references of a function within the same repo.</li></ol><p>I have been waiting a long time for these features to surface, and best of all, the code behind all this is open source!</p><p>From the top-level, they're using a Haskell library called <a href="https://github.com/github/semantic">Semantic</a>.  Semantic can <em>parse</em>, <em>analyze</em>, and <em>compare</em> source code.  As of the last update to this post, it supports Ruby, JavaScript, TypeScript, Python, Go, PHP, Java, JSON, JSX, Haskell, and Markdown. </p><p>For a full list of examples, check out the <a href="https://github.com/github/semantic/blob/master/docs/examples.md">Semantic usage docs</a>.  It comes with a great CLI that allows you to:</p><h3 id="generate-parse-trees">Generate parse trees</h3><figure class="kg-card kg-code-card"><pre><code class="language-bash">$ semantic parse test.A.py
(Statements
  (Annotation
    (Function
      (Identifier)
      (Identifier)
      (Return
        (Identifier)))
    (Empty))
  (Call
    (Identifier)
    (Call
      (Identifier)
      (TextElement)
      (Empty))
    (Empty)))</code></pre><figcaption>Generate an abstract syntax tree (AST)</figcaption></figure><h3 id="generate-syntax-aware-diffs">Generate syntax aware diffs</h3><pre><code class="language-bash">$ semantic diff test.A.py test.B.py
(Statements
  (Annotation
    (Function
    { (Identifier)
    -&gt;(Identifier) }
      (Identifier)
      (Return
        (Identifier)))
    (Empty))
  (Call
    (Identifier)
    (Call
    { (Identifier)
    -&gt;(Identifier) }
      (TextElement)
      (Empty))
    (Empty)))</code></pre><h3 id="display-import-call-graphs">Display import call graphs</h3><pre><code class="language-bash">semantic graph main.py | dot -Tsvg &gt; main.html &amp;&amp; open main.html</code></pre><figure class="kg-card kg-image-card"><img src="https://s3.amazonaws.com/blog-codenamev-prod/2021/06/import_graph.svg" class="kg-image" alt="The code behind GitHub's new Code Navigation" loading="lazy" width="389" height="173"/></figure><h3 id="display-call-graphs">Display call graphs</h3><pre><code class="language-bash">semantic graph --calls main.py | dot -Tsvg &gt; main.html &amp;&amp; open main.html</code></pre><figure class="kg-card kg-image-card"><img src="https://s3.amazonaws.com/blog-codenamev-prod/2021/06/call_graph.svg" class="kg-image" alt="The code behind GitHub's new Code Navigation" loading="lazy" width="444" height="547"/></figure><h2 id="making-sense-of-your-code">Making Sense of Your Code</h2><p>The code parsing is done with the <a href="https://github.com/tree-sitter/tree-sitter">tree-sitter</a> library which appears to be C with a handful of language bindings (<a href="https://github.com/tree-sitter/tree-sitter/tree/master/cli">the cli is in Rust</a>!).</p><blockquote>[Tree-sitter] can build a concrete syntax tree for a source file and efficiently update the syntax tree as the source file is edited</blockquote><p>Languages are supported by writing language-specific parsers.  These parsers primarily consist of two parts:</p><ol><li><strong>Grammar</strong> –  contains various rules for how the language is formatted</li><li><strong>Lexical Analysis</strong> – patterning individual character groups (for <a href="https://en.wikipedia.org/wiki/Lexical_analysis">lexing</a>).</li></ol><p>Example Grammar for parsing simple ruby methods from <a href="https://github.com/tree-sitter/tree-sitter-ruby">tree-sitter-ruby</a>:</p><figure class="kg-card kg-code-card"><pre><code class="language-grammar.json">{
  "name": "ruby",
  "word": "identifier",
  "rules": {
    "method": {
      "type": "SEQ",
      "members": [
        {
          "type": "STRING",
          "value": "def"
        },
        {
          "type": "SYMBOL",
          "name": "_method_rest"
        }
      ]
    }
  }
}</code></pre><figcaption>Ref: <a href="https://github.com/tree-sitter/tree-sitter-ruby/blob/master/src/grammar.json#L5-L46">https://github.com/tree-sitter/tree-sitter-ruby/blob/master/src/grammar.json</a></figcaption></figure><p>Tree-sitter has <a href="http://tree-sitter.github.io/tree-sitter/playground">an <em>awesome</em> Playground</a> where you can explore the parse trees it generates for any given code.</p><p>When you feed code to the Semantic library, it generates parse trees using tree-sitter, and then uses the <a href="https://github.com/github/semantic/blob/master/docs/grammar-development-guide.md">language's grammar</a> (e.g. from tree-sitter-ruby) to parse the parse trees and map AST nodes  (many of which are already available from the library itself for: <a href="https://github.com/github/semantic/blob/master/src/Data/Syntax/Literal.hs">literals</a>, <a href="https://github.com/github/semantic/blob/master/src/Data/Syntax/Expression.hs">expressions</a>, <a href="https://github.com/github/semantic/blob/master/src/Data/Syntax/Statement.hs">statements</a>, and <a href="https://github.com/github/semantic/blob/master/src/Data/Syntax/Type.hs">types</a>).</p><p>While they hope to <a href="https://github.com/github/semantic/blob/master/docs/adding-new-languages.md#faqs">drop this step in the future</a>, once the AST nodes are mapped, a second round of parsing is done to wrap them into data structures the library can comprehend (for more on this, <a href="https://github.com/github/semantic/blob/master/docs/assignment.md">see the "Assignment" documentation</a>).</p><p>There are quite a few more things that happen to <em>analyze</em> and <em>compare</em> source code, but I'll leave the explanation it to their <a href="https://github.com/github/semantic/blob/master/docs/program-analysis.md">great documentation on program analysis</a>.</p><p>Thank you GitHub!  Keep up the solid work :-)</p>]]></content:encoded></item><item><title><![CDATA[How to fix all Ruby "Failed to build gem native extension" Errors in OS X]]></title><description><![CDATA[Find how to fix those pesky "Failed to build gem native extension" errors in OS X.]]></description><link>https://blog.codenamev.com/how-to-fix-failed-to-build-gem-native-extension-error-os-x/</link><guid isPermaLink="false">Ghost__Post__60b97ee5b2352a001cc5d82f</guid><category><![CDATA[ruby]]></category><category><![CDATA[common-issues]]></category><category><![CDATA[macOS]]></category><dc:creator><![CDATA[Valentino Stoll]]></dc:creator><pubDate>Thu, 11 Jul 2019 21:00:00 GMT</pubDate><media:content url="https://s3.amazonaws.com/blog-codenamev-prod/2021/06/fixed-it-static.png" medium="image"/><content:encoded><![CDATA[<pre><code class="language-bash">cp /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg ~/Desktop &amp;&amp; open ~/Desktop/macOS_SDK_headers_for_macOS_10.14.pkg</code></pre><!--kg-card-begin: html--><video autoplay="" loop="" muted="" playsinline="">  
  <source src="https://blog-codenamev-prod.s3.amazonaws.com/2021/06/fixed-it.webm" type="video/webm">  
  <source src="https://blog-codenamev-prod.s3.amazonaws.com/2021/06/fixed-it.mp4" type="video/mp4">  
</source></source></video><!--kg-card-end: html--><img src="https://s3.amazonaws.com/blog-codenamev-prod/2021/06/fixed-it-static.png" alt="How to fix all Ruby &quot;Failed to build gem native extension&quot; Errors in OS X"/><p>Boom.  Now start removing all those pesky overrides you set in <code>~/.bundle/config</code></p><p>All credit goes to the amazing <a href="https://github.com/silvae86">João Rocha da Silva</a>.  Be sure to <a href="https://silvae86.github.io/sysadmin/mac/osx/mojave/beta/libxml2/2018/07/05/fixing-missing-headers-for-homebrew-in-mac-osx-mojave/">check out his detailed write-up</a> on why you need to do this.  TLDR; Mac OS X 10.14 no longer places the include libraries in the standard <code>/usr/include</code> directory and locked by SIP.</p>]]></content:encoded></item><item><title><![CDATA[New git-reflow release: Custom Git Workflows]]></title><description><![CDATA[This release includes the culmination of several years of effort to allow you to customize our process to suit your specific needs. We've dropped a heavy dependency and introduced a new command DSL…]]></description><link>https://blog.codenamev.com/git-reflow-workflows/</link><guid isPermaLink="false">Ghost__Post__60b97ee5b2352a001cc5d82c</guid><category><![CDATA[git]]></category><category><![CDATA[git-reflow]]></category><category><![CDATA[github]]></category><category><![CDATA[workflows]]></category><category><![CDATA[ruby]]></category><dc:creator><![CDATA[Valentino Stoll]]></dc:creator><pubDate>Sat, 10 Nov 2018 21:16:06 GMT</pubDate><media:content url="https://s3.amazonaws.com/blog-codenamev-prod/2021/06/reflow-workflows-header.jpeg" medium="image"/><content:encoded><![CDATA[<img src="https://s3.amazonaws.com/blog-codenamev-prod/2021/06/reflow-workflows-header.jpeg" alt="New git-reflow release: Custom Git Workflows"/><p>This release includes the culmination of several years of effort to allow you to customize our process to suit your specific needs. We’ve dropped a heavy dependency (<code>gli</code>) and introduced a pretty slick DSL for creating new git commands or override our existing ones.</p><p>I am really excited to announce the released version 0.9.0 of the <a href="https://github.com/reenhanced/gitreflow"><code>git_reflow</code> gem</a>!</p><h3 id="custom-workflows">Custom Workflows</h3><p>Git-reflow’s default process isn’t meant to fit every team, which is why we’ve introduced <code>Workflows</code>.</p><p>We’ve introduced a special file that can contain customizations to the default process. With this, you can:</p><p>1. Add hooks to be run before, or after any command<br>2. Use one of our pre-configured workflows as a basis for your own<br>3. Override any of the default commands<br>4. Create new commands</br></br></br></p><p>You can define a unique workflow for each of your projects simply by placing it in the root of your project, or by setting a special <code>reflow.workflow</code> git-config setting with the full path of the file.</p><p>Here is an example showcasing all the various ways you can customize the process:</p><!--kg-card-begin: html--><script src="https://gist.github.com/codenamev/e74b730fcedaa53df8ae8532d5a4b125.js"/><!--kg-card-end: html--><p>The block that you pass to each of the git-reflow reserved commands (<code>use</code>, <code>before</code>, <code>after</code>, <code>command</code>) are executed in the context of our <a href="https://github.com/reenhanced/gitreflow/blob/master/lib/git_reflow/workflows/core.rb" rel="nofollow noopener">Core workflow class</a>. This gives you the ability to use any code available to the <code>GitReflow</code> module. We encourage you to use as much of GitReflow’s tooling as possible so that you can take full advantage of getting the current branch name, logging, exception-handling, colorized output, and several other features that are baked into GitReflow’s internals. For a full list of what’s available, see <a href="https://github.com/reenhanced/gitreflow/wiki/Custom-Workflows#available-workflow-helpers" rel="nofollow noopener">Available Workflow Helpers</a> on our wiki.</p><h3 id="ramping-up-to-1-0">Ramping Up To 1.0</h3><p>With the re-workings of <code>Workflows</code> in place, we’re getting ready for our first major release! Our current plans are to focus on:</p><ol><li>Introduce Pivotal Tracker &amp; Trello workflows</li><li>Add GitLab integration</li><li>Add an Open Source workflow</li></ol><p>We’re looking forward to some exciting times! We’d love to hear all the interesting ways you use these new workflows, so please don’t hesitate to let us know.</p><p>Happy hacking!</p>]]></content:encoded></item></channel></rss>