<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <title>InfluxData Blog - Jade McGough</title>
    <description>Posts by Jade McGough on the InfluxData Blog</description>
    <link>https://www.influxdata.com/blog/author/jade/</link>
    <language>en-us</language>
    <lastBuildDate>Thu, 02 Jan 2020 07:00:18 -0700</lastBuildDate>
    <pubDate>Thu, 02 Jan 2020 07:00:18 -0700</pubDate>
    <ttl>1800</ttl>
    <item>
      <title>Release Announcement: Flux VSCode Support</title>
      <description>&lt;p&gt;Flux is a powerful, purpose-built open-source language for working with data. The language has continued to mature in recent months, and there’s never been a better time to &lt;a href="https://w2.influxdata.com/products/flux/"&gt;give it a try&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Today we’re announcing support for Flux in Microsoft’s Visual Studio Code editor, available as an extension in their marketplace &lt;a href="https://marketplace.visualstudio.com/items?itemName=influxdata.flux"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;img class="alignnone size-full wp-image-243292 aligncenter" src="/images/legacy-uploads/flux-language-error-demo.gif" alt="Flux language error demo" width="574" height="164" /&gt;&lt;/p&gt;

&lt;p&gt;We’ve leveraged the same parser used to parse Flux in InfluxDB to support features like:&lt;/p&gt;
&lt;ul&gt;
 	&lt;li&gt;Error messaging&lt;/li&gt;
 	&lt;li&gt;Finding variable references&lt;/li&gt;
 	&lt;li&gt;Syntax highlighting&lt;/li&gt;
 	&lt;li&gt;Querying directly from the code editor&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;We’re just scratching the surface of what’s possible with Flux. Expect regular updates to the extension with support for intelligent autocompletion, integrated script execution, and other features.&lt;/p&gt;

&lt;p&gt;Upcoming features include:&lt;/p&gt;
&lt;ul&gt;
 	&lt;li&gt;Statement completion for types and data&lt;/li&gt;
 	&lt;li&gt;Enhanced progressive evaluation&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Committed to open source&lt;/h2&gt;
&lt;p&gt;We’ve open sourced the &lt;a href="https://github.com/influxdata/flux-lsp"&gt;language server&lt;/a&gt; that powers the VSCode extension, and it’s already been used to add Flux support to Vim with &lt;a href="https://github.com/gianarb/vim-flux"&gt;vim-flux&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Interested in sharing feedback or adding Flux support to your favorite editor? Stop by our &lt;a href="https://w2.influxdata.com/slack"&gt;community slack&lt;/a&gt; and chat with us in the #flux channel!&lt;/p&gt;
</description>
      <pubDate>Thu, 02 Jan 2020 07:00:18 -0700</pubDate>
      <link>https://www.influxdata.com/blog/release-announcement-flux-vscode-support/</link>
      <guid isPermaLink="true">https://www.influxdata.com/blog/release-announcement-flux-vscode-support/</guid>
      <category>Developer</category>
      <category>Product</category>
      <author>Jade McGough (InfluxData)</author>
    </item>
    <item>
      <title>The Case of The Enigmatic Enumerable Module</title>
      <description>&lt;p&gt;As it sometimes happens, the problem started with updating a Ruby gem.&lt;/p&gt;

&lt;p&gt;Dawn had been working for SaaS.me for the past year, developing a localized social network app for dogs, which made heavy use of social media APIs. Their Facetwit gem’s version had been locked down some time ago and was starting to cause dependency conflicts, meaning that it was time to upgrade it.&lt;/p&gt;

&lt;p&gt;The gem update seemed to go smoothly at first, but she soon realized the application dashboard was missing its list of recent tweets by users in nearby dog parks. Checking the response from the facetwit client revealed an annoying &lt;code&gt;429: Too Many Requests&lt;/code&gt;. Dawn frowned, waited several minutes for her limit to refresh, only to be greeted by the &lt;code&gt;429&lt;/code&gt; again. This one had a new expiration time, suggesting that she’d somehow exhausted her queries again.&lt;/p&gt;

