Swap Two Column Values in SQL: Part 1

I recently needed to write a PostgreSQL snippet that would massage some
data. More specifically, I needed to swap the ordering of two different
records in the pages table. These records are made up of an id, a
name, and an ordering.

Here is a snapshot of the data in pages.

select * from pages order by ordering;
 id |  name  | ordering
----+--------+----------
  3 | Green  |        1
  1 | Red    |        2
  4 | Yellow |        3
  2 | Blue   |        4

We've been informed that we need to swap the ordering of Red and Blue.
We can see here in this snapshot of the data that Red has an ordering of
2 and Blue has an ordering of 4.

Doing a swap based on the data that we have locally would be most easily
accomplished with a couple update statements.

update pages set ordering 
Continue reading "Swap Two Column Values in SQL: Part 1"

The Facebook Patent License Punishes You For Suing Facebook, But Lets Them Sue You

There’s been a lot of discussion recently about the Facebook patent clause (“PATENTS” in Facebook repositories).

While most of the objections to the license have focused on the patent revocation provisions, most of the defense focuses on the patent grant. This has meant that both sides are talking past each other, and casual readers are getting confused about what this is all about.


The Facebook patent grant comes with a revocation clause. It is meant to protect Facebook from patent lawsuits in general. It applies to Facebook’s patents, and therefore the revocation clause does not apply to Facebook itself (by definition). Your license to Facebook’s patents in order to use the OSS is revoked if:

  • You sue Facebook for patent infringement, or
  • You sue someone for patent infringement for using a Facebook product or service, or
  • You sue someone for using the OSS software

Notably, it does nothing to punish Continue reading “The Facebook Patent License Punishes You For Suing Facebook, But Lets Them Sue You”

Kafka Everywhere: New Plans and Pricing for Apache Kafka on Heroku

Event-driven architectures are on the rise, in response to fast-moving data and constellations of inter-connected systems. In order to support this trend, last year we released Apache Kafka on Heroku – a gracefully integrated, fully managed, and carefully optimized element of Heroku's platform that is the culmination of years of experience of running many hundreds of Kafka clusters in production and contributing code to the Kafka ecosystem.

Today, we are excited to announce additional plans and pricing in our Kafka offering in order to make Apache Kafka more accessible, and to better support development, testing, and low volume production needs.

Apache Kafka on Heroku: Now With More Flexibility and Speed

Apache Kafka is a powerful, distributed streaming platform, and the dominant open source solution in managing high scale event streams. Kafka enables you to easily design and implement architectures for many important use cases, such as elastic queuing, data pipelines

Continue reading “Kafka Everywhere: New Plans and Pricing for Apache Kafka on Heroku”

Observing Change: A Gold Master Test in Practice

How do we test a system that seems untestable?

Untested legacy code is the bane of many a developer's existence. In a
permissive language like Ruby, continued development in an untested legacy
codebase requires adding tests. Users expect certain behavior to survive each release intact.

For some systems, the traditional pyramid of test types (unit, API, and
integration) is insufficient. Unit and API tests must presumably cover hundreds
or thousands of functions; which matter? Integration tests could cover a wide
range of user interactions; which are likely? Familiarity with the project is a luxury we don't all enjoy.

I recently worked on an application that took a complex input (a
production database), ran it through a large SQL function, outputting a
giant CSV file representing thousands of permutations of data. Each stage of
the transformation was complex enough that visual inspection would fail to
determine if something was amiss.

None

Continue reading “Observing Change: A Gold Master Test in Practice”

Python Testing with pytest: Simple, Rapid, Effective, and Scalable

Best of the Blogs: A Heroku Community Tour

Heroku is very fortunate to have a strong community of developers that are excited and passionate about our product. Every day we hear from customers who tell us how much easier Heroku has made their lives, and they frequently share stories about interesting technical projects we've helped them bring to life.

Our customers love us, and we love them right back. Today we'll take a look at a few blog posts and applications from Heroku users that illustrate what makes our community so special. We hope you enjoy the tour. If you have Heroku stories of your own you'd like to share, we'd love to hear them!

Dynos Spinning Other Dynos with Heroku

This article comes to us from Yoni Weisbrod, a JS & React Native developer from Ivy. Ivy makes a community and business management tool for interior designers. They ran into some challenges when their worker dynos

Continue reading “Best of the Blogs: A Heroku Community Tour”

Advanced Queries with ActiveRecord’s From Method

