<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="3.10.0">Jekyll</generator><link href="https://brokenco.de//feed/by_tag/ruby.xml" rel="self" type="application/atom+xml" /><link href="https://brokenco.de//" rel="alternate" type="text/html" /><updated>2026-07-12T13:39:01+00:00</updated><id>https://brokenco.de//feed/by_tag/ruby.xml</id><title type="html">rtyler</title><subtitle>a moderately technical blog</subtitle><author><name>R. Tyler Croy</name></author><entry><title type="html">Ruby Infrastructure Engineering</title><link href="https://brokenco.de//2019/09/09/rubby-infra.html" rel="alternate" type="text/html" title="Ruby Infrastructure Engineering" /><published>2019-09-09T00:00:00+00:00</published><updated>2019-09-09T00:00:00+00:00</updated><id>https://brokenco.de//2019/09/09/rubby-infra</id><content type="html" xml:base="https://brokenco.de//2019/09/09/rubby-infra.html"><![CDATA[<p>My favorite part of the stack is the netherworld between the underlying
infrastructure and the app. That fuzzy grey area where data goes from databases
to object-relational mappers (ORMs), web servers to request libraries (e.g.
Rack/WSGI), and so on. In many cases a technology roadmap where one considers
infrastructure, but not the application, or vice-versa, is doomed from the
start. At Scribd, I have been given permission to hire more people that love
this layer of the stack, and I have taken to calling it “Ruby Infrastructure.”
A phrase which is fairly unique, that I wanted to define in greater detail.</p>

<p>I have described the general mission of <a href="https://jobs.lever.co/scribd/6fff482b-6363-4525-b6b0-6131d6994eef">the
team</a> as
follows:</p>

<blockquote>
  <p>The Ruby Infrastructure team will help Scribd adopt major ecosystem
improvements such as Sorbet, new Rails versions, and interpreter releases.
Measure and optimize performance across the thousands of requests per second
served by Ruby at Scribd. Create libraries that encapsulate common Ruby
application patterns and approaches. Open high quality pull requests to
improve upstream projects like Sidekiq, Rails, and Ruby itself.</p>
</blockquote>

<p>Ruby at Scribd is serious business. We run one of the largest Rails deployments
on the internet (hi
<a href="https://github.blog/2019-09-09-running-github-on-rails-6-0/">GitHub</a>!) and
need more focused effort on scaling it from a technology and organization
standpoint. The Ruby ecosystem has also matured greatly over the past 10 years
and every couple of months there are new improvements which Scribd can adopt.</p>

<p>The Ruby Infrastructure team is intended to be the group of people which make
sure that all our Ruby and Rails applications are performing well, scaling, and
are easy to develop and deploy.</p>

<p>To give you a better idea of what this team will do, here are some of the
projects which I have in mind:</p>

<h3 id="simplify-with-aurora">Simplify with Aurora</h3>

<p>We have over 7TB of online relational data which, for historical reasons, is
spread across a number of master-replica clusters. Migrating these databases
to, and adopting <a href="https://aws.amazon.com/rds/aurora/#">RDS/Aurora</a> looks very
promising. The advertised read-performance and dataset storage scalability may
allow us to consolidate the database infrastructure and allow us to delete swaths
of complex database magic in the applications.</p>

<p>All that code for switching up database connections or delegating reads to
read-replicas <em>may</em> disappear behind the curtains of Aurora. We certainly need
to do some investigation here, but this is a pristine example of that grey area
where the Ruby Infrastructure team will excel.</p>

<h3 id="web-socketin">Web Socketin’</h3>

<p>Enabling Web Sockets on smaller applications is trivially easy these days. For
larger sites like <a href="https://scribd.com/">Scribd.com</a> a large number of variables
need to be considered: do we terminate sockets in Rails? What will an
incredibly high connection count do to our existing app infrastructure? How
will application developers write code which supports Web Sockets and their
existing request flows? Does our app host capacity plan change dramatically as
a result?</p>

<p>Seemingly mundane requests like “can we enable web sockets?” from application
developers or product managers, at the scale of billions of requests per month,
can have far reaching implications that the Ruby Infrastructure team is poised
perfectly to answer.</p>

<h3 id="efficient-host-sizing">Efficient Host Sizing</h3>

<p>Our current infrastructure is at times over-provisioned. The specifics I won’t
get into in this post, but there are a lot of low-hanging fruit in understanding
our existing application footprints and then sizing our infrastructure around
them appropriately. Whether we’re talking about understanding or improving our
<a href="https://www.joyfulbikeshedding.com/blog/2019-03-29-the-status-of-ruby-memory-trimming-and-how-you-can-help-with-testing.html">memory
utilization</a>,
or becoming more elastic around CPU utilization. Building an overall
understanding of how these Ruby applications perform, how to tune them, and how
to structure their resource usage is going to be one of the frequently
re-evaluated projects for Ruby Infrastructure.</p>

<hr />

<p>There are a myriad of other interesting projects which will crop up once a
couple <a href="https://jobs.lever.co/scribd/6fff482b-6363-4525-b6b0-6131d6994eef">Ruby Infrastructure
Engineers</a>
join the company. Like the other teams in <a href="/2019/08/22/platform-engineering-at-scribd.html">Platform
Engineering</a>, this team will
be entirely remote which means we can  hire the most qualified people we’re
able to find, from nearly anywhere.</p>

