Less Wrong Than Yesterday

Taking advantage of Phoenix rendering and iodata (part 1)

DRAFT: Expect updates as people who know more than I do correct me.

Among the wonderful things about Phoenix is that it doesn't render strings. Instead, it renders iodata. That's an Elixir idiom that speeds up string processing by avoiding concatenation. But it also makes it easier to work with conditional logic in views and templates. This two-post series is about how I'm doing that in a new Phoenix app (as a new Phoenix/Elixir programmer).

First, some basics

Consider a function helper in a View module, called like this from a template:

What sort of things can helper return?

Continue Reading...

Adjusting Phoenix+Elm tutorials, given Elm 0.17

There are a number of tutorials on how to add Elm to Phoenix apps. Many were for Elm 0.16. They're broken for Elm 0.17. This repo will help you translate from then to now.

Here are pointers to the files that matter. In all cases, look for "elm":

My (trivial) use of Elm is in the root page.

You might also be interested in the brunch-config and .gitignore files.

Continue Reading...

Adding bootstrap.js to default Phoenix installation

This note applies to Phoenix 1.2.0

mix phoenix.new starts you out with Twitter's bootstrap. However, it only includes the CSS, not the JavaScript. I had a good deal of trouble figuring out how to get that working, not being familiar with the JavaScript ecosystem or the brunch build tool that Phoenix uses.

Thanks to the kind help of OvermindDL1, I got it working. Here are the changes, shown in the github diffs.

Continue Reading...

My introduction to metrics

I started my first post-college job in 1981, working at a startup spun off from the University of Illinois. My first job as a Unix and C programmer was to write a program to count lines of code and comment in C programs.

My first release drew complaints. Some people used K&R-style placement of blocks, as in:

if (a = 5) {  

But some used the Proper Style:

if (a = 5)  

The former complained that the latter got "credit" for three lines of code, while they only got credit for two.

I had to add an option (-} as I

Continue Reading...

An example of many-to-many associations in Ecto and Phoenix

Warning: I am a novice at Elixir, Phoenix, and Ecto. I'll update this post as I am corrected. Note also that this applies to Phoenix 1.2.0 and Ecto 2.0.2.

Updated: July 11. There is no need for a join table model. See also this post from OvermindDL1.

Phoenix and Ecto have recently (I gather) gotten explicit support for many-to-many associations (via join tables). I found that making them work was uncharacteristically hard, hence this blog post.

Note: my job was probably made harder because I didn't want to make the join table a first class model

Continue Reading...