Midwire

Ruby, Elixir, Macintosh and Other Technical Maunder.

Elixir - Time Ago in Words

After reading the excellent book “Programming Elixir”, by Dave Thomas, and “Programming Phoenix”, by Chris McCord, Bruce Tate and José Valim, I decided to dive in.

As of this post, I am currently writing an Elixir app using the Phoenix framework. It is called Tunedrop and I am working on it for two reasons:

  1. To learn Elixir and Phoenix
  2. To share some of the music that I grew up on with my kids

You can see the code here.

It is definitely a work in progress and may look pretty raw at times. However, I wanted to share how easy it is to port code from Ruby to Elixir for your benefit, happiness and profit.

As I play music in iTunes, Tunedrop dynamically posts the song’s artist, name and year released, along with the time it was played. Originally, the time played was absolute and looked like this: 4/12 15:32. I wanted to look something like the Rails ActionView::Helpers.distance_of_time_in_words:

listings

Here’s how I did it:

Preparation

I’m using the timex Elixir library for DateTime manipulations. I followed the directions there to install it into my Phoenix project.

TimeHelpers

The Tests

In tunedrop/test/views/time_helpers_test.exs <- click the link to view the entire test module.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
defmodule Tunedrop.TimeHelpersTest do
  use Tunedrop.ViewHelperCase
  use Timex

  test "returns time in words for now" do
    time = DateTime.now
    words = Tunedrop.TimeHelpers.distance_of_time_in_words(time)
    assert words =~ ~r/Less than 1 minute/
  end

  test "returns time in words for 30 minutes" do
    time = DateTime.shift(DateTime.now, minutes: 30)
    words = Tunedrop.TimeHelpers.distance_of_time_in_words(time)
    assert words =~ ~r/30 minutes/
  end

  ...
end

The Module

In tunedrop/web/views/time_helpers.ex <- click the link to view the entire module.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
defmodule Tunedrop.TimeHelpers do
  use Timex
  alias Timex.DateTime

  @moduledoc """
  Helpers for DateTime display
  """

  @doc """
  Generates approximate distance of time between two times in words.
  """
  def distance_of_time_in_words(from_time, to_time \\ DateTime.now) do
    case from_time > to_time do
      true ->
        from = to_time
        to = from_time
      false ->
        from = from_time
        to = to_time
    end
    distance_in_seconds = abs(DateTime.to_seconds(to_time) - DateTime.to_seconds(from_time))
    distance_in_minutes = abs(round(distance_in_seconds / 60.0))

    words = case distance_in_minutes do
      n when n in 0..1 ->
        "Less than 1 minute"
      n when n in 2..45 ->
        "#{n} minutes"
      n when n in 45..90 ->
        "about 1 hour"
      n when n in 90..1440 ->
        "about #{round(n / 60.0)} hours"
      n when n in 1440..2520 ->
        "about 1 day"
      n when n in 2520..43200 ->
        "about #{round(n / 1440.0)} days"
      n when n in 43200..86400 ->
        "about #{round(n / 43200.0)} months"
      n when n in 86400..525600 ->
        "#{round(n / 43200.0)} months"
      _ -> "a long time"
    end
    words
  end
end

I’m sure this code could be better, but what I’m impressed with is how easy it is to port code from Ruby into the pattern-matching paradigm of Elixir, and how similar it looks to the original Ruby code.

Why Not Google Chrome?

Why you should not use the Google Chrome browser

As an internet software engineer, I often get asked why I don’t use Google’s ever popular Chrome browser. My answer is often met with disbelief. So I decided to answer the question once and for all with proof behind my reasoning in this six and a half minute video.

I posted the video on youtube back in August of 2015. An interesting fact is that it is virtually impossible to find the video using a Google search or a Youtube specific search. That’s right; Google refuses to index the video. If this doesn’t confirm the nefariousness behind the Chrome browser what will? Will Google simply remove the video? Probably. I propose they will remove it if it begins to gain any traction.

Try this: Do a search for “why not google chrome” or “why you shouldn’t use the chrome browser”. I’m betting that you will not find a single article or video that exposes their tracking as I do in the linked video. You will most certainly not find my video.

The clear fact is that Google tracks your every move when you use their browser. They don’t want you to know that.

