Accidental Technologist

Musings about Entrepreneurship, Technology and Software Development

  • Home
  • About
  • Still River Software
  • Privacy Policy

Powered by Genesis

Fix Installation of Ruby using rbenv on macOS Big Sur

April 26, 2021 by Rob Bazinet Leave a Comment

Tweet

I’ve been using with rbenv to manage installation and switching of Ruby versions for the pass year and have been very happy with it. I recently took the plunge and upgraded my main Apple MacBook Pro from macOS Catalina to Big Sur. Everything seemed to work well after the upgrade. Until I tried to install a new version of Ruby.

Problem

When performing the usual command to install Ruby with rbenv, I started getting this message:

~ $ rbenv install 2.6.7
Downloading ruby-2.6.7.tar.bz2...
-> https://cache.ruby-lang.org/pub/ruby/2.6/ruby-2.6.7.tar.bz2
Installing ruby-2.6.7...
ruby-build: using readline from homebrew
BUILD FAILED (macOS 11.2.3 using ruby-build 20210423)
Inspect or clean up the working tree at /var/folders/mq/tlm78wy92v54ygbzfykqc8640000gn/T/ruby-build.20210424214159.42314.u6mGui
Results logged to /var/folders/mq/tlm78wy92v54ygbzfykqc8640000gn/T/ruby-build.20210424214159.42314.log
Last 10 log lines:
        rb_native_mutex_destroy(&vm->waitpid_lock);
        ^
vm.c:2489:34: warning: expression does not compute the number of elements in this array; element type is 'const int', not 'VALUE' (aka 'unsigned long') [-Wsizeof-array-div]
                             sizeof(ec->machine.regs) / sizeof(VALUE));
                                    ~~~~~~~~~~~~~~~~  ^
vm.c:2489:34: note: place parentheses around the 'sizeof(VALUE)' expression to silence this warning
compiling dmyenc.c
1 warning and 1 error generated.
make: *** [vm.o] Error 1
make: *** Waiting for unfinished jobs....
~ $

Trying to figure out the problem by looking at the message, it didn’t seem like something I could fix. Searching the rbenv Github issues didn’t give many clues. Knowing that rbenv uses ruby-build to automate the Ruby build process, I looked at the issues reported. It looks like I was not the only one having similar problems.

CleanShot 2021 04 24 at 21 51

I tried several of the suggestions found from those issues and none of the solutions worked.

Solution

I decided to turn to my friends on Twitter to see if anyone had faced this issue. Twitter never lets me down and Robby Russell of Planet Argon came through,  suggesting installing Ruby with these CFLAGS:

CFLAGS="-Wno-error=implicit-function-declaration" rbenv install 2.6.7

It worked perfectly and I was able to get additional versions of Ruby installed. This should also work if you’re having problems with asdf Ruby version manager too. Asdf uses ruby-build behind the scenes.

I wondered why I hadn’t stumbled on this solution in the ruby-build issues on Github. It turned out I saw the issue but ignored it because it referenced installing older versions of Ruby when Xcode 12 was installed. I have Xcode 12 but was installing new versions of Ruby. The ticket was a little deceiving as it worked with new versions as well.

For those interested in the details, they can be found in the ticket – Installing older Ruby versions on OSX after Xcode 12.

Share this:

  • LinkedIn
  • Twitter
  • Facebook
  • Email
  • More
  • Pinterest
  • Tumblr
  • Pocket
  • Reddit

Filed Under: Mac, Ruby Tagged With: rbnev, Ruby

frozen_string_literal: the not so magical comment

March 16, 2021 by Rob Bazinet Leave a Comment

Tweet

I have been working on a project over the past year for a client with a large Ruby on Rails application. The project has allowed me to learn more about how large Rails applications are developed and managed in the real-world. I’ve picked up some real gems to help scale Rails applications which I’ve used in some of the smaller applications I maintain.

One of the gems I learned about was the use of this magic comment:

# frozen_string_literal: true

This comment was added to every Ruby file in this company’s application, which included several microservices along with a large main application. The files numbered over 1,000.

I read up on the use of this magic comment use in other projects and the results seen. One in particular was Sidekiq from Mike Perham. Mike documented his use of the magic comment and how it improved his use and helped cleanup his code.

Ruby 2.3 introduced a very nice option: each Ruby file can opt into Strings as immutable, meaning all Strings within that file will automatically freeze, with a simple magic comment at the top of the file.