<p>I’m excited to see the upstream pull requests, RailsConf presentations, and blog
posts that we’re going to be able to share once we start solving problems
together!</p>]]></content><author><name>R. Tyler Croy</name></author><category term="ruby" /><category term="scribd" /><summary type="html"><![CDATA[My favorite part of the stack is the netherworld between the underlying infrastructure and the app. That fuzzy grey area where data goes from databases to object-relational mappers (ORMs), web servers to request libraries (e.g. Rack/WSGI), and so on. In many cases a technology roadmap where one considers infrastructure, but not the application, or vice-versa, is doomed from the start. At Scribd, I have been given permission to hire more people that love this layer of the stack, and I have taken to calling it “Ruby Infrastructure.” A phrase which is fairly unique, that I wanted to define in greater detail.]]></summary></entry><entry><title type="html">JRuby demos from the JavaOne Script Bowl 2014</title><link href="https://brokenco.de//2014/11/02/javaone-jruby-demos.html" rel="alternate" type="text/html" title="JRuby demos from the JavaOne Script Bowl 2014" /><published>2014-11-02T00:00:00+00:00</published><updated>2014-11-02T00:00:00+00:00</updated><id>https://brokenco.de//2014/11/02/javaone-jruby-demos</id><content type="html" xml:base="https://brokenco.de//2014/11/02/javaone-jruby-demos.html"><![CDATA[<p>This past October I was invited to represent <a href="http://jruby.org">JRuby</a> in the
JavaOne 2014 “Script Bowl.” A panel where community members from various
projects which implement scripting languages on top of the JVM pitch their
language to a live studio audience. This year’s panel consisted of a members
from the Groovy, Clojure and Scala communities, and me representing JRuby of
course.</p>

<p>The session consists of two segments, historically with one focusing on
the capabilities of the language itself and the second segment focusing on the
community built around the scripting language.</p>

<p>Instead of choosing to create a presentation, I took the road less traveled and
created a series of live coding demos to demonstrate the utility of JRuby.</p>

<p>The collection of demos that I created can be found in this <a href="https://github.com/rtyler/javaone-jruby-demo">demo
repository</a>. For all of my demos
I used <a href="http://pryrepl.org">Pry</a> as a live JRuby interpreter to load and
execute Java and Ruby code on the fly, which I hope made for a compelling
presentation.</p>

<p>The following are the demos worth mentioning here:</p>

<h3 id="ascii-table-from-jar">ascii table from jar</h3>

<p>In <a href="https://github.com/rtyler/javaone-jruby-demo/blob/master/ascii-table-from-jar.rb">this
demo</a>
I had grabbed some random Java code from the internet to print ascii-only
formatted tables, and wrote some Ruby glue to make use of it. Copying and
pasting this code into a running Pry session and you’ll get a nice table drawn
in your console.</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>[16] pry(main)&gt; puts make_table(headers, mails)
+-----------------------------+--------------------------+
|           Subject           |           From           |
+-----------------------------+--------------------------+
|         NOT SPAM WE PROMISE | sirspamsalot@hotmail.com |
| Important work related info |     yourboss@example.com |
|       Don't forget the milk |         spouse@family.io |
+-----------------------------+--------------------------+
=&gt; nil
[17] pry(main)&gt;
</code></pre></div></div>

<h3 id="anonymous-classes">anonymous classes</h3>

<p><a href="https://github.com/rtyler/javaone-jruby-demo/blob/master/anonymous-classes.rb">This
demo</a>
demonstrates how JRuby merges the use of <a href="http://docs.oracle.com/javase/tutorial/java/javaOO/anonymousclasses.html">anonymous
classes</a>
in Java with Ruby’s concept of blocks. Instead of creating an anonymous class
that implements the <code class="language-plaintext highlighter-rouge">Runnable</code> interface, we can just use pass a block of code
to be executed inside of a <code class="language-plaintext highlighter-rouge">java.lang.Thread</code>.</p>

<h3 id="turtles">“turtles”</h3>

<p>This might be <a href="https://github.com/rtyler/javaone-jruby-demo/tree/master/turtles">my favorite
demo</a> because
it demonstrates one of the more compelling (to me) features of JRuby, it’s
embeddability. In the “turtles” demo, I’ve got an entirely embedded and
separate Ruby runtime environment, nested within an already existing Ruby
runtime.</p>

<p>The result is that I can create isolated Ruby environments within the same JVM,
which opens the door to all kinds of interesting sandboxing applications.</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>[44] pry(main)&gt; require './turtles/first'
=&gt; true
[45] pry(main)&gt; puts "Our original JRuby has version: #{JavaOne::VERSION}".colorize(:magenta)
Our original JRuby has version: 1
=&gt; nil
[46] pry(main)&gt; puts

=&gt; nil
[47] pry(main)&gt; # Now let's load a the same module with a different version inside the runtime environment
[48] pry(main)&gt; evaler.eval(runtime, "require './turtles/second'"); nil
=&gt; nil
[49] pry(main)&gt; evaler.eval(runtime, "puts \"Our embedded JRuby has version: \#{JavaOne::VERSION}\".colorize(:green)"); nil
Our embedded JRuby has version: 2
=&gt; nil
[50] pry(main)&gt;
</code></pre></div></div>

<h3 id="jruby-gradle">jruby-gradle</h3>

<p>The final <a href="https://github.com/rtyler/javaone-jruby-demo/tree/master/jruby-gradle-example">demo that I
gave</a>
is a little self-promiting, in that I demonstrated the capabilities of the
<a href="https://github.com/jruby-gradle">jruby-gradle</a> project. A project which allows
you to use the <a href="http://gradle.org">Gradle</a> tool for managing projects,
obviating the need for Bundler, JBundler, Warbler and RVM.</p>