If you want a browser experience without sharing every site you visit and single click you make with Google, use Firefox.

In addition, I use startpage.com instead of google.com for all of my searching. Startpage gets their results from Google but they don’t record your searches and correlate your IP address, etc.

Good luck

A Useful ~/.irbrc File

Here is my ~/.irbrc file.

~/.irbrc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
require 'irb/completion'

def what_methods(obj)
  (obj.public_methods - Object.public_methods - Object.instance_methods).sort
end

def wm(obj)
  what_methods(obj)
end

def predicates(obj)
  what_methods(obj).grep(/\?$/)
end

def locate(obj, method)
  obj.method(method.to_sym).source_location
end

It contains 4 useful methods as follows:

what_methods

Allows you to determine what methods are available on an object without displaying all of Object instance methods. The following irb session calls what_methods on an Array instance:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
ary = [1,2,3]
what_methods ary
=> [:&,
 :*,
 :+,
 :-,
 :<<,
 :[],
 :[]=,
 :all?,
   # ...
 :uniq,
 :uniq!,
 :unshift,
 :values_at,
 :zip,
 :|]

Note: wm is just a shortcut for what_methods, cuz I’m lazy.

As you can see, it lists out all public instance methods for the Array instance, ary.

predicates

Predicates is similar to what_methods. It actually calls what_methods and filters out all but methods that end with a question mark (predicates).

1
2
3
ary = [1,2,3]
predicates ary
=> [:all?, :any?, :empty?, :member?, :none?, :one?]

Pretty cool, huh?

locate(obj, method)

Have you ever been at some breakpoint and wanted to look at the code for a specific method? This tiny method lets you do just that.

1
2
3
get :index
locate response, :ok?
["/Users/midwire/Code/ruby/Rallyhood/rh_svc_analytics/vendor/bundle/ruby/2.2.0/gems/rack-1.6.4/lib/rack/response.rb", 126]

How about that? It even gives you the line number along with the file where the method is defined.

To use these in an irb session, just copy them into your ~/.irbrc file. However, that won’t help if you plan to use them during a pry session. For that just copy them into your ~/.pryrc file.

Enjoy!

Securing Your Workstation

With all of the revelations from Edward Snowden about the unconscionable and patently unlawful (unconstitutional) NSA spying on Americans and the world, here are some tips on how to secure your computer to make it more difficult for this traitorous organization to spy on you.

1. Use an anonymizing VPN service

You’ll want a service that provides a VPN (Virtual Private Network). Many services, like BTGuard, do not provide a VPN. It only masks your torrent traffic. Whereas a VPN sends all of your network traffic through the anonymized connection.

TOR (The Onion Router) by itself is not good enough either. TOR is only for browsing the web anonymously. It does help but is not foolproof. It doesn’t take much for the venal NSA, CIA, FBI, et al. (a.k.a. Axis of Evil) to trace back to you, even through TOR. In addition TOR is not a VPN. It only masks your web browsing traffic.

There are many to choose from. I have my favorite (which I will not divulge) but here is a list of a few anonymizing VPN based proxy services that I know of. I would stay away from free services, which could easily be a front for the previously mentioned Axis of Evil. In reality any of these services could be funnelling data to said Axis of Evil. Trust is all but gone and the ‘law’ will not help you.

We must ask ourselves the important question, do any of these proxy services have backdoors for the Axis of Evil? The answer is, there is no way to know for sure. Life Hacker has an article about the trust issue.

Even though you are connected to your anonymizing VPN service be careful of logging into any personal accounts. Doing so can provide a means of tracing traffic back to you. It is not possible to forever avoid logging into your accounts (email, et al.). Just be aware that doing so can help reveal you to the Axis of Evil. Think of it this way, if you want to surf the web anonymously then surf the web, but don’t login to your email account using the same session. If you want to check email, then login and check email, then disconnect then reconnect to your VPN using a different server and session to browse the web again.

Note: If you decide to use a VPN service, don’t just choose a server in single country and always use it. Switch things up, daily. For example, use Sweden for a day, then switch to Canada the next day. Of course this is assuming the VPN provider you choose has servers in multiple countries. Hint: Choose a provider with servers in multiple different countries. Do your own research!

