How to Test Your Facebook App Locally Using HTTPS

Facebook now requires you to use https for your Valid OAuth Redirect URIs for apps.  This is true even when your app is in development mode.

In order to get an https address, you could use a gem like tunnels or tunnelss, but I found using ngrok easier.

To get it to work:

  1. I went to their website and downloaded their program
  2. I extracted the file for the program
  3. In my console, I went into the directory where ngrok was extracted to and entered ‘grok http 3000’ on my Windows machine, other machines may use ‘./grok http 3000’
  4. After entering that, ngrok will provide you an https address which you put into the Valid OAuth Redirect URIs field in Facebook
  5. Once you fire up your server, you should be able to access it using that https address instead of localhost:3000
Advertisements

A Free and Easy Way to Create Responsive Emails

I’ve found a quick and easy way to create responsive emails using Bee Free.  Bee Free offers some templates (or you can build from scratch) that you can use along with their drag and drop editor to create responsive emails.

In their tool you can:

  • use a drag and drop interface
  • export everything to HTML (free)
  • preview in desktop and mobile views
  • send an email to yourself to preview it

I’d highly recommend it if you want to add style to your emails without buying templates.

Abbreviating Numbers in Rails

I needed to abbreviate numbers in Rails so that they were shorter and easier to read.  Rails has a great built in method, number_to_human.  However, I didn’t like how number_to_human displays without any customization.

My main issue was that instead of spelling out the entire number, I just wanted to put a letter abbreviation.  In addition, I didn’t want a space between the number and its text description.

For example, “out of the box”, if you do:

number_to_human(1234)

You will get:

“1.23 Thousand”

Instead, I wanted 1.23K.

Luckily, I found this StackOverflow answer by jdoe.

To format it like this, you just need to add these values to config/locales/en.yml (or whatever you’re using as your 18n locale):

(under "en:")
  number:
    human:
      decimal_units:
        format: "%n%u"
        units:
          unit: ""
          thousand: K
          million: M
          billion: B
          trillion: T
          quadrillion: Q

Make YouTube Videos Responsive

It’s kind of hard for me to believe given Google’s emphasis on making sites responsive, that they haven’t supplied people with an easier way of embedding YouTube videos on responsive sites. Fail.

Nonetheless, there’s workarounds to make the videos responsive by editing your CSS.

OS Training has a simple solution.  They create a wrapper in CSS that makes the embedded video responsive.  All you need to to is add the div class and copy and paste the CSS.

Automatically Handle N+1 Queries

I found a gem that’s helping me a bunch, so I just wanted to give it a quick mention.  After asking people for help on a N+1 query that I couldn’t figure out, one of the people recommended checking out the Goldiloader gem.

I was so impressed that the gem solved my N+1 query so easily, I decided to use it across my site.

It’s ridiculously simple to use once you have model associations defined.

All you need to do is to add the gem to your gemfile and it does the eager loading for you!  If there are places you want to avoid eager loading, you can disable Goldiloader for a query.

Improving ActiveAdmin Performance

ActiveAdmin is my favorite gem for creating admin features in Rails.  It makes it so easy to create views to monitor and manage apps.  Much of the heavy lifting is done for you by them gem.

I found that I need to do some tuning on my ActiveAdmin views to get the functionality I wanted without placing too heavy a burden on my server.

I mainly did this by doing two simple things:

(1) Specify Filters – if you don’t specify your filters, you may get far too many (and consuming too many resources when you don’t need to).  Specifying filters are easy, just go into you admin files for the resource (i.e. app > admin > article.rb), then add a line for each filter you want

filter :title
filter :created_at

(2)  Specify Index (and other) Columns – similar to above, if you don’t specify values, you may be receiving too much data.  Be more efficient by only showing what you need to see in a view.

You can do this in your admin file for a resource, simply by adding this:

index do
column :title
column :description
column :created_at
column :updated_at
end