Mike includes some benchmarks that show improved memory footprint for Sidekiq. This was enough for me.

I had one relatively small application that had an API component I was optimizing (Rails 5.2.x and Ruby 2.6.6). I thought about the use of the magic comment and decided to give it a try. I added it to every Ruby file in the project and was included as part of the weekly deploy.

The deploy was done after hours one evening and I was ready to witness the magic.

Unfortunately, this magic did not happen. I noticed right away the response times of API calls were slower, not faster. Maybe I was seeing the effects of cold cache calls and things would improve overnight.

The next morning in fired up Skylight to check the response times from the API. To my surprise, the response times did not improve. Since the only change in this deploy was the use of magic comments, I decided to rollback the changes. This application runs on Heroku, rolling back with really easy and does not require reverting the code back and redeploying.

The result was noticed instantly:

IMG 1186

Response times drastically improved as you can see from the above graph.

At this point, I don’t have any reason to believe it’s not the magic comment that caused these longer response times.

During my brief research about the comment’s use, thinking there was more to using it than simply using it everywhere, I ran across a thread from the Ruby lang issue list. The threads title, Reconsider impact of frozen_string_literal on dynamic strings, I found interesting. Maybe this is a clue and dynamic strings being frozen in my application is part of the problem.

It sounds like there is a benefit to use this feature but not everywhere, the exact result I saw in performance graphs.

I am still exploring when to use the magic comment and when it shouldn’t be used. If you are using this throughout your applications it might be worth measuring with and without their use. Any others have more information to share, please reach out.

Share this:

  • LinkedIn
  • Twitter
  • Facebook
  • Email
  • More
  • Pinterest
  • Tumblr
  • Pocket
  • Reddit

Filed Under: Ruby on Rails Tagged With: Ruby, Ruby on Rails

Fix Ruby Malloc Error on macOS Sierra

October 13, 2016 by Rob Bazinet 1 Comment

Tweet

After upgrading my iMac to macOS Sierra I have experienced a few issues that I thought I’d document here, both for myself and to help others.

Problem

The latest issue I found when trying to run a rails console command for a client application. The result was a hung terminal session and this message:

ruby(50426,0x7fff96cd43c0) malloc: *** malloc_zone_unregister() failed for 0x7fff96cca000

I’ve never seen this one before and with the terminal session hung, I had no real way to debug. Thanks to Stackoverflow, the solution was pretty simple.

Solution

What I found pointed to the Skylight gem version (0.8.1) I was using. Changing the version 0.10.6, bundling and running the console again fixed the issue.

I wondered about the root cause the issue though and did a bit of research to see if I could figure out why this one gem caused such a failure. Knowing what I know about the Skylight gem and being developed at least partially using Rust, I started there. Looking at the Skylight gem source, there is indeed references to using Rust.

A bit of spelunking Rust issues revealed there were some issues with earlier macOS Sierra betas. I was using 0.8.1 of the Skylight gem, built before Rust was fixed. One in particular looked very suspect.

Everything is working great now. I hope this helps someone with this really odd error.

Share this:

  • LinkedIn
  • Twitter
  • Facebook
  • Email
  • More
  • Pinterest
  • Tumblr
  • Pocket
  • Reddit

Filed Under: Ruby Tagged With: Ruby, rust, skylight

Life Beyond Rails: A Brief Look at Alternate Web Frameworks for Ruby

February 17, 2015 by Rob Bazinet Leave a Comment

Tweet

I wrote up a list of alternative Ruby web frameworks some time ago and now Engine Yard has published a new list. Some of my original picks are in there, so it’s great to see they’ve continued.

A couple notables include Volt, for running Ruby on the server as-well-as the client, and Cramp that helps with needing a lot of open connections and bi-directional communication.

A great list to check out.

Share this:

  • LinkedIn
  • Twitter
  • Facebook
  • Email
  • More
  • Pinterest
  • Tumblr
  • Pocket
  • Reddit

Filed Under: Ruby Tagged With: Ruby, Ruby on Rails

Errors Installing the pg Gem When Using Heroku Postgres.app

December 19, 2013 by Rob Bazinet Leave a Comment

Tweet

I?ve been using the PostgreSQL Mac OS X app from Mattt Thompson and Heroku for quite some time now. ?If you don?t know what it is, it?s a drop in app bundle for the PostgreSQL database. ?There are many ways that work, this just happens to be really simple.

I use PostgreSQL with my Ruby on Rails projects and combine that with the pg ruby gem. ?