2. Frequently modify your MAC address

A MAC address (or Media Access Control address) is the unique ID for your network interface controller (NIC). It is a hardware serial number but it can be changed using software.

Here is a script that I use for changing a MAC address. I use it on OSX but it may work on Linux as well.

It is prudent to change your MAC address at least every bootup. It may be better to change it on a regular schedule as well (i.e., every 24 hours).

Be aware that this can have the side effect of changing your IP address or confusing certain software or hardware peripherials (i.e., DHCP reservations).

3. NEVER use Microsoft Windows!

Microsoft has been revealed to be working with the Axis of Evil. However, it would be naive to think that Apple or other hardware and software manufacturers are not doing the same thing.

The main problem with Windows is that it is very unstable, insecure, buggy and often full of viruses and trojans. I’ve been a professional in the computer industry since 1989, and I can tell you (to the dismay of Windows fanboys) that Windows is the abolute worst, most insecure and unstable operating system under widespread use today.

The most secure and trustworthy OS is Linux/GNU. Why? Because it is open source and you and I, and other smarter people, can go read the source code and see what kind of shenanigans may be going on. Does that provide any guarantees? Absolutely not. Case in point, the Heartbleed bug in SSH.

Personally, I use OSX and have found Apple hardware to be far better than any other. In the past I’ve built my own high-end machines and owned Dells, Gateways, etc. It took a long time for me to jump in and purchase a more expensive Apple computer. Once I did the fog was lifted from my eyes. I’ve still got the first MacBook I purchased after the turn of the century. It still works wonderfully, albeit slowly. Macs just work, and when you drop one on the sidewalk Apple customer service has proven to be the best in the world.

4. Use Firefox

As a software engineer, most of my colleagues choose to use Google Chrome as their browser of choice. My own personal view is that since Google itself frequently hands over data to the Axis of Evil, why on God’s green earth would I use a browser that was developed at the same company?

In my opinion, Firefox can be secured better than Chrome and Mozilla (the company behind Firefox) is not beholden to Google.

5. Don’t Use Google

As stated in a previous article, Google is evil, period. Don’t use it for your search engine, email, their DNS servers (8.8.8.8 and 8.8.4.4). Avoid Google like the plague. See the linked article for alternatives.

There are also alternative DNS providers.

You can tell I hate Google. And, as is with most websites that are critical of them, you will never find high-ranking links back to this site in their index.

6. Watch Your Traffic

As with anything important, pay attention! Watch your IP traffic over the network. On Linux or OSX you can use iptraf or iftop to watch where your traffic is coming and going. You may spot some interesting hostnames like ‘gv-in-f103.1e100.net’, which is Google. Using ‘iftop’ I found an app that was connecting to Google from my machine. Those insidious bastards!

Note: Little Snitch also provides a traffic monitor.

7. Use a Firewall

Whether you use the built-in firewall and tools that come with your operating system or purchase a full-blown professional firewall appliance, don’t neglect the firewall.

Personally, I use the built-in OSX firewall and Little Snitch on my own machines. In addition my LAN is sealed off by a ZyXEL, ZyWALL USG 50.

I highly recommend Little Snitch for OSX users. Iptables works wonderfully for Linux/GNU users.

8. Use Encryption

Just like a padlock on a locker, if someone wants to break-in they will cut the lock. We just want to add as many locks to our data as possible. Our locks are encryption.

  • Encrypt your email using GPG. Encourage your friends and family to do the same.
  • Use HTTPS (SSL) instead of HTTP wherever possible. Even though SSL is clearly hackable or circumventable, it is another ‘lock’ that takes time to successfully break.
  • Use SSH for point-to-point remote connections and tunnelling.

Summary

Understand that the corporate government of America owns, or sits on, all the major switches on the Internet. They have access to all traffic and funnel it into their Utah Data Center. If they want to track you, it cannot be stopped. All you can do is make it more difficult for them. But if you are on one of their many lists, the only way to have computer privacy is to detach it from the internet, and even that guarantees nothing.

Welcome to the world we live in.

– Midwire

RSpec Shared Contexts

I love RSpec! Though I know Cucumber fairly well too, as a backend developer I use RSpec almost exclusively. Cucumber is better for having tests that muggles (non-programmers, executives, suits, etc.) like to execute and look at, IMHO.

