ruby
137 posts · All topics
- — Porting a Discord Bot to Microsoft Teams, Entirely With AI
Slava (slack-strava) connects a Strava account to a chat and posts a card for every activity, complete with map, pace, and elevation, plus commands like connect, disconnect, sta...
- — Standardizing Exception Message Style in Ruby
While reviewing dozens of PRs from ericproulx optimizing Grape’s internals recently, I noticed that the bare raise ArgumentError, "..." calls scattered across the codebase were ...
- — Adventures in Daylight Saving, Norfolk Island, and Time Zone Math (in Ruby)
distance_of_time_in_words is a small Ruby gem that turns two Time objects into a human-readable string like “3 days and 4 hours”. Several separate bug reports against it turned ...
- — Benchmarks Are Free Now
My previous post walked through four bugs in ruby-enum, a gem I maintain, all stemming from the fact that class-level instance variables aren’t inherited by subclasses. The thir...
- — Ruby Instance Variables Are Not Inherited (and Why That Breaks Your DSL)
The ruby-enum gem is a small library I maintain that adds enum-like behavior to a class via include Ruby::Enum and define :KEY, value. Four pull requests landed against it recen...
- — Generating AI Descriptions of Automated Pull Requests
The slack-ruby-client library, an open source Ruby gem I maintain, runs a scheduled GitHub Actions workflow that regenerates code from Slack’s API definitions and opens a pull r...
- — Using Claude-Swarm to Upgrade Ruby Projects
One of my colleagues wrote a pretty awesome tool called claude-swarm that orchestrates multiple Claude Code instances as a collaborative AI development team. At Shopify, we are ...
- — Safely Passing Ruby Variables to JavaScript in ERB
A user reported a bug in Slava, a bot that syncs Strava activities to Slack, where they couldn’t subscribe to the paid version because their Slack team name contained a quote. T...
- — Writing a Channel Slack Bot with Granular Permissions
In 2020 Slack introduced granular permissions and has begun enforcing that legacy applications use them. I’ve previously migrated a simple bot to use those in-place, but it has ...
- — Migrating Classic Slack Ruby Bots to Granular Permissions
Slack recently introduced granular permissions and is now requiring all new apps to use those. The old apps are called classic apps, and new apps are called … apps. Slack also p...
- — Dup, Don't Modify Input Hash Parameters in Ruby
We often write Ruby functions that take an options Hash, remove some of its values, then pass the hash further down. Unfortunately we also often introduce a very difficult to ca...
- — Comparing Version Numbers in Ruby
Time and again, and again, developers fail to compare gem or ruby version numbers correctly. It’s an easy mistake to make.
- — Writing a New OpenWeatherMap.org API Ruby Client
I have been writing Ruby clients for various services for a few years now using the same pattern described in Writing a New Strava API Ruby Client. That itself was built on the ...
- — Handling of HTTP Headers in Grape with Rack and Rails
I recently helped debug Grape#1880, an issue a developer had with HTTP headers in Grape and Rack. It wasn’t immediately obvious.
- — Solving Slack-Side Disconnects in slack-ruby-client
In June 2018 users started reporting slack-side disconnects in their Ruby bots, reported via slack-ruby-client#208, regardless of the concurrency library (Eventmachine or Cellul...
- — Writing a New Strava API Ruby Client
Despite an existing Swagger-compatible API, most of Strava interactions written in Ruby don’t use any auto-generated code and prefer strava-api-v3 (update: this gem was yanked i...
- — Implementing Geolocation with a Custom GraphQL Scalar Type in Ruby
How does one return and accept a geolocation type in GraphQL? Something that has a latitude and longitude?
- — Prompting for Github Credentials in Ruby
Last week I wrote a tool to find a Github user’s e-mail address from their commits. One of the annoyances of the original implementation was the need to manually generate a pers...
- — Auto-Publishing Strava Runs to Github Pages
I always hated running. And now I have a open-source running blog. Most entries are automatically generated from runs recorded in Strava - I’m just too lazy to do it by hand :)
- — Google Finance Web API Ruby Client
There’s a bunch of financial market APIs out there, and after having tried a few for slack-market I still ended up using Yahoo Finance, undocumented, but wildly popular, “API”. ...
- — Generating and Handling Errors in GraphQL in Ruby
In a previous post I walked you through building and consuming a GraphQL API in Ruby. That was the happy path. In this post we’ll generate and handle some errors.
- — Building and Consuming a GraphQL API with Ruby on Rails
In the past few weeks I’ve convinced myself that GraphQL can work well for any micro-service. This post is a full walk-through of getting a working GraphQL API on Ruby on Rails....
- — Grape Framework 1.0 Released
I took a deep breath, and released Grape Framework 1.0. We’re at 8,066 Github stars and 965 forks. I still think Grape is the best way to build Ruby RESTful APIs. I’ve written m...
- — The Demonic Possession of Hashie::Mash
I’ve been co-maintaining the Ruby library hashie for a few years now. It’s a wonderful set of extensions written by some of the best Ruby developers. But sometimes, a piece o...
- — Why does Slack API rtm.start send you all this data?
Like many, I found it easy to immediately criticize the Slack Web and RealTime API design. I would have wanted a RESTful implementation and not an RPC one. I would have liked fo...
- — Writing a Slack Bot Service for Multiple Teams
- — How To Test Delayed Jobs
There are two ways to test delayed jobs under RSpec.
- — Lazy Each in Ruby MRI vs. Rubinius
It’s fairly rare to run into MRI vs. Rubinius or JRuby differences. Here’s one from spidey#5.
- — The New Ruby Grape
- — Getting Things Done with Mongoid 5
- — The Easiest Way to Write a Slack Bot in Ruby
I’ve extracted and improved upon common code from slack-gamebot and slack-mathbot and made slack-ruby-bot. It’s probably the easiest way to make a Slack bot in Ruby today.
- — Slack Bot Real Time Messaging API Integration in Ruby Tutorial
I’ve been recently contributing to slack-pongbot, a node.js Slack bot for setting up ping-pong matches at Artsy.
- — ActionMailer Integration Testing with Email-Example-Spec
Introducing email-example-spec, integration testing for your ActionMailer e-mails.
- — Designing a Hypermedia API with Grape & Roar
Slides from my talk last night @ API Craft NYC: https://www.slideshare.net/dblockdotorg/designing-a-hypermedia-api-with-grape-roar.
- — Taking Over Someone Else's Open-Source Projects
Thanks to the amazing crowd at GoGaRuCo 2014, San Francisco!
- — Syntax Highlighting in Markdown Content with Recarpet, Coderay and Rails
I wanted Ruby and JSON code blocks ala Github’s Flavored Markdown when rendering markdown documents in doppler. The idea is that we can API documentation authored in markdown, a...
- — Golden Gate Ruby Conference 2014
I’m very excited to be speaking at GoGaRuCo in San Francisco in September about taking over open-source projects, along with people like @wycats, @ultrasaurus and @pat. No press...
- — Anatomy of a Ruby Gem: Grape
I’ve recorded a screencast during the Anatomy of a Ruby Gem meetup in New York. It’s a deep dive into Grape internals.
- — Ruby Enumerable Detect with Value
Given an Enumerable, you can detect a value that matches a condition. But what if you want the result of the evaluation? You can now use _Enumerable##detect_value _from the enum...
- — Custom RSpec Meta Tag Validator
I’ve written my share of RSpec tests that look for specific meta tags in a web page under Capybara. It would be nice to be able to spell the following.
- — ld: library not found for–lXext installing RMagick on Mavericks
As always, ImageMagick is super fun after an OS upgrade. Mavericks + Ruby 2.x + RMagick failed with something very confusing today. It couldn’t find the Xext library, which is p...
- — Grape Mounted behind Goliath
Got a chance to play with Goliath for a bit. You don’t need to do much work to mount Grape behind it. Grape figures out content-negotiation and formatting for you, so just strea...
- — Making HTTPs Requests in Ruby & JavaScript w/ Node.js
Making HTTPs requests seems oddly difficult. Why can’t an HTTP library just figure things out for me like curl does? It mostly can.
- — Evolving APIs using Grape API Versioning
I’ve seen two common API versioning strategies in the wild. The first is to use a single API version and gradually deprecate methods. This usually means introducing new API rout...
- — Being Helpful with Ruby Exceptions and Error Messages
We talk a lot about error handling in Ruby. But we rarely talk about raising errors and creating helpful error messages that are actionable. A good error should tell the develop...
- — Your First Ruby Gem
UPDATE: I did another iteration of live-coding a Ruby gem at Flatiron School in January 2018. The code, a very similar but more complete and up-to-date checklist is here.
- — Grape vs. Poncho
There are a number of excellent micro-frameworks to author RESTful APIs in Ruby. Let’s take a look at the newcomer, Poncho, from the Stripe team, brought up on the Grape mailing...
- — Grape 0.4.0 Released w/ Stricter JSON Format Support & More
I’m very excited to Release Grape 0.4.0 today. Again, thanks to the 10 (!) contributors to this release.
- — Should you use 'Should' in RSpec Examples?
There are two kinds of developers: those who use should in RSpec examples and those who use present tense.
- — Losing Control to the Heroku PaaS
- — Measuring Performance in Grape APIs w/ NewRelic RPM
If you’re not using NewRelic, here’s a pretty picture to convince you to try it out. And a blog post on measuring performance in Grape APIs with NewRelic RPM on the Art.sy Engin...
- — TaxCloud: SOAP Service Integration in Ruby
- — Slow Migration to Mongoid::Slug 2.x
- — New York Times Open Source Science Fair
- — RSpec-Rerun Gem
I just published a new gem: rspec-rerun. It’s a packaged solution to rerunning failed RSpec tests. See README for details.
- — Returning a Sample Set from a Mongo Collection w/ Mongoid
module Mongoid class Criteria def sample(n = 1) indexes = (0..self.count-1).sort_by{ rand }.slice(0,n).collect! if n == 1 return self.skip(indexes.firs...
- — Wrapping Responses with Grape and Rack
Grape’s after blocks don’t allow you to modify response text or status code [#200]. So how can you wrap an API response?
- — GoRuCo 2012: From Zero to API Cache w/ Grape & MongoDB in 10 Minutes (Video)
tl;dr watch the video
- — How Not to Rewrite Everything
I wrote a blog post yesterday about How to Start Small With Big Data and Google Analytics. Essentially, it’s a jumpstart for fetching Google Analytics pageviews and merging the ...
- — Grape 0.2.0 Released
After almost a year of active development with 200+ commits, Grape 0.2.0 has finally been released. It’s the code from the “frontier” branch that we’ve been using in production ...
- — Paging and Iterating Over Large Mongo Collections
Sometimes you need to iterate over a large MongoDB collection. The biggest issue is that, by default, cursors timeout after 10 minutes of inactivity. For very large collections ...
- — How To Convert Numbers Into Words in Ruby (with numbers_and_words)
You’d think someone has implemented simple conversion of numbers into English by now? For example 42 becomes “forty-two”.
- — How Long Does it Take to Create a 12 Lecture, 8 Week Course
My family counts many teachers. My grandparents were teachers, my father started as a school English teacher and is now a University professor. My wife changed her successful ca...
- — Crafting a Ruby on Rails Course for Developers
- — Watching Rack Application Changes with Guard-Rack
One of the frequently requested features in Grape is to automatically reload code changes, much like Rails does (#131). This is actually pretty difficult to implement and requir...
- — Updating Devise Trackable Last User Sign-In Time with Devise Rememberable
Devise has a :trackable _strategy which updates the user’s last sign-in time, remote IP and increments a counter in the _User model upon successful logon. This is implemented in...
- — CarrierWave: DelayJob-Processing of Selected Versions, Revisited
I’ve written about delay-processing certain image versions in this article. We’ve made some progress since with a much more robust implementation. Check out this new post on the...
- — Testing w/ Analytical Gem and RSpec
We use the Analytical gem to include various thirdparty Javascript in our Rails application. Our test environment was configured with dummy values in config/analytical.yml.
- — Grape API Mounted on RACK w/ Static Pages
tl;dr – the source is here
- — Paginating w/ Mongoid 2.4.0, MongoMapper and Kaminari
I’ve upgraded our project from Mongoid 2.0.2 to 2.4.0. It took me a few days since our specs raised a couple of real issues. If you’re doing the same, take Mongoid from the tip ...
- — Warning: Toplevel Constant XYZ Referenced Admin:XYZ
I posted this to a Ruby forum a while ago.
- — Fabricating Spec Failures
I love fabricators. We use the awesome fabrication gem that lets you do some pretty neat things in Rails specs.
- — Blame it all on MongoDB
You may have read my previous post about the MongoDB 1.4.x Ruby driver hell.
- — Grape vs. Webmachine
One of my favorite talks at QCon 2011 was about Webmachine. I was very curious to see what those well-disciplined Erlang people had come up with. At the end of the talk I had le...
- — Grape: Describing and Documenting an API
Building a software platform is not just an investment in the future, it’s a software architecture philosophy. A proper API is a manifestation of some of the core principles of ...
- — Pushing Assets to S3 w/ Rake: Versioning and Cache Expiration
A while ago I wrote about how we package and push Rails assets to Amazon S3. We version assets with the GIT hash – varying the assets by URL enables setting indefinite cache exp...
- — Serving Compressed Rails Assets from S3 via CloudFront
I wrote about how we do asset packaging with Rails, how we Jammit and push them to S3 in this post. We’ve had a few surprises since then, one that had to do with compressed asse...
- — NYC.rb: Building RESTful APIs w/ Grape
I’m speaking at NYC.rb tonight @ Pivotal Labs, RSVP.
- — Rendering Markdown Documents in Rails
There’s got to be a prettier way of implementing this.
- — Grape: Routing Multiple Methods
Sometimes you want to support both GET and POST in a Grape API.
- — Filtering by User-Agent in Rails
Let’s filter out some unwanted browsers from displaying broken pages in our Rails application. We could disallow IE6, for example, but allow IE7, 8 and 9.
- — Using GCC to install Ruby w/ RVM on Mac OSX Lion
I have an iMac with a gigantic screen and Mac OSX Lion standing on my desk.
- — Mongoid 2.0.2, Mongo + bson + bson_ext 1.4.0 and 1.4.1
In the past two days we’ve had hell with our production environment. It started with a general feel of slowness followed by all kinds of alarms going off in the monitoring syste...
- — Sorting Tables in Rails w/ Mongoid
Sorting tables in Rails is a common problem. It must have been done before, right? In fact it has been done so many times that it’s really hard to find anything that “just works...
- — Capybara: Failed to Resynchronize, Ajax Request Timed Out (not caused by green elves)
I used to attribute this error to little green elves inside of Capybara, Selenium or Firefox. But, as usual, things turn out to have a much more reasonable explanation.
- — CarrierWave: DelayJob-Processing of Selected Versions
Our image upload pipeline has gotten a bit too long and no longer fits in the Heroku’s 30-second limit. We generate several image versions and would like to get a couple of size...
- — New Relic: Performance Instrumentation with Grape API
We’re using Grape in our Rails app on Heroku, which comes with New Relic instrumentation out-of-the-box. Let’s get the Grape API route details to show in New Relic as well.
- — Mongoid Collection Snapshot
Another fine open-source contribution from @aaw, mongoid_collection_snapshot: easy maintenance of collections of processed data in MongoDB with the Mongoid ODM.
- — Rails Editable Mail Templates w/Preview from 37Signals
Last time we added custom editable mail templates to our mailers and made them Markdown format [read first]. Awesome. Let’s add a preview to the templates with 37-signals mail_v...
- — IE9: Cache-Busting with Grape Middleware
Ran into a series of weird bugs with IE9. Turned out that a lot of our API requests were cached on the client. I am not sure whether this is some clever plot to make things work...
- — Being Lazy: Using the Ruby driver to connect to MongoDB
One of my rake tasks failed with an interesting error this morning.
- — Rails: Custom and Editable Mailer Templates in Markdown
You love markdown? We do too.
- — Jenkins: Running RoR Builds w/ Bash & RVM
I went through a few iterations of running builds via shell commands in Jenkins. Once I added a remote node things didn’t work quite the same as on master. I learned that Jenkin...
- — The Jenkins AnsiColor Plugin You've All Been Waiting For
I’ve released AnsiColor, a Jenkins plugin you’ve all been waiting for.
- — Barista: Custom Preambles in CoffeeScript => JavaScript
- — Exporting Data to Excel in Ruby on Rails w/ Spreadsheet and to_xls
- — Permission denied - /var/tmp/ruby-uuid
I’ve been fighting a trivial RoR controller test failure on a new build machine. The spec is rather trivial.
- — Embedding API Sandboxes in Documentation
Oh, I know how much you want this!
- — Contribute to any of these open-source projects and I will help you in any way I can
We all have wish lists. Here’s the deal. Contribute to any of these open-source projects and I will help you in any way I can.
- — RSpec: Fuubar + Breaking Tests into Suites
Inspired by this post on RSpec best practices and updated for RSpec2.
- — Selecting items from a dropdown with Capybara, Selenium (Firefox) & JQuery
I am having a weird problem with Capybara and Selenium (Firefox) selecting items in a dropdown.
- — Modularizing a RoR Grape API: Multiple Versions
We made some progress with modularizing our Grape API in the last post. But we only had one version and declared Api_v1 as our main API entry. Unless you’re Netflix and need an ...
- — Introducing Gem-Licenses: Collect 3rd Party Licenses in RoR Projects
Yet again I have to deal with 3rd party licenses, this time in RoR. It’s a pretty common thing to do for technical managers and in my last job I ended up creating 3licenses. For...
- — Modularizing a RoR Grape API
A lot of people ask me whether we use Rails controllers for our API. We don’t, we use Grape. Grape is a Rack-based system and a DSL that provides a cleaner separation, some API-...
- — Storing Server-Side JavaScript Functions w/ Mongoid + Weekly Rollup
I was working on some map/reduce that rolled up daily, weekly and yearly statistics in MongoDB and discovered, to my surprise, that JavaScript Date doesn’t have a getWeek method...
- — Mongoid 2.0.2 Dropped Pagination => Kaminari
I was a bit surprised to see mongoid drop pagination support in 2.0.2 (here and here). It got some people confused (see mongoid#983). In a project that uses will_paginate, this ...
- — RSpec + Capybara Don't Return a Proper Exit Code
We’ve been trying to fix an issue with our continuous integration where Capybara tests were failing, but the CI process reported success. Rather annoying for CI!
- — Compass: Invalid US-ASCII character 'xE2'
This one drove me crazy for a while. Compass would fail with “Syntax error: Invalid US-ASCII character “\xE2”. So I checked the files, found nothing changed since last time and ...
- — Delaying Image Processing on Heroku with delayed_job
There’s a Gem for That Too
- — RoR Win: 'Getting Things Done' with MongoDB Mongoid
- — Improving tags map/reduce with MongoDB 1.8.x
Today we’ll improve this map/reduce implementation that produces a collection of tags with their counts. We’ll add inline map/reduce for databases that support it, inline JavaSc...
- — Rails + S3 + CloudFront + Jammit + Heroku + 100 грам
When someone says that you need a “100 grams” to figure something out, it means that it’s completely unobvious and complicated and therefore you need a few vodka shots. Vodka in...
- — Grape: API Authentication w/ Devise
Now that we have dealt with exceptions in our API we need to provide various methods of authentication. We’re going to be talking grape and devise.
- — Grape: trapping all exceptions within the API
We’ve been using Grape to provide a RESTful API. Grape is a micro-framework for Ruby that makes it really easy.
- — Wrapping the Idee PixMatch RESTful API in a Ruby Gem
I had a nice time today wrapping up the Idee PixMatch API in a Ruby gem. PixMatch is a general image matching engine that allows you to perform large scale image comparisons and...
- — VirtualBox: Linux on Windows
I am going to say nice things about Oracle software. Brace yourself.
- — Mongoid_fulltext: full-text n-gram search for your MongoDB models
- — CarrierWave: Saving Best Image Geometry
I recently needed to find out the geometry of the image being uploaded via CarrierWave. Images come in many different sizes and shapes. What I want is to have a “best” image and...
- — A Rake Task for Backing Up a MongoDB Database
It’s time to connect MongoDB with S3 and write a task that backs up a MongoDB database to Amazon S3. This follows a series of articles, so before you read this you might want to...
- — A Rake Task for Copying Data between Amazon S3 Buckets
- — Rails: Passing Arrays in a Query String
I found this quite unusual. I needed to receive an array with some nested hashes part of a query string into a JSON API. Passing encoded JSON wasn’t looking hot. Turns out, in R...
- — A Rake Task for Copying MongoDB Databases
Now that we have a staging and a production environment, we want to copy all production data to staging at the same time as we push new code to staging via continuous integratio...
- — CarrierWave: Full Control over Changing (S3) Upload Path Name
Today, we will be uploading JPG, BMP or TIFF images to Amazon S3 that are attached to a model.
- — Continuous Deployment with Heroku-Bartender
You’ve heard about continuous deployment. But did you actually try to do it?
- — How to define Enums in Ruby?
This is going to heavily quote https://www.rubyfleebie.com/enumerations-and-ruby/, please read that first. The proposed implementation lets you iterate over enumerated values, ...
- — Models look nice, but sometimes you just want to change they way they feel
Mongoid models provide an excellent level of abstraction. Consider a User model.
- — Dan North doesn't believe in magic and makes babies cry
I’ve watched many Dan North’s InfoQ videos. I like 95% of what you say, Dan. But your latest Twitter whining on Ruby/Rails #fail have left my 2 y.o. son extremely disappointed. ...
- — Ruby: Unlearning OOP and Embracing Anarchy
- — Folder-Driven Development: when to create a folder?
- — Adding (almost) static pages to your fancy Rails website
So you’ve built the super amazing complicated Rails website. You are serving data from millions of documents from MongoDB, rendering complex objects using HAML and generally doi...
- — Seeding, exporting and importing MongoDB data with Rake
- — Rails: opinionated directory structure
One thing that has been irritating me is the default Rails app/models directory. It doesn’t support subdirectories, so models that deal with the database and classes that deal w...
- — DataMapper: promoting columns into classes
I recently had to deal with reading a schema in a MySQL database in Ruby and migrating data to MongoDB. It has been made real easy with DataMapper (note: datamapper.org is no lo...
- — Running ruby files on Heroku via rake
Let’s say you have some Ruby file that you want to run on Heroku. For example, I have stuff\things.rb. The easiest way to run the file on Heroku seems to inspire ourselves from ...
- — BSON::InvalidKeyName: key must not contain '.' or ‘$'
I ran into an error from Mongo, BSON::InvalidKeyName: key must not contain ‘.’ (or sometimes ‘$’ instead of ‘.’). It would happen randomly under RSpec (I do plan to check out Cu...
- — kernel.rb:27:in `should': uninitialized constant RSpec::Expectations::PositiveExpectationHandler (NameError)
This one took a while and required extensive help from a rocket scientist. While running RSpec I got this.
- — The program can't start because msvcrt-ruby18.dll is missing from your computer.
So I’ve been playing with Ruby. Yes, I am using a Windows 7 64-bit laptop and yes, despite the common message from most people on the Internet encouraging me to run Ubuntu, thin...