I ran into a situation where the pg gem would not install because it could not find pg_config in a known location on my Mac. ?The error occurred on Rails 3.2 but 4.0 may show the same behavior. ?

The Error

The error can come up when running a bundle install or just a straight gem install pg from the command line. The resulting error may look something like this:

Installing pg (0.17.0) with native extensions 
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension
.
.
.
.
An error occurred while installing pg (0.17.0), and Bundler cannot continue.
Make sure that `gem install pg -v ?0.17.0'` succeeds before bundling.

The Solution

I already mentioned the problem is the gem install not finding pg_config during installation. ?So let?s find it.

1. First, find where pg_config is located. ?Run this command from a terminal window:
which pg_config

Should display something like this:

/Applications/Postgres.app/Contents/MacOS/bin/pg_config

2. You can tell RubyGems where your pg_config file is located:

gem install pg -- --with-pg-config='PATH_TO_YOUR_PG_CONFIG'

For example, pg_config is here on my system:

/Applications/Postgres.app/Contents/MacOS/bin/pg_config

So I would install the gem this way:

gem install pg -- --with-pg-config='/Applications/Postgres.app/Contents/MacOS/bin/pg_config'

The pg gem should now install. I hope this helps.

UPDATE: Scott Watermasysk points out another good solution:

@rbazinet another route that worked for me was to put the pg.app (as a folder) in my path. This allows the config to be properly found.

? Scott Watermasysk (@scottw) December 19, 2013

Share this:

  • LinkedIn
  • Twitter
  • Facebook
  • Email
  • More
  • Pinterest
  • Tumblr
  • Pocket
  • Reddit

Filed Under: Ruby on Rails Tagged With: postgresapp, postgresql, Ruby, Ruby on Rails, rubygem

Use TinyURL from Ruby

June 6, 2013 by Rob Bazinet Leave a Comment

Tweet

I recently found myself needing to use TinyURL on a client project. ?I did a bit of scouring the web for some Ruby code to solve the problem but with little success. ?Much to my surprise they don’t have an available API, but they do have a way to access over HTTP.

This is a simple Ruby class to use TinyURL. ?Note: this depends on HTTParty, so add to your project.

class Tinyurl 
include HTTParty
base_uri 'tinyurl.com'

def shorten(url)
self.class.get("/api-create.php?url=#{url}")
end
end

You can find the Gist on Github. Hopefully you find this code useful. Enjoy!

Share this:

  • LinkedIn
  • Twitter
  • Facebook
  • Email
  • More
  • Pinterest
  • Tumblr
  • Pocket
  • Reddit

Filed Under: Ruby Tagged With: httparty, Ruby, tinyurl

I Backed The Ruby 2.0 Walkthrough on Kickstarter and So Should You

November 9, 2012 by Rob Bazinet Leave a Comment

Tweet

Ruby20

It was announced at RubyConf that Ruby 2.0 would be released in February 2013 and a preview available immediately. ?If you use rvm, you can try it out pretty easily.

The problem is, there are many changes coming. ?How are you going to know what’s different from Ruby 1.9.x? ?What about all the way back to 1.8.x? ?I think it will take any one of us a significant amount of time to sort it all out, but it doesn’t have to.

There really is a rather simple answer; it’s a Kickstarter project by our Ruby friend Peter Cooper called The Ruby 2.0 Walkthrough. ?Peter is looking for a small sum of money to help pay for his time to create this valuable asset.

What do you get?

Ruby 2.0 launches in February 2013 and at that time I’ll be selling the screencasts alone for $19 and the screencasts + e-book for $29. By backing the project now, you’ll get the same material for less and depending on what tier you go for you could get access to special bonuses and benefits that I WON’T be offering when it goes on general sale (like update e-mails, consultancy time or a limited PRINT edition). Also, having people pledge to the project will ensure I stick to it and get it done which is the main motivation for this campaign.

I am backing this project and so should you. ?Why? ?

  • The resource created will be valuable to everyone moving to Ruby 2.0.
  • The small amount of money to back the project will pay for itself in the time you save. ?Minutes based on your hourly rate, I’m sure.
  • Peter would like your support. ?He provides so much value to our community with his weekly newsletters for Ruby, JavaScript, HTML5 and others, that when someone so giving asks for support..it’s a no-brainer.
  • Peter needs the pressure from us, by raising the money to get it done.
Head over to Kickstarter and support The Ruby 2.0 Walkthrough. ?Many less worthy projects have been funded.

?