I really appreciate Philippe Creux’s post on the way he uses RSpec. I do all of those things as well but I have also found shared contexts to be extremely useful in helping to keep my specs DRY.

They are really easy to use. We typically have a spec/support directory in which we put shared stuff, used across more than one set of specs. I like to create a file called shared_contexts.rb and inside we put code like this:

./spec/support/shared_contexts.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
shared_context 'authentication' do
  let(:user) { login_user(FactoryGirl.create(:user)) }
  let(:auth_params) do
    {
      public_key: Settings["api_keys"]["public"],
      app_token:  ControllerMacros.generate_app_token,
      user:       {remember_token: user.authentication_token},
      format:     :json
    }
  end

  def login_different_user(user)
    login_user(user)
    auth_params[:user] = {remember_token: user.authentication_token}
  end
end

Then, in your actual specs, you can do things like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
require 'spec_helper'

describe Api::V3::PhotoCommentsController, 'Actions' do
  include_context 'authentication'
  ...
  context 'on POST to #create' do
    let(:new_comment) do
      {comment: 'created from rspec'}
    end

    it "does not allow non-related user to post a comment" do
      login_different_user(FactoryGirl.create(:user))
      expect {
        post :create, auth_params.merge(new_comment)
      }.to change(GalleryComment, :count).by(0)
      response.response_code.should == 401 # not authorized
    end
  end
end

If we didn’t use shared contexts, we would have to repeat the login_different_user method declaration and the necessary let variables in every spec that uses them.

DRY is a fundamental principle that keeps code maintainable and with fewer bugs. Just do it!

– Midwire

Rack, Paperclip, File Uploads & RSpec

So I’ve been writing a couple Ruby services, for Rallyhood, using Padrino. We’ve got Rallyhood Authentication Service (RAS) and I’m currently working on Rallyhood File Service (RFS).

Writing my specs for the assets controller, I ran into:

