Thursday, October 5, 2017

Use Your iPad as a Second Monitor

Sometimes carrying around a laptop and an iPad seems like overkill. Yet, sometimes, it's purely fantastic. That's right, with a nifty app called Duet Display, one can turn an iPad in to a second display! 


There are a couple different apps that let you turn your iPad into a secondary display, each with their pros and cos. The two other main contenders are AirDisplay 3 and iDisplay which were reviewed along with Duet by LifeHacker. Long story short, Duet works well and I'm a happy camper who can now have dual displays even at a coffee shop. If you have an iPad, go ahead and get this app and enjoy the extra screen real estate! 

Oh, and if you are wondering about the wonderfully colorful iPad stand, you need not go further than these Lil' Engineer Construction Blocks. They may be rated for 3-5 year olds, but who says Dad can't have any fun? 




Thursday, August 17, 2017

Programmatically Logging in to a site with the Auth0 Lock Widget

I had the joy of having to figure out how to programmatically log in to a website that uses the Auth0 Lock Widget for authentication. Since Auth0 provides authentication as s service, the login flow is slightly more complex than a simple POST to the site's login endpoint. Fortunately for you, I've spent the time figuring it out ;)

In a nutshell, there are 4 calls that have to be made for a successful login
  1. GET to the site you are trying to log in to (to get a state variable)
  2. POST to Auth0 with the username and password
  3. POST to the callback handler on Auth0 with the results from the previous POST
  4. GET to the redirect page that the previous POST indicates to redirect to
The following Ruby script does exactly what you'd expect it to do making use of the RestClient and Nokogiri gems. Note, you could make this script work without these two gems, but they do make life quite a bit easier.


Let's hope that Auth0 doesn't change it's login specs anytime soon!

Thursday, January 26, 2017

Nested send and hash/array access for Ruby Objects

I had to do some work where I needed to be able to perform nested calls to an object mixing both send 'sending' and accessing data from a hash/array in a single call. In this gist I've put together a method that can be added to the base Ruby Object that lets you perform complex nested calls. For example
value = obj.send_nested("data.foo['bar'].id")
and under the hood this will do something akin to
obj.send(data).send(foo)['bar'].send(id)
This also works with symbols in the attribute string
value = obj.send_nested('data.foo[:bar][0].id')
which will do something akin to
obj.send(data).send(foo)[:bar][0].send(id)
In the event that you want to use indifferent access you can add that as a parameter as well. E.g.
value = obj.send_nested('data.foo[:bar][0].id', with_indifferent_access: true)
Since it's a bit more involved, here is the link to the gist that you can use to add that method to the base Ruby Object. The gist also includes the relevant tests for your peace of mind.