<p>During the demo I showed the
<a href="https://github.com/rtyler/javaone-jruby-demo/blob/master/jruby-gradle-example/build.gradle">build.gradle</a>
file which references a Ruby gem and demonstrated how to build a
self-contained, self-executing <code class="language-plaintext highlighter-rouge">.jar</code> file with the tool:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>% ./gradlew shadowJar
</code></pre></div></div>

<p>Then executed it:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>% java -jar build/libs/jruby-gradle-example-all.jar
REQUIRED RELATIVE
Hello from JRuby built with Gradle!
%
</code></pre></div></div>

<p>That is a jar file, running Java and Ruby code all from within the file, pretty
spiffy if you ask me!</p>

<hr />

<p>Predictably, JRuby didn’t win the Script Bowl, unpredictably Clojure did. The
event was enjoyable, but for me my favorite part was creating the demos and
honing my pitch for JRuby, which I’m sure I’ll have the opportunity to reuse in
the future.</p>]]></content><author><name>R. Tyler Croy</name></author><category term="ruby" /><category term="jruby" /><category term="javaone" /><summary type="html"><![CDATA[This past October I was invited to represent JRuby in the JavaOne 2014 “Script Bowl.” A panel where community members from various projects which implement scripting languages on top of the JVM pitch their language to a live studio audience. This year’s panel consisted of a members from the Groovy, Clojure and Scala communities, and me representing JRuby of course.]]></summary></entry><entry><title type="html">Catch me at JRubyConf EU 2014</title><link href="https://brokenco.de//2014/07/06/catch-me-at-jrubyconfeu-2014.html" rel="alternate" type="text/html" title="Catch me at JRubyConf EU 2014" /><published>2014-07-06T00:00:00+00:00</published><updated>2014-07-06T00:00:00+00:00</updated><id>https://brokenco.de//2014/07/06/catch-me-at-jrubyconfeu-2014</id><content type="html" xml:base="https://brokenco.de//2014/07/06/catch-me-at-jrubyconfeu-2014.html"><![CDATA[<p>This has already been posted on the <a href="http://hackers.lookout.com/2014/07/join-us-at-jrubyconfeu">Lookout hackers
blog</a> but I figured
I would repost on my personal blog in lieu of actual content.</p>

<p>My colleague <a href="https://github.com/ismith">Ian Smith</a> and I will be presenting a
talk at <a href="http://2014.jrubyconf.eu/">JRubyConf EU 2014</a> titled:</p>

<blockquote>
  <p><strong>Building a scalable messaging fabric with JRuby and Storm</strong>.</p>
</blockquote>

<p>The abstract can be found below, but since this is my personal blog I’d like to
expand a bit more on why we’re giving the talk.</p>

<p>Last year my team and I deployed <a href="http://activemq.apache.org">ActiveMQ</a> in
order to provide an inter-service messaging bus between a new product we were
developing and some legacy infrastructure at <a href="http://www.lookout.com/about/careers/">Lookout</a>.
Alongside ActiveMQ we deployed a number of different worker daemons to consume
and dispatch messages. These were <a href="http://jruby.org">JRuby</a>-based processes
that polled a <a href="http://stomp.github.io/">STOMP</a> connection for new messages and
then performed some amount of “work.”</p>

<p>In the process of building out all of this infrastructure we learned a couple
of important lessons:</p>

<ul>
  <li>ActiveMQ scales like MySQL. That is to say it kind of <em>doesn’t</em> scale, the
most effective way to scale out a number of ActiveMQ brokers is to perform
some amount of application-layer “sharding” across message brokers. We did
not do ActiveMQ any favors in attempting to scale it out effectively, so minus one
point us.</li>
  <li>Many of our problems became less of shoveling work from a single app server
into a work-queue, where tools like <a href="http://sidekiq.com">Sidekiq</a> excel, and
more about complex message routing and processing, which
<a href="https://storm.incubator.apache.org/">Storm</a> was built specifically to solve for.</li>
  <li>If you provide a good stream of events, everybody, <strong>everybody</strong> will want
to take part in it. One of the unexpected results of deploying ActiveMQ and
some messaging facilities was that nearly every team in the company then wanted
to take part in the event streams. This wouldn’t have been a problem if we
had planned to become the “messaging team” or even had a roadmap to scale out
the deployment and managing of messaging infrastructure with ActiveMQ+STOMP.
Alas, we did not, and quickly ran into scaling challenges both technically and
organizationally.</li>
</ul>

<p>In our talk, Ian and I will discuss some of these lessons coming from our “old
messaging infrastructure” along with some of the important lessons that we’ve
learned moving to the newer system. Naturally, neither Storm nor
<a href="http://kafka.apache.org">Kafka</a> are silver bullets for scalability, but
I believe that they’re the right path to moving towards a broader Lookout-wide
messaging fabric.</p>

<p>As previously mentioned, this talk will be at <a href="http://2014.jrubyconfeu.org">JRubyConf
EU</a> which will be held <strong>August 1st</strong> in Potsdam,
Germany. We hope to see you there!</p>

<h4 id="abstract">Abstract</h4>

<blockquote>
  <p>As Lookout has grown the number of backend Ruby services the need for
reliable, asynchronous service-to-service messaging has gone from “nice to
have” to “absolute requirement.”</p>

  <p>Our first attempts included some names you may be familiar with: <a href="http://activemq.apache.org/">ActiveMQ</a>,
<a href="https://github.com/resque/resque">Resque</a>, <a href="http://redis.io">Redis</a>, and
<a href="http://sidekiq.org/">Sidekiq</a>. As our infrastructure grew, we found we were
reinventing many of the concepts “Storm,” an open source real-time
computation/stream-processing system, was specifically designed to handle such
as message routing, durability, streaming from multiple inputs, delivering to
multiple outputs, etc.</p>

  <p>In this talk we’ll cover how we built a scalable service-to-service messaging
