z19r

Sending Email with Laravel, SendGrid, Beanstalkd and Go

Dec/21/2013

Yeah, I know. That's a mouth full, perils of webscale, I guess.

I was recently having a conversation with Taylor Otwell on twitter about consuming Laravel queue messages in other languages, and figured I'd quickly throw together a little proof of concept.

You can see all of the source code here.

There is an almost fresh laravel install, with a single artisan command email:send. The command simply uses Queue:push to put a message in a beanstalkd queue. The app does nothing else, but one could image it's a fully functional app undergoing a refactor.

There is also a small go application here. This worker listens to the beanstalk queue with one goroutine, and sends email with another. The goroutines communicate through a single channel. I've included the complied go binary in case someone wants to play with this without getting a go environment setup.

The source for the go application is relativly small, and should be pretty readable. Feel free to ask questions in the comments if something isn't entirely clear.

If you want to play with this, you'll need a valid sendgrid account and Beanstalkd running and the following env vars set:

  • BEANSTALKD: location of the beanstalk installation (e.g. localhost:11300)
  • SENDGRID_USER: username for sendgrid account
  • SENDGRID_PASS: password for sendgrid account

Update: Extra special thanks to the SendGrid team for provisioning a test account early on a saturday morning.

Tiny PHP

Nov/30/2013

Today, I'd like to annouce my new PHP Micro-Framework, Tiny.

Ha. Just kidding.

When I was building Forrst with Kyle, we knew that we didn't want to expose various primary keys, like post_ids, and user_ids, etc, on the site. The solution was to make URLs that looked like http://forrst.com/posts/Poly_Mantis-GFC.

We used a library from our friend, Jacob, that allowed us to obfuscate primary keys simply by base62 encoding them. I find myself using this library constantly, constantly copying and pasting from Kyle's github account, where the code has been sitting untouched for literally years. I finally made it composer-installable.

You can find it here. I hope you can find it as useful as I do.

edit: Just to clarify, the tiny-ified ID wasn't stored anywhere, it was always calculated. We used methods something like:

class Post {
    public function getUrl() {
      return $this->getSlug() . '-' . $this->getTinyId();
    }
}

edit 2: This could also be used to build something like a URL shortener, as $tiny->to(99999999); would actually output jpWDw

Upgrading to Mavericks breaks lxml

Oct/26/2013

Turns out upgrading to Mavericks breaks a few things, afterall. One error ran into today was #include "libxml/xmlversion.h not found trying to install lxml.

Simple Fix: reinstall XCode Developer Tools with

$ xcode-select --install

You should probably just do that anyway.

what i've been watching

Oct/17/2013

words in word

Oct/16/2013

My son, Jayden (8 years old), had a homework assignment yesterday to find words made up of the letters of another word (e.g. pat in part). So, instead of thinking, we wrote this:

from itertools import permutations
import sys

word = sys.argv[1]

words = open('/usr/share/dict/words').read().split("\n")
valid = set()

for k in range(1, len(word)):
    for combination in permutations(word, k + 1):
        to_check = "".join(combination)
        if to_check in words:
            valid.add(to_check)

print list(valid)

Use like:

$ python words-in-word.py part

He also now has some understanding of strings and lists in python.

close enough