Monday, May 12, 2014

Diarrhea Cure

Healthy software development starts with healthy mind and body.

Here is my cure for diarrhea.

Ingredients:
1 handful Guarilama
5 teabags of chamomile tea (te de manzanillo)
5 ripe guava
4 tablespoons linseed (semilla de linaza)
2 liters of water

Preparation:
1. Bring 2L of water to boil with the Guarilama, chamomile tea, and guava.
2. Turn off heat and mix in the linseed.
3. Let sit for about 5 minutes.
4. Chill.

Serve chilled and drink 2-3 8oz glasses per day. Symptoms should improve within a few hours of the first glass.

Thursday, March 20, 2014

4 Quick ProTips for New Ruby on Rails Programmers and Managers

I'm writing these four tips for programmers and managers who are starting to work professionally on projects using the Ruby on Rails development framework. These tips are helpful in fine tuning your understanding, and productivity on the apps you are working on. Bottom line, your team mates and project managers will be happy you have these things under control.

  1. "Read the code"

    Often, our expectations mislead us and the code that we or others have written produces different outcomes. The first reaction might be to ask other team members for help. The next time you hit this, first ask yourself, "Did you read the code?" Did you read it all? Did you go to the next file in the stack-trace? Did you dig into dependent gem's code? You see new methods or syntax you don't understand? Keep reading! The solution is in the code!

  2. rake routes

    Are you curious about a path in the app that you need to hook up client-side code to? The Rails stack along with rake has a slick command that breaks down all the paths that the app handles. Simply run: rake routes
    Does the app have tons and tons of routes? Pipe the output through grep to search for the keyword you are looking for: rake routes | grep 'resource_name'

  3. Speed up your Rails Environment

    The faster your environment, the faster you can deliver value on your projects. Rails apps grow, and loading dependencies takes time. Constantly look for ways work around these known obstacles and you will find you can quickly iterate on your rails app confidently. For many years I found myself waiting for test runs, console restarts, rake tasks, etc. I recently started using a tool (zeus) to eliminate these wait times. Make sure you and your team aren't wasting time.

  4. Write integration and unit tests

    Without evidence of a fully integrated system, you have no control of your app. This lack of control quickly will be seen in uncontrollable errors, costs, and expectations. Do your team a favor and demand any code commit for feature or bug fix go in with passing unit and integration tests. But we aren't just writing test code for clients, we're writing them for other programmers too! I currently prefer using rspec for unit tests and cucumber with capybara for integration specs where browser interaction is required.

Friday, November 8, 2013

Move terminal cursor to front of prompt while attached to GNU Screen

Moving your cursor to the front of a terminal prompt will save you time and frustration. To move your cursor to the front of the terminal prompt in a bash shell session simply use the key binding

C - a

Since it is common that C - a is the key binding for GNU Screen, you have to use:

C - a - a

The other option is to bind it to a key for your shell. In bash, add this line to ~/.bashrc

bind '"\C-p": beginning-of-line'

Then

source ~/.bashrc

Now you can nail that cursor home anywhere with:

C - p

This is the two-step of terminal prompt dance moves. Learn it.

Thursday, October 17, 2013

An overview of pub/sub in the Ruby on Rails ecosystem

It’s not AJAX, it’s PUB/SUB

The following will look at the basics of pub-sub and review a number of pub-sub solutions for ruby/rails apps.

For many web apps, we want to notify our users about activity within their network. This is broken down into two steps 1) knowing when there’s a notification and 2) displaying it.

With AJAX, we can send asynchronous requests to check app endpoints for updates, but this means lots of requests.

It’s 2013 and the new way to address this challenge is called pub-sub. There’s a publisher (publishing notifications) and our users, once online, become subscribers to the publications.

The means the messages are pushed instead of pulled.

The transfer of these pushed notifications commonly utilize either Websockets or the Server Sent Event (SSE) methods to push data to the clients.

The websocket protocol is established over http or https, using an upgrade handshake request from the client to the server. If properly validated, a full-duplex data transfer is initialized between the client and server on the ws or wss protocol. As of Thursday October 17, 2013 all the latest browsers except Android browser support the latest specification (RFC 6455) of the WebSocket protocol.

Server Side Events are part of the HTML5 EventSource API. The browser is set up listen for text/event_stream server responses. They are not currently supported for IE.

It's important to understand what Websockets and SSE are so you can make the right decision for which technology you want to integrate into your production stack, and to understand the limitations of each.

What tools are available to do pub-sub in your rails app? Here are a few options...

Pusher.com

Pusher is a commercial service that handles all websocket interaction and exposes an API for publishing to subscribers.

Pros:

-Should work out of the box making it fast to integrate, and offer the same basic features we'd get from Faye
-Rails 3 compatible

Cons:

-Seems like the android browser is out of the picture since it's websockets backed.
-Connections limited based on your service plan
-Not Free

Rails

Rails 4 offers the ActionController::Live mixin to do SSE.

Pros:
-No additional gems needed

Cons:
-No IE support

For Rails 3 Aleksey Magusev shows a dead simple implementation which seems to work in Rails 3. A simple response object sent to establish and feed the SSE stream, and it's handled by an instance of the EventSource class in the HTML5 compliant browsers. In a load-balanced server environment, this solution might not be enough since connections could be left open.