fabric on top of Storm and Kafka, with <a href="http://jruby.org">JRuby</a> playing a starring role.</p>
</blockquote>]]></content><author><name>R. Tyler Croy</name></author><category term="ruby" /><category term="jruby" /><summary type="html"><![CDATA[This has already been posted on the Lookout hackers blog but I figured I would repost on my personal blog in lieu of actual content.]]></summary></entry><entry><title type="html">About the Lookout Hackers Blog</title><link href="https://brokenco.de//2012/05/22/lookout-hackers.html" rel="alternate" type="text/html" title="About the Lookout Hackers Blog" /><published>2012-05-22T00:00:00+00:00</published><updated>2012-05-22T00:00:00+00:00</updated><id>https://brokenco.de//2012/05/22/lookout-hackers</id><content type="html" xml:base="https://brokenco.de//2012/05/22/lookout-hackers.html"><![CDATA[<p>I’ve neglected cross-posting some of the articles I’ve written over the past
month or so for the newly inaugurated <a href="http://hackers.mylookout.com/">Lookout Hackers
blog</a>. The generally idea of the Hackers blog is
to give Lookout Engineering a bit clearer of a voice and an avenue to publish
blog posts on things that are nitty-gritty and technical.</p>

<p>A couple of the posts I’ve written which may interest you are:</p>

<ul>
  <li>
    <p><a href="http://hackers.mylookout.com/2012/04/integration-testing-with-foreman">Integration Testing with Foreman</a></p>

    <p><em>At Lookout we find ourselves building more and more APIs and backend
  services these days. Naturally we would like to be certain that everything will
  work fine and dandy once it has been deployed. The reality of building out a
  service-oriented architecture is that you not only have to expect failure to
  happen, you have to plan and test for it.</em></p>
  </li>
  <li>
    <p><a href="http://hackers.mylookout.com/2012/05/continuous-deployment-for-gems">Continuous Deployment for Ruby Gems</a></p>

    <p><em>With the above workflow and these conventions in place, we’ve reaped a
  couple of benefits, the most obvious one has been the severely reduced time it
  takes for new gems to be created and incorporated into production systems.
  At a higher level, we’ve gained more confidence in our gems with this emphasis
  on testing, traceability and code review baked into the process from the start.</em></p>
  </li>
</ul>

<p>The blog is still fairly young, and we’re getting more developers used to
writing blog posts for it. You can subscribe to the <a href="http://feeds.feedburner.com/LookoutHackersBlog">atom feed
here</a> or just follow
<a href="https://twitter.com/lookouteng">@LookoutEng</a> on Twitter.</p>]]></content><author><name>R. Tyler Croy</name></author><category term="lookout" /><category term="ruby" /><category term="devops" /><summary type="html"><![CDATA[I’ve neglected cross-posting some of the articles I’ve written over the past month or so for the newly inaugurated Lookout Hackers blog. The generally idea of the Hackers blog is to give Lookout Engineering a bit clearer of a voice and an avenue to publish blog posts on things that are nitty-gritty and technical.]]></summary></entry><entry><title type="html">Introducing the Vagrant plugin for Jenkins</title><link href="https://brokenco.de//2012/03/13/introducing-the-vagrant-plugin.html" rel="alternate" type="text/html" title="Introducing the Vagrant plugin for Jenkins" /><published>2012-03-13T00:00:00+00:00</published><updated>2012-03-13T00:00:00+00:00</updated><id>https://brokenco.de//2012/03/13/introducing-the-vagrant-plugin</id><content type="html" xml:base="https://brokenco.de//2012/03/13/introducing-the-vagrant-plugin.html"><![CDATA[<p><em>Look! A <a href="http://unethicalblogger.com/2012/03/13/vagrant-plugin-in-action.html">screencast of the plugin in
action!</a></em></p>

<p>The impossible has happened. Not only have I written a plugin for Jenkins, I’ve
<em>released</em> it. An event I’ve long avoided has finally come to pass, mostly
thanks to the fantastic <a href="https://wiki.jenkins-ci.org/display/JENKINS/Jenkins+plugin+development+in+Ruby">Ruby plugin development
support</a>
developed largley by <a href="https://github.com/cowboyd">Charles Lowell</a>.</p>

<center><img src="http://agentdero.cachefly.net/scratch/vagrant-plugin-0.0.3.png" alt="Vagrant plugin" /></center>

<p>The Vagrant plugin is still fairly new, and “beta” tested. Thus far I’ve
modeled it after the fantastic <a href="https://wiki.jenkins-ci.org/display/JENKINS/Android+Emulator+Plugin">Android Emulator
plugin</a> in
that it will bring up a Vagrant VM for the duration of the job, and then
destroy it afterwards.</p>

<p>As you can see, the Vagrant plugin adds a couple new build steps to the
configure page. One thing to note is that the
<a href="http://vagrantup.com/docs/provisioners.html">provisioning</a> is operated as a
separate step, instead of bundled in with the boot of the Vagrant machine. This
is purposeful, to allow any additional set up of the environment prior to
running Puppet or Chef.</p>

<p>The plugin does of course expect that you have a functional VirtualBox
environment on the slave you’re running the job on, if you don’t, Vagrant will
explode with a fantastic stack-trace and probably burn your house down.</p>

<h4 id="in-the-near-future">In the near future</h4>

<p>I’m thinking about bundling
<a href="https://github.com/t9md/vagrant-snap">vagrant-snap</a> with the plugin to allow
fancy snapshotting support, but I’m not sure of a good definite usecase for
that just yet.</p>