For those of us that write database-backed Rails apps,
ActiveRecord is a
familiar beast. We know its various query building methods well: where,
order, limit, and even group. The most important SQL clause is
conspicuously missing from our repertoire: the from clause.

Chances are you can't think of many, if any, times that you've used
ActiveRecord's from method. This is to be expected. The from clause in
SQL specifies the target table of a query. In the context of ActiveRecord, the
target table is explicitly expressed by the model from which you query.

Consider the times you use one-liners such as Developer.first,
Developer.all, and Developer.count. With each of these, the developers
table as the target of the query is expressed by the use of the Developer
model.

So, where does the from method come into the picture?

The
docs
describe the

Continue reading "Advanced Queries with ActiveRecord’s From Method"

Today I Learned in Phoenix

The Phoenix port of Today I Learned, Tilex, is live.

Today I Learned began as a Ruby on Rails application.
We open-sourced the code after launch and have maintained it for over two
years. Our mission:

Today I Learned is an open-source project by Hashrocket that exists to
catalogue the sharing & accumulation of knowledge as it happens day-to-day.
Posts have a 200-word limit, and posting is open to any Rocketeer as well as
selected friends of Hashrocket. We hope you enjoy learning along with us.

Today, we are moving forward with an Elixir/Phoenix port of the project.
Here's a little more about the project, focusing on the work, technology, some
observations, the people behind it, and the future.

Work

This project began over two years ago as my
Hashrocket apprentice project. Here's the launch
announcement
from that time.

We open-sourced the Ruby on Rails
application in February 2016.

Continue reading “Today I Learned in Phoenix”

Customize ActiveAdmin Index Filters

ActiveAdmin allows us to quickly bootstrap an admin interface to our application. One of the features we get out of the box is a robust, comprehensive filtering sidebar. When viewing a resource's index page with hundreds of records, filtering allows us to narrow down to a digestible subset.

Unfortunately, the set of filters generated by ActiveAdmin for a particular model can sometimes be a bit hairy. If there are lots of fields and associations, you can end up with way more filters than you need, detracting from the user experience.

One solution is to remove the filters altogether.

ActiveAdmin.register Post do
  config.filters = false
end

This is a bit drastic though. Perhaps we can find some middle ground by customizing the filters a bit. In the rest of this post, I'll layout some approaches we can take to make our filters cleaner and more directed.

Table of Contents

React for Real, Effective Testing with RSpec 3: both in print and shipping

Release It! Second Edition: Design and Deploy Production-Ready Software

React for Real, Effective Testing with RSpec 3: both in print and shipping

Keep Anaconda from Constricting Your Homebrew Installs

Fixing conflicts between Anaconda and Homebrew

I recently installed Anaconda to my local machine and noticed that Anaconda modified my PATH variable. For Mac installations, if you check your .bash_profile, you should see something like the following:

# Added by Anaconda3 4.4.0 installer
export PATH="/Applications/anaconda/bin:$PATH"

Now if you run brew doctor, you'll get the following gnarly message:

Warning: Anaconda is known to frequently break Homebrew builds, including Vim and
MacVim, due to bundling many duplicates of system and Homebrew-available
tools.

If you encounter a build failure please temporarily remove Anaconda
from your $PATH and attempt the build again prior to reporting the
failure to us. Thanks!

Warning: python is symlinked to python3
This will confuse build scripts and in general lead to subtle breakage.

Warning: "config" scripts exist outside your system or Homebrew directories.
`./configure` scripts often look for *-config 
Continue reading "Keep Anaconda from Constricting Your Homebrew Installs"

Heroku Webhooks: Powering New Integrations and Real-time Notifications

We're happy to announce that Heroku app webhooks is now generally available for all Heroku customers.

App webhooks provide notifications when your Heroku app changes, including modifications to domain settings, releases, add-ons, and dyno formations. These notifications can empower your internal communications, dashboards, bots or anything else that can receive HTTP POST requests. Integrating with Heroku webhooks provides easy support for driving custom workflows and 3rd party tools.

Creating webhooks

With the webhooks CLI plugin, you can subscribe to events with a single command.

heroku plugins:install heroku-webhooks        
heroku webhooks:add -i api:release -l notify -u https://example.com/hooks -a your-app  

In this example, after a new release is created for your-app, Heroku sends a POST request to your server endpoint with the details of the event. The example below shows the first section of a typical POST request:

webhooks_blog2

Receiving webhooks

Webhooks are delivered by POST requests to a designated, publicly accessible URL.

