Page 2 of 2

Previous page

Working with Templates in Ruby ERB

Templates in ERB

This post is a bit of a thought experiment. Looking into this led me down the route of some interesting ruby solutions.

The problem

Ruby ships with the erb library, but it natively doesn’t come with a way to wrap one ERB file in another. This makes composing files difficult. There’s no way to use something like rails’ yield method.

Some Basic ERB

Here’s how we’d render a simple erb template.

1
2
3
require 'erb'
template = "1 and 1 is <%= 1 + 1 %>"
ERB.new(template).result
Read more…

Elixir - Tuples vs Lists

Immutability Primer

Elixir is a Functional programming language with immutable types. You might see code like the following and think that we’re mutating a value.

1
2
3
names = ["Steven", "Kelly", "Michael"]
names = ["Telly"] ++ names
names # => ["Telly", "Steven", "Kelly", "Michael"]

Elixir is giving us a new copy of the array. How it got this might be a bit confusing though. For starters, this is how Elixir stored that original names list.

1
names = ["Steven" | ["Kelly" | ["Michael"]]]
Read more…

Let me find out

Finders keepers

The find method is one of the first methods I suggest people use when they’re suffering from eachitis.

EACHITIS: A condition where all solutions involving collections are solved using the each method.

One problem with find is how to interpret the funky method signature.

1
find(ifnone = nil) { |obj| block }  obj or nil

From this signature, you might think you could just give an argument to find and it will be returned if no value is found. But that’s when disaster strikes...

Read more…

Next generation is better. I promise

Yey!….?

In addition to my regular hostility towards programming, I occasionally get really excited about stuff. When I heard that Chrome 39 had native support for Generators, I got really excited… until I realized I didn’t really know what that meant.

Everything but the kitchen sync

ES6 Features are sneaking into browsers already. A lot of features are around dealing with asynchronous code. Generators are really cool in that they let you pause a functions execution until all yield statements...

Read more…

Using Ruby to learn JavaScript

I’ve written about why I believe learning to program is hard. If you’ve made it to the other side, rejoice! It’s time for the easy part. Learning a new language. Let’s see how knowing Ruby can help us learn a little JavaScript. (I’m assuming you know Ruby for the duration of this post)

Ruby to JavaScript

First, let’s find some similarities. Both are:

  • Dynamically Typed
  • Both are Object Oriented
  • Functions are first class citizens

Let’s look at these first

Dynamically Typed

1
2
my_account 
Read more…

On why learning to program is hard

The first mention of ‘Objects’ with regard to some non-tangible thing was in the late 1950s. Before that, ‘Objects’ didn’t exist. Once you realize that all concepts in programming are made up, you start to feel less bad about not understanding them right away.

Learn all the things!

To be clear, when I say “Learn to program” I don’t mean following a tutorial. Quite the opposite. Learning to program means you are able to create experiences through a combination of your own internal understanding...

Read more…

Closures

I’ve been trying to gain an appreciation for JavaScript recently. Behind its semicolon ridden lines, and funky funky functions, I’ve found it has a bunch of cool stuff going on. I owe my appreciation for it to Speaking JavaScript by Dr. Axel Rauschmayer. Great book. Go get it.

JavaScript and Me

Up until recently, my JavaScript know-how didn’t extend far beyond using jQuery to select some element, and...

Read more…

Custom params in route resources

Anyone who knows me will tell you I’m a huge rails fanboy. There are times when you get stuck. A name can’t be changed because it’s something the framework decided on. I ran into this recently when working with nested routes.

The problem

Working at The Flatiron School has been awesome. I’ve gotten to work on some great projects. While working on a Progress Dashboard I came across this code for creating nested routes. WALL OF CODE COMING.

In my routes file

1
2
3
4
resources :dashboards, only...
Read more…

Keyboard Navigation

Get over here!

One of the unsung heroes of development is knowing how to use your keyboard. I don’t just mean typing. That skill, while important, is still second to being able to move around. What do I mean by this?

Let’s say I’m typing this obscenely long line of bash:

1
cat ~/schol/GA/BEWD_Curriculum/01_Dev_Workflow/README.md| grep -i git

Oh NO! I’ve misspelled school. Here we go: backspace backspace backspace… 59 backspaces! Even if you didn’t erase it and just used left, it’s still going...

Read more…