<p>If there’s anything you’d like to see, please file a request on the <a href="https://github.com/rtyler/vagrant-plugin/issues">GitHub
issues page</a>.</p>

<hr />

<p>You can find the plugin:</p>

<ul>
  <li>in your Jenkins “Manage Plugins” page :)</li>
  <li><a href="https://github.com/rtyler/vagrant-plugin">on GitHub</a></li>
  <li><a href="https://wiki.jenkins-ci.org/display/JENKINS/Vagrant+Plugin">on the Jenkins wiki</a></li>
</ul>

<p><strong>Enjoy!</strong></p>

<p><strong>NOTE:</strong> Be sure to grab version 0.1.2 or later!</p>]]></content><author><name>R. Tyler Croy</name></author><category term="vagrant" /><category term="jenkinsci" /><category term="ruby" /><summary type="html"><![CDATA[Look! A screencast of the plugin in action!]]></summary></entry><entry><title type="html">How is Ruby built?</title><link href="https://brokenco.de//2011/12/26/how-is-ruby-built.html" rel="alternate" type="text/html" title="How is Ruby built?" /><published>2011-12-26T00:00:00+00:00</published><updated>2011-12-26T00:00:00+00:00</updated><id>https://brokenco.de//2011/12/26/how-is-ruby-built</id><content type="html" xml:base="https://brokenco.de//2011/12/26/how-is-ruby-built.html"><![CDATA[<p><strong>Note:</strong> This is a rant, I’m not actually going to explain anything of use</p>

<hr />

<p>For a rather long time, I’ve used <a href="http://clang.llvm.org/">clang</a> on my Linux
machine as the default value of the <code class="language-plaintext highlighter-rouge">$CC</code> environment variable. I’ve simply
found it to be a faster and more friendly compiler to work with than the
default <code class="language-plaintext highlighter-rouge">gcc</code>.</p>

<p>When I first came to Ruby, I tried building Ruby 1.8.7 with clang and it failed
<em>utterly</em>. After bitching on Twitter, as I’m prone to doing, <a href="http://timetobleed.com">Joe
Damato</a> pointed out that Ruby 1.8 isn’t really valid
C. Instead it is a hodge podge of macros, C code, assembly and tears.</p>

<p>I later found out that Ruby 1.9 seems to cope with being built with <code class="language-plaintext highlighter-rouge">clang</code>
properly, so I built a couple of <a href="https://rvm.beginrescueend.com/">1.9 variants with
RVM</a> for my personal projects.</p>

<p>Everything was all fine and good until <a href="https://gist.github.com/1521970A">I tried building a native extension for
a 1.9 Ruby:</a></p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>make
compiling em.cpp
cc1plus: warning: command line option ‘-Wdeclaration-after-statement’ is valid for C/ObjC but not for C++ [enabled by default]
cc1plus: error: unrecognized command line option ‘-Wshorten-64-to-32’
cc1plus: warning: command line option ‘-Wimplicit-function-declaration’ is valid for C/ObjC but not for C++ [enabled by default]
make: *** [em.o] Error 1
</code></pre></div></div>

<p>I lost <strong>hours</strong> trying to figure out what the hell was going on here. I was
convinced for hours that EventMachine (the gem being built here) had a bug in
it. Then I was convinced that RVM had a bug in it, but I finally landed on
Ruby’s build system itself.</p>

<p>I should point out that the warning <code class="language-plaintext highlighter-rouge">shorten-64-to-32</code> only exists in patched
versions of compilers shipped with Mac OS X. It <em>certainly</em> doesn’t exist on
any compiler on Linux, so where the hell did this flag come from?</p>

<p>Somehow, and arriving at this “somehow” took me a number of miserable hours,
the difference between using <code class="language-plaintext highlighter-rouge">clang(1)</code> and <code class="language-plaintext highlighter-rouge">gcc(1)</code> to build Ruby resulted in
a single nonsense <code class="language-plaintext highlighter-rouge">CXXFLAGS</code> value which didn’t come back to bite me until I
tried to build a native extension.</p>

<p>How the shit does Ruby get built!?</p>]]></content><author><name>R. Tyler Croy</name></author><category term="ruby" /><category term="wtf" /><category term="opinion" /><summary type="html"><![CDATA[Note: This is a rant, I’m not actually going to explain anything of use]]></summary></entry><entry><title type="html">Keeping ri useful, still</title><link href="https://brokenco.de//2011/11/20/keeping-ri-useful-still.html" rel="alternate" type="text/html" title="Keeping ri useful, still" /><published>2011-11-20T00:00:00+00:00</published><updated>2011-11-20T00:00:00+00:00</updated><id>https://brokenco.de//2011/11/20/keeping-ri-useful-still</id><content type="html" xml:base="https://brokenco.de//2011/11/20/keeping-ri-useful-still.html"><![CDATA[<p>A couple months ago <a href="/2011/09/01/making-ri-useful.html">I posted some tips</a> on
making the <a href="http://www.caliban.org/ruby/rubyguide.shtml#ri">ri</a> a bit more
useful.</p>

<p>In the post I mention how installations of anything lower than Ruby 1.9.2 need
special treatment in order to make <code class="language-plaintext highlighter-rouge">ri</code> usable on a day-to-day basis.</p>

<p>For my side-projects, I’ve been using Ruby 1.9.2, so imagine my surprise when I
ran the following command:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>-&gt; % ri Random
Nothing known about Random
-&gt; %
</code></pre></div></div>