Share this:

  • LinkedIn
  • Twitter
  • Facebook
  • Email
  • More
  • Pinterest
  • Tumblr
  • Pocket
  • Reddit

Filed Under: Ruby Tagged With: kickstarter, peter cooper, Ruby

Get Your RubyTapas On

October 23, 2012 by Rob Bazinet Leave a Comment

Tweet

Rubytapas

I really love the efforts being put forward by people in our developer community, lots of cool new tools and especially screen casts. ?Screen casts are a great way to spend some time and learn something new.

One new screen cast that has quickly become one of my favorites is RubyTapas by Avdi Grimm. ?Avdi is a speaker, writer and a Ruby Rouge.

What’s RubyTapas?

These are short, 2.5 to 7 minutes in length, but are laser focused on a very specific aspect of Ruby and published 3 times a week.?

RubyTapas is for the busy Ruby or Rails developer who is ready to reach the next level of code mastery. Short screencasts three times a week will introduce you to a wide variety of intermediate to advanced Ruby concepts and techniques, as well as core Object-Oriented design principles. Lead by head chef Avdi Grimm (author of Exceptional Ruby and Objects on Rails), you?ll go from journeyman to master, one small, tasty plate at a time.

As I write this Avdi has published his 13th episode which covers singleton objects. ?The growing list of episodes can be found on the RubyTapas site. ? Subscribing to the full list requires a subscription, only $9 per month..so a great deal.

What’s to love about these?

Each episode is a super focused topic, great video and great sound. ?This isn’t the best part in my humble opinion; each episode comes with a very well commented Ruby file as well as an HTML document containing the episode explained so you can get a deeper understanding of the concept. ?

I have gone through all the episodes and they are pure Ruby, no Rails no Sinatra..just pure Ruby. ?I have been working with Ruby for a good number of years and I am learning a bunch from these, great style and techniques. ?I wouldn’t say they are for beginners but your mileage may vary.

I’m not affiliated with Avdi at all, just a happy subscriber. ?It’s sometimes hard to filter the good from the bad out there.??

Happy Hacking!!

Share this:

  • LinkedIn
  • Twitter
  • Facebook
  • Email
  • More
  • Pinterest
  • Tumblr
  • Pocket
  • Reddit

Filed Under: Ruby Tagged With: Ruby, rubytapas

Minitest Not Running My Unit Tests

September 17, 2012 by Rob Bazinet 2 Comments

Tweet

I have started using minitest for Rails 3.x unit testing and since it comes with Ruby 1.9.x by default, it seems like a good direction to take my testing.

I am using the great gem by Mike Moore called minitest-rails which has a minitest dependency so I can easily have the latest version of minitest. ?This gem helps to more cleanly integrate and use minitest in our Rails 3.x projects.

As part of my setup I use Autotest so my tests run automatically when files change. ?I noticed none of my unit tests were running and upon further inspection, minitest was looking in test/unit and test/unit test directories but not in the test/models folder, which seems to be the minitest default. ?

Opening up my .autotest configuration file and adding the following:

Autotest.add_hook :initialize do |at|
?at.add_mapping(/test\/models\/.*\.rb/) do |_, m|
??at.files_matching %r%^test/(models)/.*\.rb$%
?end
end

After restarting autotest, my unit tests are now being tested. ?I hope this saves someone some time.

Share this:

  • LinkedIn
  • Twitter
  • Facebook
  • Email
  • More
  • Pinterest
  • Tumblr
  • Pocket
  • Reddit

Filed Under: Ruby on Rails Tagged With: autotest, minitest, rails, Ruby, unit testing

RailsConf 2012 Wrap Up

May 2, 2012 by Rob Bazinet Leave a Comment

Tweet

IMG 0370

I was fortunate enough to be able to work out attending RailsConf 2012 in Austin, TX. ? This was the first time on many years that the conference was not organized by O’Reilly but rather Ruby Central, Inc.

I have to go on record and say I usually avoid cities but the city of Austin is a great place and would not hesitate to return. ?The people are friendly and there is so much diversity in the city that there is something new on each corner. ?I noticed an abundance of restaurants with so many different types of food. ?I can’t say I had a single bad meal during my journey. ?Everyone I spoke with about the trip said I had to try the BBQ, and they were right?it was fantastic.

IMG 0379

Many of the sessions overfilled the room. ?This on in particular exemplifies what I’m talking about. ?I bet the fire marshal wasn’t aware of these. ?Overall the floors were pretty comfortable.

