September 21, 2015 by Daniel P. Clark

Introspection by Design in Ruby

If I have one pet peeve in Ruby it’s knowing state at a certain point in the program’s process.  Sure they make plugins for advanced diagnosis of this.  And when you start out learning to program it’s common practice to use puts everywhere to see what’s going on.  But this causes a lot of back…

Continue Reading »

July 25, 2015 by Daniel P. Clark

Play HD Youtube from the Raspberry Pi Command Line

Quick tip for most Linux distros.  You can just use the mpv player to play a Youtube video from the command line.  It’s a take off on mplayer2, and it has quvi built in.  Unfortunately it’s not available for the Raspberry Pi architecture. Now the Raspberry Pi has some pretty good graphics built in.  But…

Continue Reading »

July 23, 2015 by Daniel P. Clark

Ruby on the Raspberry Pi (free distro image)

I’ve customized my own Raspberry Pi distro (Raspbian) with Ruby 2.2.2 on it.  It’s available for download for you to use.  Here are the details. 4 GB image with 370Mb of free space at a download size of 1.9Gb DOWNLOAD Custom Ruby 2.2.2 on Raspbian Distro (ruby_rpi.img.bz2) User: pi Pass: raspberrypi Checksum: md5sum ruby_rpi.img.bz2 53637c11e3115381ac5867391f527f75…

Continue Reading »

June 21, 2015 by Daniel P. Clark

Ruby Refinements – Not quite ready for production

I recently looked for a method on Array for a boolean response on its uniqueness.  As Ruby currently doesn’t have one I figured it’s easy enough to write one.  Now Ruby’s refinements are fairly new and a nice feature to have around.  So I decided to write a benchmark for different ways to test the…

Continue Reading »

May 28, 2015 by Daniel P. Clark

Rails’ HashWithIndifferentAccess

A Ruby Hash is a very powerful collection type to use in Ruby.  When working in Rails sometimes you’ll have symbols as keys or sometimes they will be strings.  If you use a normal Hash these will store as different keys for the same name. sample = Hash.new sample[:a] = 1 sample[“a”] = 2 sample…

Continue Reading »

May 16, 2015 by Daniel P. Clark

Switching From Unicorn to Puma on Heroku is Easy!

I’ve had my project running on Heroku with Unicorn for some time now.  Not that long ago Heroku put out a notice advising people to switch over to Puma as Unicorn doesn’t do well with low latency connections.  And you know that with the internet you’re always going to have people with slow connections accessing…

Continue Reading »

May 15, 2015 by Daniel P. Clark

Speed Up Your Rails Views By Deferring Changes

Nobody likes a slow website.  And the more notifications and content privileges you calculate beforehand the longer your web requests take to load and send.  The most efficient way to change this is to make as much of your site static as you can and defer your changes to after the page has fully loaded. …

Continue Reading »

May 13, 2015 by Daniel P. Clark

Rails: Don’t “pluck” Unnecessarily

Using pluck in Rails is both quick and efficient.  But there are cases where it’s not what you want to use.  For example if you’re selecting all users who have contacts, you might see something like this. User.where(id: Contact.pluck(:user_id)) Rails’ where method allows for Arrays of items for lookup so the above code might turn…

Continue Reading »

May 12, 2015 by Daniel P. Clark

Fake a SMTP Server with Python for Rails Testing

So I’ve been in the process of writing an integration test to verify the flow of registration through some unique conditions.  One thing I ran into while writing my Rails test was this error. Connection refused – connect(2) for nil port 25 After looking around at documentation on what to do for testing it seemed…

Continue Reading »

May 11, 2015 by Daniel P. Clark

HABTM; You Don’t Need It

My point: “For any valid use of implementing a has_and_belongs_to_many there is an equally valid way to implement it without it.” A few reasons: Rails had changed both the way it worked and removed it from reflections for a brief period (Rails version 4.1.0 and 4.1.1).  Also the preferred implementation is to use has_many :through. …

Continue Reading »

Page 3 of 8
1 2 3 4 5 8
1 2 3 4 5 8