<p>In order to manage swapping between Ruby 1.8 for work and Ruby 1.9 for play,
I’ve been using the tool <a href="https://rvm.beginrescueend.com/">rvm</a> to manage local
installations of multiple rubies.</p>

<p>As [bad] luck would have it, <code class="language-plaintext highlighter-rouge">rvm install ruby-1.9.2</code> by default doesn’t
generate any of the standard library documentation, which will leave you with a
marginally useful <code class="language-plaintext highlighter-rouge">ri</code> as shown above.</p>

<p>The remedy for this is quite simple, re-run the installation command with the
<code class="language-plaintext highlighter-rouge">--docs</code> flag:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>-&gt; % rvm install ruby-1.9.2 --docs
  ... # configuring
  ... # installing
  Attempting to generate ri documentation...
  Install of ruby-1.9.2-p290 - #complete 
-&gt; %
</code></pre></div></div>

<p>Ta-da! Proper local documentation for the standard library.</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>-&gt; % ri Random
Random &lt; Object

# --- etc

-&gt; %
</code></pre></div></div>]]></content><author><name>R. Tyler Croy</name></author><category term="ri" /><category term="ruby" /><category term="documentation" /><category term="rdoc" /><summary type="html"><![CDATA[A couple months ago I posted some tips on making the ri a bit more useful.]]></summary></entry><entry><title type="html">The only problem with cucumber</title><link href="https://brokenco.de//2011/11/16/cukes-make-me-pukes.html" rel="alternate" type="text/html" title="The only problem with cucumber" /><published>2011-11-16T00:00:00+00:00</published><updated>2011-11-16T00:00:00+00:00</updated><id>https://brokenco.de//2011/11/16/cukes-make-me-pukes</id><content type="html" xml:base="https://brokenco.de//2011/11/16/cukes-make-me-pukes.html"><![CDATA[<p>I have been exploring the wide world of <a href="https://en.wikipedia.org/wiki/Behavior_Driven_Development">Behavior Driven
Development</a> lately
with <a href="http://cukes.info">Cucumber</a>. For the longest time I’ve been fascinated
with Cucumber from a conceptual standpoint; a written-word testing framework,
do go on! I’m quite pleased to finally be able to put it to good use with some
recent <a href="https://github.com/rtyler/jenkins-selenium-tests">projects</a> that I’ve been working on.</p>

<p>The <strong>only</strong> downside I’ve found, thus far for Cucumber comes down to the
use of the term “cukes” to describe Cucumber-based tests.</p>

<p>The word “cuke” or “cukes” simply has an unpleasant, wretched feeling to it. It
sounds like something unpleasant to get on your shoes. I really do not like
this word.</p>

<p>As such, I will henceforth refer to Cucumber-based tests as “<em>gherkins</em>” instead.</p>

<p>I look forward to writing plenty of posts in the future about creating high
quality gherkins for browser testing and cross-system testing, stay tuned!</p>

<hr />

<p>(I sure have been complaining about names a lot lately haven’t I?)</p>]]></content><author><name>R. Tyler Croy</name></author><category term="cucumber" /><category term="ruby" /><category term="programming" /><category term="opinion" /><summary type="html"><![CDATA[I have been exploring the wide world of Behavior Driven Development lately with Cucumber. For the longest time I’ve been fascinated with Cucumber from a conceptual standpoint; a written-word testing framework, do go on! I’m quite pleased to finally be able to put it to good use with some recent projects that I’ve been working on.]]></summary></entry><entry><title type="html">Inside ActiveRecord Joins, a quick note</title><link href="https://brokenco.de//2011/11/15/inside-activerecord-joins.html" rel="alternate" type="text/html" title="Inside ActiveRecord Joins, a quick note" /><published>2011-11-15T00:00:00+00:00</published><updated>2011-11-15T00:00:00+00:00</updated><id>https://brokenco.de//2011/11/15/inside-activerecord-joins</id><content type="html" xml:base="https://brokenco.de//2011/11/15/inside-activerecord-joins.html"><![CDATA[<p>There was once a time when I prided myself on my ignorance of SQL Joins,
foolishly proclaiming “if I need to use a JOIN, I’ve already screwed up.”</p>

<p>I’ve slightly changed my opinions since then, mostly because I can no longer
afford to avoid JOINs. Sometimes harsh reality is the best cure for young
idealism.</p>

<p>Anywho, what was my point again about joins?</p>

<p>Ah yes, joins in <a href="http://rubygems.org/gems/activerecord">ActiveRecord</a>. While
ActiveRecord is a very solid ORM gem for Ruby, it is not without it’s quirks.
Most of which come down to “magic” behavior or defaults you’ve assumed
incorrectly. As much as I would like to pontificate on the odd <code class="language-plaintext highlighter-rouge">method_missing</code>
magic ActiveRecord developers seem to love, this post is more about the latter.</p>

<p>In general, JOINs involve two tables, JOINing together the tables typically for
a nested query of some form or fashion. For an example, let’s use this make believe query:</p>

<figure class="highlight"><pre><code class="language-sql" data-lang="sql">    <span class="k">SELECT</span> <span class="nv">`guests`</span><span class="p">.</span><span class="o">*</span> <span class="k">FROM</span> <span class="nv">`guests`</span> <span class="k">JOIN</span> <span class="nv">`plates`</span> <span class="err">\</span>
        <span class="k">ON</span> <span class="n">plates</span><span class="p">.</span><span class="n">guest_id</span> <span class="o">=</span> <span class="n">guests</span><span class="p">.</span><span class="n">id</span> <span class="k">WHERE</span> <span class="err">\</span>
        <span class="p">(</span><span class="n">guests</span><span class="p">.</span><span class="n">favorite</span> <span class="o">=</span> <span class="s1">'sushi'</span> <span class="k">OR</span> <span class="n">plates</span><span class="p">.</span><span class="n">content</span> <span class="o">=</span> <span class="s1">'sushi'</span><span class="p">);</span></code></pre></figure>