1
2
3
4
5
6
7
8
9
  1) AssetsController POST on /assets uploads the file
     Failure/Error: post '/assets', params
     Paperclip::AdapterRegistry::NoHandlerError:
       No handler found for {:filename=>"rails.png", :type=>"image/png", :name=>"asset[attachment]", :tempfile=>#<Tempfile:/var/folders/34/4z_fjgbs7ys9c3rzj1cgdn6r0000gn/T/RackMultipart20140131-97373-1iy6kt6>, :head=>"Content-Disposition: form-data; name=\"asset[attachment]\"; filename=\"rails.png\"\r\nContent-Type: image/png\r\nContent-Length: 6646\r\n"}
     # ./app/controllers/assets.rb:19:in `block (2 levels) in <top (required)>'
     # (eval):108:in `block in call'
     # (eval):98:in `catch'
     # (eval):98:in `call'
     # ./spec/app/controllers/assets_controller_spec.rb:30:in `block (3 levels) in <top (required)>'

Subsequent web searches revealed various unrelated issues. So after spelunking in the Paperclipe code I found the exception being thrown was due to the uploaded file being represented by a Hash (Rack converts it into a Hash), and that Paperclip does not provide an adapter for this Rack specific Hash out of the box.

The Hash looked like this
1
2
3
4
5
6
7
8
9
10
11
12
13
{"remember_token"=>"75806eba-a178-43ad-a49b-6632c49e8970",
 "oauth_token"=>"nmou6vz3kk6gx1yq8hqw3pygq97srrq",
 "asset"=>
  {"user_id"=>"730",
   "folder_id"=>"1",
   "attachment"=>
    {:filename=>"rails.png",
     :type=>"image/png",
     :name=>"asset[attachment]",
     :tempfile=>
      #<File:/var/folders/34/4z_fjgbs7ys9c3rzj1cgdn6r0000gn/T/RackMultipart20140131-97556-i2p4b>,
     :head=>
      "Content-Disposition: form-data; name=\"asset[attachment]\"; filename=\"rails.png\"\r\nContent-Type: image/png\r\nContent-Length: 6646\r\n"}}}

I figured someone had to have run into this issue before. I then looked for a gem and found paperclip-rack.

Added this to my Gemfile

gem 'paperclip-rack', require: 'paperclip/rack'

… which fixed the issue.

Software Development - Onsite or Remote?

I’ve been in the Software Development business since 1990 and seen a lot of changes in the industry. From GUI-less operating systems and using the “C” language to the world-wide-web and high-level expressive languages like Ruby, things have changed. Some things have come full circle like client-server architectures to ‘the cloud’. One thing that has changed for the better and to its logical conclusion is the ability to telecommute.

Back in the day there was no choice. The internet did not exist and in order to make a living you had to take the time to travel to work everyday, spending your own money for gasoline, wear and tear on your car and sit in a tiny cubicle with no window to write code on a monochrome text-only green or amber colored CRT (Cathode Ray Tube). They weren’t called monitors back then.

Now we live in the age of the “Internet Superhighway” (another throwback term), and we have the option to work remotely from a home office. Taking advantage of this option provides many benefits:

  • Environmental: Far fewer people are required to travel for work, using combustion powered vehicles which are bad for the environment.
  • Financial: This benefit is two-fold in that telecommuting saves money not only for the employer who doesn’t need to provide office space, computers, electricity, water, restrooms, etc., but it also saves money for the employee who no longer has to spend money on gasoline and car maintenance. Employers typically save between 30 to 70 percent on employees who telecommute even part time.
  • Time: The employee can now often save hours each day on commuting and spend that time working or with family.
  • Productivity: Workers that work from home tend to be happier and more productive. Telecommuters are less likely to be absent from work and can more easily manage their time. It is also proven that telecommuters produce higher quality work. In addition employers who are willing to hire remote workers have a much larger pool of high quality talent from which to choose.

Some employers like to throw up the “what about security” issue. With modern day VPNs security is not a concern unless you don’t trust your employee to begin with. Who wants to work for an employer that doesn’t trust you?

All of these jobs nowadays that require software developers to work “onsite” astound me. In this day and age to require software developers to drive to a brick-and-mortar building everyday is simply ridiculous. That kind of policy is a sign of one of two things:

  1. The employer is ignorant of the benefits of telecommuting.
  2. The employer has management issues. Management doesn’t trust their employees to work independently and report their time honestly.

So, to all of the recruiters/head-hunters that keep trying to ‘relocate’ me in order to make a few bucks… give it up! I don’t work onsite!

Minimizing NSA PRISM

With the recent revelation about the illegal NSA spying on American citizens, it is advisable to do what we can in order to curb or limit the NSA’s ability.

Below are some of the ways you can do this.

Browser

Use Firefox

Why would anyone want to use Google’s Chrome browser when they (Google) are the largest provider of PRISM data in the world? Does anyone actually trust Google with their data? The question is obviously rhetorical since we know that millions of users use Google services and applications.

Firefox allows extensions. I don’t want to get into any religious argument over why Chrome, Opera, Safari or any other wannabe browser is better. The fact is that Firefox, with the right extensions, is the safest, most secure browser available today. Just use it!

There are some very good extensions that I would simply not want to live without:

  • NoScript. NoScript disables Javascript by default. When you need to use Javascript you simply allow it temporarily. There is no good reason to allow Javascript to run on every web page you visit. It can be malicious and is the number one way for companies and governments to track you on the web, so why trust it?
  • Ghostery. Ghostery notifies you of, and blocks by default, web tracking through cookies, invisible pixel images, etc.
  • Disconnect. Another plugin to help prevent tracking on the web. This will catch most anything that Ghostery doesn’t.
  • MaskMe. MaskMe’s free email masking is perfect for eliminating spam. It provides masked emails on the fly and forwards emails until you tell it to stop. Let’s say you go to a job hunting website like monster.com and sign up using a MaskMe email address like ‘abcdefg@opayq.com’. When Monster sends you an email it gets forwarded to your real email address. But all of a sudden one day you start getting emails from jobhat.com, and other such websites that you never signed up for. Simply disable or block that particular masked email and the spam goes away, forever. Never give out your real email address again. Ever!

Search Engine

Then there is the search engine. I remember back in the 90’s when Google was just trying to hold their own next to Yahoo. I was a big Google evengelist because I didn’t, and still don’t, like mega-corporations and the data they collect. Google has since become far more nefarious than Yahoo ever was. They actively participate in the illegal NSA PRISM program, and every time you search using Google your information is captured and stored for future use against you in a criminal, or possibly military, court. In addition most websites now use Google analytics, Google fonts or Javascript stored on Google. That means every time you visit a website that uses one of these services, Google tracks and saves a record that you, “insert name here”, visited that particular website, the time of day, what you clicked on or downloaded and possibly any data you entered while there.

It is purely speculation, but what happened to all of the legal trouble Google was in back in 2012? There were antitrust issues, alleged copyright infringments and other alleged predatory practices. All of that seemed to silently just go away before this new PRISM revelation. Coincidence? I think not. Google has likely made a deal with the US government to provide private information in return for prosecution exemptions.

Let’s face it… Google is evil! Period.

Use Startpage or Ixquick for a more secure search experience. They are from the same company and located in the Netherlands.

Startpage provides anonymous Google results, and Ixquick provides a separate index, but both aparently privately as they say they do not track your IP address or use cookies for anything but storing preferences.

Operating System

It is clear that Microsoft and Apple are both participating in the PRISM program. The safest OS is Linux-GNU. Why? Because you can download, examine, modify and compile the kernel and all of the GNU tools and utils. That said, OSX (a FreeBSD derivative) can be made relatively safe as well.

I will not personally use Windows, ever. Nor will I allow anyone in my immediate family to use any of the horrible and unstable Microsoft operating systems.

OSX

If you use OSX, as I do, it is simply a must to purchase and learn to use Little Snitch.

I also own an Apple Airport router. Recently I fired up my AirPort Utility application and Little Snitched warned me that it (AirPort Utility) was trying to send information to “dni.gov”! I am not kidding. The Director of National Intelligence website! This is a good site to block, so I told Little Snitch to never let any of my applications contact dni.gov. Of course they will likely modify their code to use some arbitrary IP address, to which I will promptly block as well. Using Little Snitch, always block unless you are sure of the traffic you are allowing. If you have a question about a particular IP address or application use Startpage to search for answers.

Do NOT use iCloud if you are using an Apple product. Just turn it (iCloud) off and store your data locally. Backup to USB drives or external drives but never use their cloud.

Cloud Services

Avoid cloud services like DropBox and obviously GoogleDrive when storing any sensitive information. It is also a good bet that Amazon cloud services are part of PRISM. Avoid if possible.

Email

It is difficult to find a proven secure email hosting service. Even Hushmail has its issues. A good alternative is to encrypt your own email and when sending unencrypted email to anyone, just assume that the NSA and every other government agency will get their eyes on it.

Encryption

Mac users have a wonderful option in GPGMail. The main drawback is that most users don’t understand or use email encryption. You cannot send an encrypted email to anyone who does not have a public key.

Spread the word and convince everyone you know to use GPG encryption for their email.

Conclusion

Lastly, avoid non-free scanning programs like: PrivacyScan that supposedly do everything for you at the click of a button, for a price. They can do a few good things but they will not change your bad habits or force you to use Firefox and GPG encryption. You can do more to protect yourself by following the ideas and tips in this article or doing your own research for free.

EVGA UV + 19: Mac Third Monitor Testing

Disclaimer: I am not paid to review products. This post is here in hopes that it will benefit someone wanting more than 2 monitors for their Macbook laptop. If you do happen to click on one of the Amazon links below and purchase one of these products, Amazon will add a few cents to a gift card for me to use the next time I want to buy a Kindle book.

As a software engineer I value my Mac hardware a great deal. My ideal setup would be a Mac Pro tower at the office, with 3-4 monitors and more RAM than I would ever use. However, in this business we need to be mobile so we can work at the office, from home or while we are at the beach in Belize. Onsite is almost always out of the question, but that is another rant.

So, we are stuck with our Macbook Pros supporting only 8GB of RAM and a single external display. Us Mac users really love the ability to attached a huge second monitor to our Macbook Pros. It is invaluable for software development, especially when pairing remotely, but a third monitor would be even better. After looking at several different options I came up with two likely solutions.

  1. EVGA UV + 19: $58.49 from Amazon
  2. Matrox TripleHead2Go: $306.99 from Amazon

With Amazon’s excellent return policy, I decided to start with the less-expensive EVGA solution. If it doesn’t work I will return it and spring for the Matrox hardware.

I got the UV Plus from Amazon within 3 days. Opened up the package and found the following:

  • The small 2.5-inch square device, 7/8ths of an inch thick
  • A retractable USB cable
  • A VGA-DVI adapter

EVGA UV Plus

I planned to try out the device at the office where my large third monitor lives. Being impatient as I am, I decided to install the driver and hook it up to my second large monitor which lives at home, and is usually plugged into the mini-dvi on my Macbook Pro. Installing the driver requires a reboot, but after I found that the device does indeed work. The video had a slight, noticeable lag when moving the mouse or dragging a window. But the Display manager worked and allowed my Macbook to arrange what it considered a new monitor, and I could drag things to it and away from it.

Being happy that it worked, I unplugged the device and plugged my second monitor back into the mini-dvi interface. My Macbook then began acting increasingly strange. Apps started being unresponsive and everything start to crawl along at intolerably slow speeds. Finally, I uninstalled the driver using the uninstall icon that came with it and everything went back to performing normally.

Before I send it back I plan to try it again at the office where I can leave the third monitor hooked up. I have a feeling that the EVGA device will end up being returned in favor of the Matrox solution.

Stay tuned for updates…


Update: 01/10/2012: After setting up my 2 external monitors at the office, re-installing the DisplayLink (EVGA Plus) driver, and plugging everything in, I am extremely pleased to announce that everything works! No race-conditions occur, even when unplugging the EVGA monitor. I have a feeling that plugging in a monitor to the EVGA device that was previously setup as an OSX native second monitor causes race conditions.

3 Monitors

Anyway, now I have three monitors and my development setup couldn’t be more perfect. Another monitor would cause me to strain my neck :)