Continue reading “Heroku Webhooks: Powering New Integrations and Real-time Notifications”

A Friendly Introduction to Convolutional Neural Networks

Introduction

Convolutional neural networks (or convnets for short) are used in situations where data can be expressed as a "map" wherein the proximity between two data points indicates how related they are. An image is such a map, which is why you so often hear of convnets in the context of image analysis. If you take an image and randomly rearrange all of its pixels, it is no longer recognizable. The relative position of the pixels to one another, that is, the order, is significant.

Convnets are commonly used to categorize things in images, so that's the context in which we'll discuss them.

A convnet takes an image expressed as an array of numbers, applies a series of operations to that array and, at the end, returns the probability that an object in the image belongs to a particular class of objects. For instance, a convnet can let you know

alt text
alt text
alt text
alt text
alt text
alt text
alt text
alt text
alt text

Continue reading “A Friendly Introduction to Convolutional Neural Networks”

Playing with React VR

The React concept of "Learn once, write anywhere" is virtually real, I mean, it is real!

After attending a local React meetup here in Jacksonville, I decided to try React VR.
I've been doing React Native for almost two years now, and almost the same APIs are available in React VR, so the learning curve for me was super low.

So if you've been doing React or React Native for the past months, you'll see that React VR is super simple to get started and will let you build exciting 360 experiences.

To get started with React VR you have to install the CLI:

npm install -g react-vr-cli

After that let's create a new project:

react-vr init HashrocketVR

Now, let's go to the created directory and start the server:

cd HashrocketVR
npm start

Now open your browser:

open http://localhost:8081/vr/

You should see this page:

Open scene in new tab for

Continue reading “Playing with React VR”

Evolution of the Heroku CLI: 2008-2017

Over the past decade, millions of developers have interacted with the Heroku CLI. In those 10 years, the CLI has gone through many changes. We've changed languages several times; redesigned the plugin architecture; and improved test coverage and the test framework. What follows is the story of our team's journey to build and maintain the Heroku CLI from the early days of Heroku to today.

  1. Ruby (CLI v1-v3)
  2. Go/Node (CLI v4)
  3. Go/Node (CLI v5)
  4. Pure Node (CLI v6)
  5. What's Next?

Ruby (CLI v1-v3)

Our original CLI (v1-v3) was written in Ruby and served us well for many years. Ruby is a great, expressive language for building CLIs, however, we started experiencing enough problems that we knew it was time to start thinking about some major changes for the next version.

For example, the v3 CLI performed at about half the speed on Windows as it did on Unix. It was

2017-07-20 09

Continue reading “Evolution of the Heroku CLI: 2008-2017”

Ruby on the Command Line

Ruby is strongly identified with Rails and web development. But Ruby is far more than a web language. Ruby has a rich set of tools for shell scripting and text processing.

Let's start by executing a Ruby command. The -e argument tells Ruby to run the provided code and exit.

$ ruby -e 'puts "Hello, world."'
Hello, world.

Multiple statements can be separated by a ;.

$ ruby -e 'puts "Hello, world."; puts "It is now #{Time.now}."'
Hello, world.
It is now 2017-08-08 16:43:56 -0500.

Or multiple -e arguments can be provided.

$ ruby -e 'puts "Hello, world."' -e 'puts "It is now #{Time.now}."'
Hello, world.
It is now 2017-08-08 16:45:10 -0500.

Reading Files

Where this really becomes valuable is to easily process text. Ruby is a Swiss army knife of text processing tools that can be used in place of sed and

Continue reading "Ruby on the Command Line"

Ruby on the Command Line

Ruby is strongly identified with Rails and web development. But Ruby is far more than a web language. Ruby has a rich set of tools for shell scripting and text processing.

Let's start by executing a Ruby command. The -e argument tells Ruby to run the provided code and exit.

$ ruby -e 'puts "Hello, world."'
Hello, world.

Multiple statements can be separated by a ;.

$ ruby -e 'puts "Hello, world."; puts "It is now #{Time.now}."'
Hello, world.
It is now 2017-08-08 16:43:56 -0500.

Or multiple -e arguments can be provided.

$ ruby -e 'puts "Hello, world."' -e 'puts "It is now #{Time.now}."'
Hello, world.
It is now 2017-08-08 16:45:10 -0500.

Reading Files

Where this really becomes valuable is to easily process text. Ruby is a Swiss army knife of text processing tools that can be used in place of sed and

Continue reading "Ruby on the Command Line"