I’ve been teaching a part time Back End Web Development course at General Assembly which focuses on building web applications using Ruby and Rails. I very purposely say “Ruby and Rails” instead of “Ruby on Rails” because understanding the Ruby language will allow you to understand any Ruby web framework. One of the biggest challenges in teaching the course is explaining all of the “magic” that Rails uses to do its job. Having written a custom MVC framework on top of Sinatra many times before I understand the broad strokes of that magic but to really understand Rails and even the more basic Sinatra I think you need to go deeper and start with Rack and a basic knowledge of Ruby fundamentals. That’s why I’ve been building a Ruby web framework on top of Rack for the last few days. If you want to understand Rails then let’s check out Rack and build a basic web framework.
Running your own CDN has become incredibly cheap and easy these days thanks to Amazon’s Web Services (AWS). I’ve been using an Amazon Cloudfront CDN distribution to host assets for several websites for a couple of years now. They’re super easy to set up and they cost pennies a month for the average site. The only problem was that, until recently, if you wanted your CDN to serve assets over HTTPS then you either had to pay thousands a month for Amazon to give you a dedicated IP address or you were forced to use the default Cloudfront domain which was long, ugly, and looked something like
https://dsy12448xkv.cloudfront.net/. No one wants that. But now there’s a cheaper option! Amazon allows you to upload your own SSL certificate to use with your custom Cloudfront domain for no extra cost. The process was a bit confusing the first time I set it up so I’m documenting it here for anyone who needs a reference.
Starting a company is the cool thing to do these days it seems. If you watch TV for any length of time you’ll inevitably see that VistaPrint commercial that glorifies new businesses and makes it seem as though its everyone’s dream to start one. Then there are the GoDaddy commercials that, if you didn’t know any better, would have you believe that having a business means you get a website and then customers charge in to shove money down your throat. Its also cool to not start a business. No, businesses are lame. What’s cool is starting a “startup” which to me has become a synonym for “an unrealistic business idea that involves a website and the word ‘viral’ that can only be profitable through investment and/or a buyout”. I have to roll my eyes any time I hear someone say they started or work for a startup. Everyone wants to start a startup or a business and have these dreams of what its like. I’m here to crush your dreams and tell you its nothing like what you imagine.
In one of my recent projects I needed to run background jobs from an Express application. I looked at RabbitMQ, Resque, and custom Redis setups but they all sort of fell short of what I needed. My first attempt was to use the Redis
BRPOP command since the command blocks and waits for there to be items in a list before it returns. The Express app would add a new item to a list then a custom daemon I wrote in Go would use
BRPOP to grab the latest item and do some processing before storing it in our database. But our Go daemon could only talk to the Express app by putting stuff in a database and we didn’t want the Express app to have some special endpoint just for this daemon and tie up the event loop for our customers. After some research I came across the Agenda module which allows you to set up recurring or on-demand background jobs in an Express application. Here’s how we set it up.
Here’s a weird error for you. You have Nginx running, you change the configuration, run
sudo nginx -t and it tells you everything is fine. You try to restart the server and it fails. What’s going on? Here’s how to fix it.
A lot of times we don’t have the luxury of being able to hire a full time server admin or ops person. That’s alright though! It isn’t hard. As a developer, if you’re comfortable on the command line you can competently manage a server of your own. The two places I always look first when setting up a new server are the Linode quickstart docs and this article. The rest you’ll learn on the job. This is just a link post but if I had to give someone one piece of advice about managing servers it would be this: focus 90% of your energy on security, triple check your iptables, and, if you’re managing servers for a company, hire someone who specializes in it ASAP.
Imagine you’re working with a new framework or library for your next project. You discovered the perfect tool. The README is perfect – not too much detail, not too little either. You’ve breezed through the installation and setup process, committed to using this new package, and suddenly you encounter a problem the README doesn’t cover. No problem, you’ll just head over to the official docs. What you find there makes you want to murder the original author. It’s auto-generated documentation. Friends don’t let friends generate docs.
Rails has a really helpful (but not well documented) token authentication mechanism you can use for authenticating your API users. But Rails is overkill for many APIs and so I usually turn to Sinatra. Sinatra doesn’t have much selection when it comes to API authentication. At least not the secure methods I’m interested in. So for my company’s new insurance quoting and licensing API I rolled my own. Here’s how to implement secure token authentication in a Sinatra app.
Ever used a Node.js module that was instantiated like so:
something = new Something(). We’re used to it with built in types like
Date() but how are the developers of Node modules doing this and why would you want to?