It was often difficult to decide which sessions to attend, with 3 full-tracks there always seemed to be two talks during the same time slot I wanted to take. ?I usually decide which sessions to attend by how applicable they are to current work.

One of my favorite sessions was by Obie Fernandez about using Redis?with Rails. ?Although the examples of the talk were from his recent startup, they were excellent and showed integrating Redis into a Rails application not to remove ActiveRecord but to compliment it. ?Obie discussed a gem he released to help the integration called redis_props along with sample code used in the talk. ?The code is clean and concise?great stuff.

Another talk I found personal value in was the Semi Automatic Code Review by Richard Huang. ?Richard is the creator and maintainer of the Rails Best Practices gem. ?In the talk he discusses another related open source project called Railsbp.com which allows for your code to be reviewed when committing to Github. ?The results will be displayed on the Railsbp.com site where you can change the code right there and commit back to your repo. ?Very informative details produced from the site, GitHub allows hooks into the service and thoughtfully open sourced. ?I wasn’t aware of the site before but now I am using it regularly.

The other talk which I took a lot away from was Digging Deep with ActiveSupport::Notifications by Matt Sanders. ?This talk when into great detail with many examples of using notifications in your applications. ?It is similar to the event publishing and subscriber model from other platforms such as .NET. ?Having spent many years writing .NET applications this talk brought back many memories of this pattern. ?The techniques exemplified here I had never used in Rails but do need this functionality on a new project. ?

UPDATE (05/03/2012): One talk that was intended to be included here, is from Lori Olson. ?Her talk titled, Mobile Rage – What causes it & how to fix it?(Confreaks), takes the view of web application use on a mobile device from the user’s perspective and how developers can implement very simple techniques to ease the pain. ?I recommend this one highly, good stuff and some tips I was not aware of. ?I admit I have some sites that can take advantage of this. ?

IMG 0387

The final keynote of day one was from a non-Ruby developer, Rich Hickey, which seemed to be out of the ordinary. ?Maybe he was there to pull some Ruby developer to the Clojure world. ?It appears Rich is trying to convince these two Rubyist that LivingSocial would be better with Clojure. ?I wish I could have overheard the conversation.

There were three very large, two-sided, white boards used for companies to post jobs, and they were pretty full of opportunities. ?I noticed there were far too many companies attempting to make the next Facebook or Twitter and not enough companies creating really useful applications. ?There were exceptions from what I could see, but too few. ?I remember the same thing happening around 2000 and then the bubble burst. ?Apparently we are not better from this event in history because we have not learned from it.

I finally met face-to-face many friends I only knew from various social networks with lively hallway track discussions. ?I think this is the #1 reason to attend conferences. ?The materials from the talks are available everywhere and with Confreaks recording all the sessions, you can watch the show later. ?You can’t however, experience meeting new friends and seeing old ones without attending.

I recommend every Rails developer attend just one of these events, well worth the time and effort. ?The next on is in Portland, OR from April 29 to May 2, 2013.

Share this:

  • LinkedIn
  • Twitter
  • Facebook
  • Email
  • More
  • Pinterest
  • Tumblr
  • Pocket
  • Reddit

Filed Under: Ruby on Rails Tagged With: conference, railsconf, Ruby, Ruby on Rails

Next Page »

Recent Posts

  • How to Fix Rails Flash Rendering When Using Hotwire
  • Hotwire Fix for CORS Error when using Omniauth
  • Fix Installation of Ruby using rbenv on macOS Big Sur
  • RailsConf 2021 and the Future of Conferences
  • Fixing Out of Diskspace Errors on Amazon EC2

Categories

Services I Love

HatchBox - Easy Rails Deploys Fathom Analytics
Follow @rbazinet

Rob Bazinet
@rbazinet

  • Exactly this…. https://t.co/yWj7fZ01HR
    about 1 day ago
  • https://t.co/EmagdpLoNv "Introducing GitHub Copilot X · GitHub"
    about 2 days ago
  • RIP Gordon Moore: https://t.co/c5J9LaHrj8
    about 2 days ago
  • Our daughter works as a teaching assistant at a local K-8 public school. It’s become apparent that students today r… https://t.co/p2t912GVyc
    about 2 days ago
  • Working to wrap up my current consulting gig by mid-April. I will be looking for the next thing soon. If anyone has… https://t.co/sg3cSV9yqM
    about 3 days ago
  • RSS - Posts
  • RSS - Comments
Find me on Mastodon