Conclusion: For less than $60.00 USD. the EVGA UV Plus 19 works! This makes me extremely happy!


Update: 01/17/2012: Another few days went by and I have started to see problems. Processes seem to be running slow, video on all three monitors seems to jump and be slow as well. The actual CPU usage is very low but nevertheless performance has started to suffer. Unfortunately I cannot tolerate these kinds of issues during a typical workday. I have uninstalled the driver. Will give it one more shot before I send it all back. At this point I am disappointed. I may make one more updated entry if anything changes (i.e. if performance doesn’t drop off during my next test). Otherwise I have changed my conclusion.

Updated Conclusion: The driver still seems a bit buggy. Performance suffers intermittently. Work becomes intolerable. If you don’t want to deal with these kinds of issues, I sadly recommend not using this product. Hopefully the DisplayLink people will fix the driver issue soon.

Update: 06/27/2013: After a year and a half of using the EVGA UV Plus 19 I can say that the initial weirdness has gone away. Every now and then it will do strange things like lag severely but overall it works pretty well. For the money spent I cannot complain.

– Midwire

Ruby Performance : Case vs. If-elsif

In this edition of Ruby Performance I take a look at case vs. if-elsif.

In my testing, links below, it is clear that case statements are consistently more expensive than if-elsif. The difference in a single call is insignificant, but that difference adds up over time to possibly matter.

I am certainly not recommending that you use if-elsif in every instance. There are times when the trade-off may be worth the difference in performance.

Case

Case offers less typing, but implicitly compares using the more expensive === operator. Case may also offer more concise code when determining if a value falls within a range of values or a non-contiguous set of multiple values. Case code also looks prettier in most instances.

If - Elsif - Else

If-elsif-else offers speed of execution and more conspicuous code in some instances. But the fact remains that it is always faster than case.

Here are the timing summaries for strings:

Timings for [case when using strings]
Total: 3.587024

Timings for [if elsif else using strings]
Total: 2.380505

Here are the summaries for integers

Timings for [case when using integers]
Total: 3.495027

Timings for [if elsif else using integers]
Total: 2.570731

I also wanted to see the difference between the === operator with if-elsif and case which implicitly uses ===

Timings for [case when using integers]
Total: 3.495027

Timings for [if elsif else using integers with ===]
Total: 3.561783

So in this case, no pun intended, the case statement is faster slower.

Find the tests here: https://github.com/midwire/ruby-profiles/raw/master/case_vs_if.rb

Regards,

– Midwire