Faye

Faye, has been around for a while (2009) and recently hit v1.0. It is an implementation of the Bayeux protocol over websockets (supported by faye-websocket) and uses an in-memory or redis engine for storage and message semantics. Enabling redis supports load-balanced (distributed) servers. It utilizes it's own websocket impmentation faye-websocket - https://github.com/faye/faye-websocket-ruby and a redis client - faye-redis - https://github.com/faye/faye-redis-ruby.

Pros
-Actively maintained, mature project
-Can push messages for Chats and more
-Can be used across multiple devices
-Solid candidate for a production pub-sub platform

Cons
-Comprehensive configuration options might be overkill
-Requires configuring redis

Closing Thoughts

True pub/sub means turning on websockets or SSE. The faye platform offers a complete solution for production systems, with fine tune-able configurations for single direction and bi-directional streams. If you are looking to extensively use pub/sub in your app, it’s worth taking the time to intrgrate faye. For quick streams, the rails solution offers less strings attached approach.

Tuesday, April 9, 2013

Full Stack Developer Retires MacBookPro for Ubuntu Laptop

Since I began developing with open source technologies in 2007, my computer of choice was the MacBookPro (MBP).

The MBP continues to be a great system for developing open source software, but at this time, when I started looking for my next development workstation, speed, service and value were the leading factors, and it made more sense to stop working with the MBP and start working on a laptop that doesn't glow Apple.

I will miss the MBP's glowing keyboard, and I will miss the magnetic click of the power adapter. However, I will not miss needing to drop $80 for a new adapter after my daughter decides to suck on it like a chew toy.

AppleCare is a fantastic service plan that I have utilized to keep the MBP in tip-tip shape in the USA and Costa Rica. Now, I'm living too far away from an Apple Store to get a F'ed system in the hands of a "Genius." My town has a sharp computing community and would not have a hard time serving any issues on a generic system.

The features I wanted in my new system were a Solid State Hard Drive for fast disk read/writes, and a monster dose of RAM (16 Gig). The MBP with retina display offered these features, for a hefty price. Adding the AppleCare support plan gave me pretty expensive system that I would need to dump in three years when the warranty expired.

I've learned the lessons on servicing computers in Costa Rica and know the risk of carrying around a $2K system. It's time for something new.

I'm empowering myself to continue the journey in open source software and Linux operating systems. The seven years that I have been working with Linux hosting environments has given me the chance to learn how to be productive in the Linux environment. I am excited to add to that knowledge and offer clients more "full-stack" skills. Developing on a Mac and managing production environments are two different animals. Bringing the practices of maintaining secure production systems back to the workstation is clearly the new win-win to work towards.

Sunday, January 13, 2013

Dreamhost Server Blocking Emails From Getting Sent

For anyone who has a rails project hosted on Dreamhost that sends emails this might affect you. Some time recently Dreamhost updated their security setting for sending mail through their SMTP servers and now require plain authentication to send mail through your localhost.

If your error log looks like this, you definitely need to make sure you are getting authenticated to send email.

Dec 28 17:51:16 servernuts postfix/smtpd[57430]: NOQUEUE: reject: RCPT from localhost[127.0.0.1]: 554 5.7.1 : Recipient address rejected: Access denied;
In your rails app environment files you can enable authentication:
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => "localhost",
:port => 587,
:domain => 'foobar.com',
:user_name => '',
:password => '',
:authentication => 'plain',
:enable_starttls_auto => true }

I am not a fan of this update since one would have to put their shell account credentials in a codebase. This is a good reason to check out something like postmarkapp or sendgrid.

Saturday, January 12, 2013

Problem Solving: Thread a 1/2 in. tube

Problem solving is an art. Here's a problem I recently faced outside of the software engineering space, but I felt it was worth posting here.

The problem: Running copper wire through 90 meters of 1/2 tubing

Background: I decided it was time to extend my electricity line to a structure about 60 meters from the source. With 120 meters of copper wire in hand I set off on the challenge. To protect from weather, I wanted to make sure the wire is insulated in a plastic tube. It became apparent rather quickly that the cable wasn't going to walk itself through the tube.

The solution: +1 to my neighbor who happened to be walking by and gave the suggestion that ultimately did the trick.

Materials:
100 meters of fishing line
Small piece of foam that with a little squeezing will fit in the 1/2 in tube
100 meters of all purpose twine
Water source (hose will work)
Sharp piercing object that will pierce tube

  1. Start off by unraveling the tubing
  2. With your piercing object, make a small hole about 2 inches from the high end of the tube. My hole was small enough to pass the fishing line through, but small enough that a pencil wouldn't enter
  3. Put the tip of the fishing line through this hole and pull it out the closest end of the tube
  4. Tie off the sponge
  5. Push the sponge towards the low and end apply water source
  6. Watch the fishing line get pulled into the tube with the sponge fighting the force of the water
  7. Your sponge will eventually come our of the other end of the tube and you can tie off the fishing line the the all purpose twine and feed the twine through the tube by pulling on the fishing line that the water fed down the line. I had to run the twine because my fishing line was pretty light weight and probably would snap if the copper wires were tied off to the line
  8. With the twine capable of resisting more force, tie it off of the copper cables and pull the suckers through.

    ----------------------------
A     .                            B
    ----------------------------