<p>There are five basic JOINs in SQL land, and in this context they mean:</p>

<ul>
  <li><strong>LEFT JOIN</strong>: Find all the rows in <code class="language-plaintext highlighter-rouge">guests</code>, even if they don’t have a corresponding <code class="language-plaintext highlighter-rouge">plates</code> row, then apply sub-query.</li>
  <li><strong>RIGHT JOIN</strong>: Find all rows in <code class="language-plaintext highlighter-rouge">plates</code>, even if they don’t have a corresponding <code class="language-plaintext highlighter-rouge">guests</code> row, then apply sub-query.</li>
  <li><strong>INNER JOIN</strong>: Find rows <em>only</em> if <code class="language-plaintext highlighter-rouge">guests</code> has a corresponding <code class="language-plaintext highlighter-rouge">plates</code> row.</li>
  <li><strong>STRAIGHT JOIN</strong>: Find your way to the DBA’s desk and receive your punishment.</li>
  <li><strong>NATURAL JOIN</strong>: I’ll be honest, I don’t fully understand what a natural join does.</li>
</ul>

<p>Back in ActiveRecord land, let’s imagine I want to create a
<a href="http://apidock.com/rails/ActiveRecord/NamedScope/ClassMethods/named_scope">named_scope</a>,
which in Rails 3 has been deprecated in favor of just
<a href="http://apidock.com/rails/ActiveRecord/NamedScope/ClassMethods/scope">scope</a>,
I’d write code something like this:</p>

<figure class="highlight"><pre><code class="language-ruby" data-lang="ruby">    <span class="k">class</span> <span class="nc">Guest</span> <span class="o">&lt;</span> <span class="no">ActiveRecord</span><span class="o">::</span><span class="no">Base</span>
      <span class="n">has_one</span> <span class="ss">:plate</span>
      <span class="c1"># ...</span>
      <span class="n">named_scope</span> <span class="ss">:with_food</span><span class="p">,</span> <span class="nb">lambda</span> <span class="p">{</span> <span class="o">|</span><span class="n">food</span><span class="o">|</span> <span class="p">{</span>
                    <span class="ss">:conditions</span> <span class="o">=&gt;</span> <span class="p">[</span><span class="s2">"guests.favorite = ? OR plates.content = ?"</span><span class="p">,</span> <span class="n">food</span><span class="p">,</span> <span class="n">food</span><span class="p">],</span>
                    <span class="ss">:joins</span> <span class="o">=&gt;</span> <span class="ss">:plate</span>
                <span class="p">}}</span>
    <span class="k">end</span></code></pre></figure>

<p>Underneath the hood, ActiveRecord generates a query <em>almost</em> exactly like the
one above with one subtle difference. “<code class="language-plaintext highlighter-rouge">JOIN</code>” is instead an “<code class="language-plaintext highlighter-rouge">INNER JOIN</code>”
which means my query will <em>not</em> return a Guest object for any guests who do not
already have a plate object.</p>

<p>The “solution” is to use a <code class="language-plaintext highlighter-rouge">LEFT JOIN</code>, which is unfortunately rather gnarly.
There may be a better way to perform alternate JOINs in ActiveRecord, but I
don’t yet of one:</p>

<figure class="highlight"><pre><code class="language-ruby" data-lang="ruby">    <span class="k">class</span> <span class="nc">Guest</span> <span class="o">&lt;</span> <span class="no">ActiveRecord</span><span class="o">::</span><span class="no">Base</span>
      <span class="n">has_one</span> <span class="ss">:plate</span>
      <span class="c1"># ...</span>
      <span class="n">named_scope</span> <span class="ss">:with_food</span><span class="p">,</span> <span class="nb">lambda</span> <span class="p">{</span> <span class="o">|</span><span class="n">food</span><span class="o">|</span> <span class="p">{</span>
                    <span class="ss">:conditions</span> <span class="o">=&gt;</span> <span class="p">[</span><span class="s2">"guests.favorite = ? OR plates.content = ?"</span><span class="p">,</span> <span class="n">food</span><span class="p">,</span> <span class="n">food</span><span class="p">],</span>
                    <span class="ss">:joins</span> <span class="o">=&gt;</span> <span class="s2">"LEFT JOIN `plates` ON plates.guest_id = guests.id"</span>
                <span class="p">}}</span>
    <span class="k">end</span></code></pre></figure>

<p>Basically if you want to use anything other than a simple <code class="language-plaintext highlighter-rouge">INNER JOIN</code>, you’ve
got to enter it in yourself. At a certain point ActiveRecord throws up its
hands and says “Look, buddy, I have no idea what you’re trying to do here.
Enter your own damn SQL.”</p>]]></content><author><name>R. Tyler Croy</name></author><category term="ruby" /><category term="rails" /><category term="activerecord" /><category term="programming" /><summary type="html"><![CDATA[There was once a time when I prided myself on my ignorance of SQL Joins, foolishly proclaiming “if I need to use a JOIN, I’ve already screwed up.”]]></summary></entry><entry><title type="html">10 poorly chosen Ruby gem names</title><link href="https://brokenco.de//2011/11/13/ten-poorly-chosen-gem-names.html" rel="alternate" type="text/html" title="10 poorly chosen Ruby gem names" /><published>2011-11-13T00:00:00+00:00</published><updated>2011-11-13T00:00:00+00:00</updated><id>https://brokenco.de//2011/11/13/ten-poorly-chosen-gem-names</id><content type="html" xml:base="https://brokenco.de//2011/11/13/ten-poorly-chosen-gem-names.html"><![CDATA[<p>There’s something weird in the Ruby community that has been driving me crazy
since I started using the language. There’s this habit, by what I hope is a
minority, of choosing “clever” gem names instead of useful or descriptive
names. I’m not above a good pun or play on words, but some gem names range
between confusingly stupid and utterly aggrevating.</p>