&lt;p&gt;Poking around the controller didn’t immediately reveal anything out of the ordinary:&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-markup"&gt;class FacetwitController &amp;lt; ApplicationController
def search
client = Facetwit::Client.new(api_key: 'fuzzy_pickles')
@posts = client.search(params[:query])
respond_to do |format|
format.json { render json: @posts }
end
end
end&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;She stepped through with a debugger after that, and noticed something interesting when she examined &lt;code&gt;@posts&lt;/code&gt;. She’d expected it to be an array of responses returned from the search, but it was actually a &lt;code&gt;Facetwit::SearchResults&lt;/code&gt; object. Even more surprisingly, &lt;code&gt;client.search&lt;/code&gt; wasn’t actually making an API call at all. So how was her query limit being exhausted?&lt;/p&gt;
&lt;h3&gt;The Enumerable Module&lt;/h3&gt;
&lt;p&gt;Let’s step back for a moment. One of Ruby’s great strengths is its powerful collection manipulation methods, such as &lt;code&gt;inject&lt;/code&gt;, &lt;code&gt;sort_by&lt;/code&gt; and &lt;code&gt;map&lt;/code&gt;. These are made available in both &lt;code&gt;Array&lt;/code&gt; and &lt;code&gt;Hash&lt;/code&gt; by Ruby’s &lt;a href="http://ruby-doc.org/core-2.2.3/Enumerable.html"&gt;Enumerable module&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;In fact, you can gain access to all of these methods in any class. You simply need to include the module and create an &lt;code&gt;each&lt;/code&gt; definition which yields members to a block. Ruby is smart enough to extrapolate all of the other methods from your &lt;code&gt;each&lt;/code&gt; definition (though you’ll also need to define &lt;code&gt;&amp;lt;=&amp;gt;&lt;/code&gt; for sorting methods).&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-markup"&gt;class Pack
include Enumerable
attr_accessor :dogs&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code class="language-markup"&gt;def initialize
@dogs = []
end

def each(&amp;amp;block)
@dogs.each{ |dog| block.call(dog) }
end
end

Dog = Struct.new(:name, :breed)

&amp;gt; pack = Pack.new
&amp;gt; pack.dogs &amp;lt;&amp;lt; Dog.new("Fido", "Pug")
&amp;gt; pack.dogs &amp;lt;&amp;lt; Dog.new("Sparky", "Beagle")
&amp;gt; pack.map(&amp;amp;:breed)
=&amp;gt; ["Pug", "Beagle"]&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;So how does this relate to Dawn’s problem? Well, what if &lt;code&gt;each&lt;/code&gt; wasn’t just used for iterating through a collection, but requesting the actual collection as well?&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-markup"&gt;Module Facetwit
class SearchResults
include Enumerable&lt;/code&gt;&lt;code&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code class="language-markup"&gt;def each(start = 0)
@posts.each{ |item| yield(item) }
unless finished?
start = [@posts.size, start].max
get_next
each(start, &amp;amp;Proc.new)
end
end
end
end&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Dawn saw this and realized that, given how popular a platform Facetwit is, iterating through a single &lt;code&gt;Facetwit::SearchResults&lt;/code&gt; object would continue to fetch results until it exhausted her available queries. The searching wasn’t being kicked off in her controller, but here in her view:&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-markup"&gt;&amp;lt;% @posts.each do |post| %&amp;gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;In order to limit the number of external requests, Dawn made use of another Enumerable module method, &lt;a href="http://ruby-doc.org/core-2.2.3/Enumerable.html#method-i-take"&gt;take&lt;/a&gt;.&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-markup"&gt;&amp;lt;% @posts.take(10).each do |post| %&amp;gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;With that simple change she reloaded the page again and was greeted by ten posts from Dolores Park.&lt;/p&gt;
&lt;h3&gt;Don't Be Enigmatic&lt;/h3&gt;
&lt;p&gt;Dawn immediately had to debug her code because an external library was behaving unexpectedly. The programmer who made the change violated the &lt;a href="https://en.wikipedia.org/wiki/Principle_of_least_astonishment"&gt;principle of least astonishment&lt;/a&gt;. This is an important concept that many Rubyists try to adhere to which states that code should not behave in a way that’s unnecessarily surprising.&lt;/p&gt;

&lt;p&gt;Using Enumerable module for pagination can be an elegant pattern to use when writing an external API gem, as long as it’s clear to the user that use of Enumerable methods can make multiple external requests. In a single-threaded Rails application, actively waiting for several HTTP responses in a controller could lock up the application for an unacceptably long period of time.&lt;/p&gt;

&lt;p&gt;After all, you should be able to appreciate good code without needing to solve a mystery.&lt;/p&gt;
</description>
      <pubDate>Mon, 20 Mar 2017 12:29:58 -0700</pubDate>
      <link>https://www.influxdata.com/blog/case-enigmatic-enumerable-module/</link>
      <guid isPermaLink="true">https://www.influxdata.com/blog/case-enigmatic-enumerable-module/</guid>
      <category>Developer</category>
      <author>Jade McGough (InfluxData)</author>
    </item>
  </channel>
</rss>
