This has been driving me crazy all evening. It turns out when you use Homebrew, the installation directories for OpenSSL and Readline libraries are different. Fortunately, there’s a compilation override as mentioned on the ruby-build Issues page:
RUBY_CONFIGURE_OPTS=”–with-openssl-dir=`brew –prefix openssl` –with-readline-dir=`brew –prefix readline`” rbenv install 2.0.0-p0
You can of course change which Ruby version to install, like 1.9.3-p392.
I have literally been bashing my head into the wall this past week trying to figure out how to get RSpec view tests to pass when using Devise. I finally figured it out after a lot of trial and error because there is a particular combination of things you have to have in place to make things work.
First, the what: I added some navigation to a menu bar that only shows up if the user is logged in. It was just:
<% if user_logged_in? %>
<%= link_to ...blah... %>
<% end %>
The trouble is, I kept getting this error:
undefined method `authenticate' for nil:NilClass
The first problem was figuring out why Devise’s helpers weren’t being loaded. According to the Devise documentation you should create a
spec/support/devise.rb file like:
RSpec.configure do |config|
config.include Devise::TestHelpers, :type => :controller
But what about running view tests? The missing line is:
RSpec.configure do |config|
config.include Devise::TestHelpers, :type => :controller
config.include Devise::TestHelpers, :type => :view
Great! But that only solves the missing helpers. What about getting
current_user to actually return a user? I tried all sorts of things and spent days searching for the answer and it comes down to stubbing out the helpers … but which object? The answer is on the
@user = double('user')
@user.stub(:id => 100)
view.stub(:user_signed_in? => true)
view.stub(:current_user => @user)
That works exactly as I want it. So now I can write my view tests like:
describe 'layouts/application' do
describe 'authentication nav' do
context 'when authenticated' do
it 'should have Log Out' do
rendered.should have_selector('nav a', text: 'Log Out')
It needs to be more mass-market.
That is what I keep telling myself. I have been dawdling on a project I have been coding in my spare time. I threw the base of it together maybe a couple of months ago? Then a few weeks ago I started shopping it around to my friends. I saw the warts and I cringed. I saw the directions this thing could take. I seriously contemplated throwing it all into /dev/null and starting over—even up to last night.
But I just had a moment of clarity. Right now.
Just ship it.
I am laid up in bed sick and here I am on my iPhone typing away on the WordPress app and I realized that my original idea is still valid. So very much so. I still might toss the codebase away a fresh copy based mostly off it, but the core of the idea is solid. I am not going to pivot.
I felt when I came up with this idea that it wasn’t a sexy idea. After demoing it to a small number of people I got lured into the trap that it wasn’t pretty enough. That it wasn’t simple enough. That my mom wouldn’t be able to grok it. That I should pivot—is the word veer these days?
No. I am on my bed and fairly lucid and I want—nay, need—exactly what I have built right now and I know of no replacement. I still know that the direction I was going to change to is a potential future but I think my current physical condition validates my efforts.
At the end of the day I know that am the one that must be the primary use case because I saw something that wasn’t available and I know how to solve this.
I am tired of getting horrible search results when trying to understand how to conceptualize 3D transforms with CSS. So I’m going to write my own help guide:
Check it out!
The popular trick most people apparently do to remove that iPhone address bar in mobile Safari is to scroll the window up by 1 pixel:
My problem with this is it shifts the canvas up thereby losing 1 pixel. It turns out you can specify a fraction of a pixel and the trick works just fine still:
Note: I added a 100ms delay to it because it made it work better. I tried listening to the window “load” event it just wasn’t as reliable.
This post is mostly for me to remember how to do this.
It turns out that getting Devise (or the built-in mailer for that matter) to send email through Amazon Web Services’ (AWS) Simple Email Service (SES) is stupid easy. Most of the work is just getting SES set up properly. After that:
1. Verify some email addresses
- If you just set up SES you are probably still in sandbox mode. You need to add new recipients on the Verified Senders dashboard first.
2. Generate your SES SMTP Credentials
- You must generate a new SMTP User and SMTP Password to connect ActionMailer to AWS SES. These are NOT your AWS login credentials!
- Go to the SMTP Settings dashboard.
- Click the button “Create My SMTP Credentials”.
- Copy the information out—it will not be displayed again!
3. Edit your ActionMailer settings in the production.rb file
That should do it! Send yourself a test message.
Remember: you can only send to verified email addresses while in Sandbox Mode. You must request Production Mode access to send to any unverified email address. Otherwise you will probably see the Rails log error: Net::SMTPFatalError (554 Message rejected: Email address is not verified.)
This is mostly a note to myself on how to do this.
Amazon’s Simple Email Service (SES) seems pretty easy to use but working with the DreamHost DNS management proved slightly tricky because of the large amount of steps and the order of them. Getting the DNS values right was also not completely obvious. Here’s my recipe:
1. Register a Domain
- Log into your DreamHost Panel
- Add a domain (Domains -> Registrations)
2. Change the Domain to DNS-only
- Click the Edit link for your domain (Domains -> Manage Domains -> Edit)
- Scroll all the way down to the DNS Only section
- Choose that
3. Turn on Amazon SES
- Create your Amazon Web Services (AWS) account
- Go to the console page
- Click SES to get to your SES dashboard
- Click Verify New Sender
- Click Verify a New Email Address
- Wait until your new email address shows up in the Email Addresses list (or hit Refresh)
- Click on the new email address to get its Details, you should see Status: pending verification
4. Verify Your Email Address
- You should have gotten an email with the verification link in it: click it
- Go back to the SES dashboard and click on the new email
5. Update DNS custom records on DreamHost
- Return to your DreamHost Panel
- Click Domains -> Manage Domains
- Click the DNS link under your domain
- Scroll down to the “Add a custom DNS record to YOURDOMAIN.com” section
- Add a TXT record with the full value:
- Notice: SES might recommend a text record of _amazonses.YOURDOMAIN.com. Do not paste this full value in! You must remove the “.YOURDOMAIN.com” part. That’s right, just enter: _amazonses
- You might also want to add DKIM to your domain as well.
- Click the “copy record” link to see the full name and value.
- Notice: Again, SES might recommend a CNAME record that looks like abcdefghijklmnop1234567890._domainkey.YOURDOMAIN.com. You need to remove “.YOURDOMAIN.com” for DreamHost.
- It takes a while for the DNS records to propagate. You will also get an email notification that says the sender is verified and the DKIM verification is complete.
I have been working on this thing for the past few weeks. It’s a nifty idea spawned from a need I had recently, and I figured I could package it as a service—you know, SaaS stuff. You input data and the system magically formats it for you. (No, I’m not talking about the idea I tried launching 2 years ago, but something in the same vain…)
Anyways, so over this holiday break I put in some time and crafted a basic working system to demonstrate my concept. Then I put it in front of a few friends who are in my target demographic. What I heard was this:
- Neat idea!
- I love the way it does the magic for you!
- I can see it used for X, Y, and Z purposes!
That’s really encouraging! Yay! Proof of concept … sort of. I also heard this:
- I wish I could import file formats A, B, and C
- I don’t get the formatting syntax
- I wish it also had features D, E, and F
Here I had spent time crafting a syntax I thought was relatively simple. Think of it like Wiki formatting: you type raw text in and then add some special characters and boom you get neatly-formatted data. But because this SaaS is a kind of visualization tool, people want me to be able to import all sorts of spreadsheet formats and other document types. That was exactly what I was trying to avoid.
Do I listen to my users who say they just want to basically have a version of their Office suite replicated in my service? If I go down that route I’m afraid I’ll end up being very feature incomplete. (Which, incidentally, is what happened with that other startup idea I had. There was no way for me to reach feature parity.) I was hoping that by forcing people to edit in a syntax not too distant from Wiki formatting and CSVs I could skip the problem of me having to create a GUI. I’ve learned my lesson about GUIs: never make a pretty GUI because it will always be feature deficient.
And yet, I know it’s not really the syntax that’s bothering my users. Really, it comes down to the same problem I before: users already did the work and they don’t want to do it again. I can totally see that point. They want to copy or import. They want tools to edit. I also know that is a hell of a lot of work.
Being a creator is hard. I’m trying to encourage simplicity in the face of complexity. But I also need to please the people that will carry my dreams forward. The art of all of this is finding the balance between what I think is a “good enough” experience that will get my users to their end goals, at the same time I need to make things easy enough that the amount of work they do is minimized.
I was looking over some code that I thought should have generated an error:
# ... blah blah blah
foobar = some_method_making_a_value
In this case I thought
foobar would have been undefined at the point where
call_other_method() is run, but no! The value
nil was being passed in. I somehow expected instead the error: undefined local variable or method `foobar’. Why didn’t this make an exception? Scoping.
Even though the stuff in the
if block isn’t executed the fact is that
foobar is assigned at least once in that localized scope. Therefore when Ruby runs
call_other_method() it knows it’s a variable (not a method) and can safely return
nil. In the above example, function
proc creates that local variable context within
c() and so
foobar doesn’t know about the
It makes sense when you think about it but I still find it awkward.
I saw a link fly by on Facebook today that really depressed me. Click if you want to read it. Summary: people on Twitter spouting epithets at the President when they would rather watch football.
It is 2012 people. Twitter is known to be a public platform. (Facebook too.) 1) do you not realize you are broadcasting to the world and you are now searchable? 2) do you not realize your words are permanent? You now will forever for the rest of your life be known a person who openly yelled the N-word at the Commander in Chief. Hey we love our civil liberties of free speech. (America, Fuck Yeah!) But free speech has responsibilities. And the Internet has eternal memory.
So do yourself a favor when you post anything on the Internet—including email and chat boards—don’t openly be a dick. Especially to the guy that is running your country.