<h4 id="probably-offensive">Probably offensive</h4>

<p>I basically spent about 30 minutes typing borderline or completely NSFW terms
into the <a href="http://rubygems.org">rubygems.org</a> search box to come up with this
list. It’s a little longer than 10 gems, I didn’t anticipate finding so many
“gems” (so to speak).</p>

<p>For slang or singular terms, I will include the definition according to Google, of the term to the right of
the gem.</p>

<ul>
  <li><a href="https://github.com/ithouse/lolita">lolita</a> - <em>A sexually precocious young girl</em></li>
  <li><a href="https://github.com/joshkrueger/tranny">tranny</a> <em>Short form of transmission in the automotive sense; …  A transgender person.</em> (the second link listed was to tranny/shemale porn)</li>
  <li><a href="http://github.com/mintdigital/asset_hat">asset_hat</a> (pun on “ass hat”, clever)</li>
  <li><a href="http://github.com/aantix/sex_it_up">sex_it_up</a></li>
  <li><a href="http://rubygems.org/gems/womanizer">womanizer</a> <em>a man who likes many women and has short sexual relationships with them.</em></li>
  <li><a href="https://rubygems.org/gems/trollop">trollop</a> <em>A woman perceived as sexually disreputable or promiscuous.</em></li>
  <li><a href="http://github.com/LifebookerInc/hash_dealer">hash_dealer</a></li>
  <li><a href="https://rubygems.org/gems/ball_gag">ball_gag</a> <em>A gag is sometimes worn during some bondage and BDSM roleplays.</em></li>
  <li><a href="https://github.com/francois/clitt">clitt</a></li>
  <li><a href="https://rubygems.org/gems/tramp">tramp</a> (debatable whether is closer “Lady and the Tramp” or “Tramp Stamp”)</li>
  <li><a href="http://rubygems.org/gems/texticle">texticle</a> (<em>thanks for the reminder <a href="https://twitter.com/scottmlikens">@scottmlikens</a></em>)</li>
</ul>

<hr />

<p><em>Tips for Naming a Gem:</em></p>

<ul>
  <li>Can you make an incredibly obtuse pun on the name of the library you’re wrapping?</li>
  <li>Grab a photo album from your childhood, find a picture of your bedroom, what’s the name of the first thing you see?</li>
  <li>Are you coding in between bong rips? Choose a word that sounds the funniest to your stoner friends.</li>
  <li>Are you British? What is the local slang term for “slut?”</li>
  <li>Go to 4chan, pick the 7th word of a random post to /b/</li>
  <li>Are you a white guy from Memphis who loves Asian culture? Use the Japanese name of the nearest household appliance.</li>
</ul>

<hr />

<h4 id="just-plain-stupid">Just plain stupid</h4>

<p>While searching for blatantly offensive gem names, I found a number of other
“wonderfully” named gems that don’t offend so much as they confuse. There was such a
plethora of simple nouns which can make searching for documentation
exceptionally difficult for novice users.</p>

<ul>
  <li><a href="https://rubygems.org/gems/cocaine">cocaine</a></li>
  <li><a href="https://github.com/icebreaker/girlfriend">girlfriend</a>  (okay, the name is appropriate, but seriously, what the?)</li>
  <li><a href="http://github.com/thumblemonks/smurf">smurf</a></li>
  <li><a href="https://github.com/adlaiff6/tit">tit</a></li>
  <li><a href="http://github.com/radamant/analdiffist">analdiffist</a></li>
  <li><a href="https://github.com/tenderlove/nokogiri">nokogiri</a>, from my understanding a Nokogiri is a <a href="http://en.wikipedia.org/wiki/Japanese_saw">saw</a>?</li>
  <li><a href="http://github.com/stephencelis/miniskirt">miniskirt</a></li>
  <li><a href="https://rubygems.org/gems/hoe">hoe</a></li>
  <li><a href="https://rubygems.org/gems/vegas">vegas</a></li>
  <li><a href="http://github.com/flavorjones/loofah">loofah</a></li>
  <li><a href="http://github.com/trafficbroker/mandy">mandy</a></li>
  <li><a href="http://github.com/jeremyevans/home_run">home_run</a></li>
  <li><a href="http://github.com/xlymian/hansel">hansel</a></li>
  <li><a href="http://github.com/ohrite/vacation">vacation</a></li>
  <li><a href="http://github.com/richmolj/whoa">whoa</a></li>
</ul>

<p>I don’t have much of an idea what half of these gems do, and I can’t be
troubled to dig into what the use case is for “cocaine”, “vegas” or “whoa”, at least from
the Ruby perspective that is.</p>]]></content><author><name>R. Tyler Croy</name></author><category term="ruby" /><category term="opinion" /><summary type="html"><![CDATA[There’s something weird in the Ruby community that has been driving me crazy since I started using the language. There’s this habit, by what I hope is a minority, of choosing “clever” gem names instead of useful or descriptive names. I’m not above a good pun or play on words, but some gem names range between confusingly stupid and utterly aggrevating.]]></summary></entry></feed>