Here is the slides for a presentation on Elixir and Phoenix I gave at my local ruby meetup.
During a recent ruby meetup we touched on some finer points of ruby’s global substitution method. That’s right gsub, likely you have used it in your every day ruby code and never knew all the things it could do. The most common usage of gsub is for simple pattern match and replace.
However this is just the tip of the iceberg of what you can do with gsub. So lets explore that a bit and see what all we can do with gsub.
Another way to use gsub is with a ruby block.
1 2 3 4
The block allows you the chance to do more complex computation of each match as it’s passed into the block, allowing you greater control than the first option.
But there is a more interesting option for gsub that I only recently became aware of. gsub can also take a hash of key value matches.
This can be used to handle multiple matches in the same way each time. While this is the most specialized use case for gsub it can be handy to pull it out when the right time arises. Such as a 1337 Sp34k traslator.
1 2 3 4 5 6 7 8 9 10
Granted this is not the best translator, since we are not handling the edge cases of transforming words to their leet speak equivalent, for instance “hacker” should be translated to “h4x0r” in such a case. In the above example we had to pass through haxor instead of just hacker. However we could easily use gsub again to translate know words into their alternate form, so “elite” would become “leet” and “hacker” would become “haxor” then run those through the original gsub.
1 2 3 4
Notice the bang “!” on the end of gsub in the first gsub call. When calling gsub with and exclamation mark or “bang” gsub will then modify the original string it was called on.
Using the above method we can now catch known words that need to be changed to an alternative and unknown words that contain the key letters would still be handled on a basic level. This is essentially how many translation programs handle translation, they take a matrix of words that map to other words or series of words and then proceed to find and replace them. Although this doesn’t yield the best results, and completely ignores grammar and other considerations for true translation.
Happy hacking with gsub.
In order to get started with phoenix you will need to install elixir. Fortunately installing elixir is pretty painless. The elixir installation page has some really great documentation on how to install for many different environments. My preferred method is with homebrew, if you aren’t already using it you should be.
With homebrew the install is just running the following command.
Now that we have elixir installed we need to install a package management utility called hex. This is required for dependency management in phoenix.
To install Hex run this command.
Now lets actually install the phoenix package.
Awesome! Phoenix is installed!
Let’s create a new phoenix project.
This command will create a new phoenix application in the folder called phoenix app. So lets move into that directory.
Now that we are in our Phoenix app’s directory. We need to run a few commands to launch the most basic phoenix page.
We need to ensure all of our dependencies have been downloaded and are available to us.
this command is equivalent to “bundle install” for ruby applications. If you are not familiar with ruby then just think of this command as a way to ensure all the required parts of your app are there. During the course of building a phoenix application you will use this command many times to download and include libraries which will ease your building process.
Once we have all of our dependencies downloaded and in our app we need to ensure we have a database to connect to. Now this is not required for some apps, but it is usually required on most applications of some substance.
Before we can configure the database we need to ensure we have the correct credentials to access the database installation and interact with it. In phoenix these credentials are stored in the respective environment files for development this is config/dev.exs for production the file would be config/prod.exs
1 2 3 4 5 6 7
Change the user name and password to your local database’s username and password
Now we can create the database.
Once you have the database we can start the server.
Now you can load http://localhost:4000 in your browser and you should see the phoenix welcome page.
If you don’t want to use Turbolinks with your Rails 4 app.
remove the following line
After you remove that line run a bundle install to update your gem file and dependencies.
remove the following line.
Inside you application layout, app/views/layouts/application.html.erb.
Find the following two lines.
My trip started off like any other cross country trip I’ve taken: I packed my bags and headed for the airport. I was super excited for the upcoming conference and my very first RailsConf. I’ve been to many software engineering conferences, but none with a ruby and rails focus. The ruby community is by far one of the most welcoming I’ve experienced, and I was confident I would meet tons of great people and make friends.
After a two-hour delay in Houston, TX, I finally landed in Atlanta, GA and jet to my hotel room in the Ellis hotel. I dropped off my bags and made my way down the block to the Westin Hotel where the guide scholar meet-and-greet was being held.
Walking down the street, I recognized a face in the crowd and racked my brain to think of where I knew her from. Then it hit me! It was Coralline Eda Ehmke, from the Ruby Rogues podcast walking down the street toward my hotel. As the name popped into my head, she had already passed me, and I wheeled around to shout “Coraline!” She had this look on her face that said “Who are you and how do you know me?” I told her I’m a big fan of the Ruby Rogues and love her as a regular panelist. We chatted for a couple short minutes, and then I continued on my way to the scholar/guide gathering.
I finally made it to the last thirty-minutes of the two-hour gathering. I meet my Scholar, Michelle Bonat, and we started getting to know each other. We talk about our day jobs and what interests us, what talks we’re looking forward to, what we want to gain from the next three days at RailsConf. We were excited to meet people and network, and the talks were a bonus, an icing on the cake to the greater value of the community.
After DHH’s awesome keynote, we had a 15-minute break before the first talk began. I talked with my scholar and helped her to pick talks that she would find both interesting and useful, since this was her first conference.
As the conference kicked off, I was well aware of the hallway track. It was as entertaining and interesting as any of the talks. The “hallway track” is the conversation people have in the hallways in between talks. Normally at most conferences, these are just conference goers having discussions about the talks they just saw. However, I realized at RailsConf this was where you could also meet and chat with some of the most influential rails celebrities. On the first day, I saw that someone had managed to pull DHH to the side and start a conversation. Soon, ten of us were asking him questions. It shows how powerful a conference can be in bringing people together and involving any member of the community with even the most iconic.
During lunch on the first day, we had a CodeNewbie get together. This was by far one of my favorite parts of the conference. The CodeNewbie community is awesome and so friendly. I brought my scholar with me to the CodeNewbie lunch and her first experience was an awesome one. While short and sweet, this was an amazing chance to meet and get to know some of my fellow CodeNewbies.
The second day kicked off with Aaron Paterson (A.K.A. TenderLove) giving the keynote, and the trolling commenced. He trolled Kent Beck and DHH within the first 10 minute. In fact, one of the main themes of the keynote was trolling Kent Beck. As much as I love watching Tenderlove troll people, the keynote did have some really great points on performance and the work he’s been doing with bundler to make it more performant.
We proceeded to the expo area where many of the most well known ruby on rails tools and integration vendors were present and passing out swag. Needless to say, this was pure anarchy. The expo area was an awesome chance to interact and talk with some of the developers and support teams for products like Heroku, Mandrill, RubyMine, Skylight, and many more.
After the pure bedlam of the expo area, we continued to our talks for the second day. The talks were all choice quality, but one in particular stuck out in my mind as possibly the best conference talk I have ever seen. Adam Cuppy of ZEAL gave a talk called “What If Shakespeare Wrote Ruby?” I am not sure this talk fits into the category of talk, as much as it does “performance and spectacle”. This talk was not only entertaining, but had a great message for software engineers everywhere. If you ever have a chance to see Adam Cuppy speak, I wouldn’t miss it.
The second day was closed out with happy hour and lightning talks. Happy hour was definitely happy. Everyone grabbed appetizers and hung out. The appetizers were quickly demolished, and the din of the crowd was deafening. It was amazing to see so many people sharing their love for Ruby and Rails. The lightning talks were hit or miss, but some were fantastic. CodeNewbies had a wonderful lightning talk given about the community and how awesome it is. Then the after parties started. HIRED was celebrating the opening of their Atlanta office and rented out a bar at the top of the Hilton. Engine Yard rented out JoyStick Game bar, an arcade with booze, and yes it was as epic as that sounds.
That meant that when the third and final day of the conference started, a good majority of the crowd was hungover The Ruby Hero Awards were presented: Nobuyoshi Nakada, Eileen Uchitelle, Sarah Mei, Zachary Scott, Jeremy Evans, Sam Saffron. Thank you for all your contributions to the Ruby community.
We moved on to a panel with members of the Rails core team. These are people who work on the core and are responsible for maintaining and building new features in ruby on rails.
After the panel, we made our way to the last remaining talks for the conference, and wrapped up the day with a wonderful talk from the awesome Kent Beck. He gave a keynote on how he feels at work and how he strives to be at ease in his job. As a young software engineer, he was taught to do a good enough job that any flaws would be someone else’s fault. This passing of the blame, as well as many other common practices, caused him to be very uneasy at work, so Kent developed some rules for how he creates a sense of ease for himself, and alleviates work-related worries.
And then, the conference was over. We said our goodbyes and many of us ran to catch a flight home. RailsConf was an onslaught of learning, meeting people, and making friends, I loved every minute of it, and left the conference thoroughly exhausted. I headed for home, my life enriched just a little more by the experience.
If you happen to make it to RailsConf next year, don’t be a stranger – come and say hi :)