Mary Dickson Diaz

Code, Life, Learning

Tag: ruby (page 1 of 2)

making a baby blanket (smaller)

sleeping baby in a baby blanket

I’m scheduled to return to work this week, which makes it the perfect time to pick up another project (not). Nonetheless, I’ve been wanting to knit something for Aurelio for some time, and Ravelry’s declaration that they won’t steer away from “political knits” inspired me to go check out some patterns.

I found a simple baby blanket with a repeating pattern that adds some lacy details — baby loves this because he can stick his lil fingers in the holes. Here’s the pattern:

CO 107 st
Row 1: knit
Row 2: purl (and all even rows)
Row 3: k3, * k2tog, yo, k2 *
Row 5: knit
Row 7: k1, * k2tog, yo, k2 *, k2
Finish with row 1 or 5.

The elements in * are repeated for the remaining stitches in the row.

Now, I want my blanket to be smaller than the pattern. A mini-blanket. But the thing with knitting is you can’t just pick an arbitrary number to cast on or else you’ll break the pattern and wind up ☠️. So how do I figure out how many stitches to cast on?

Option 1: Overengineer a ruby solution to visualize the pattern, then guess and check at cast-on numbers to figure out which ones work.

What an EXCELLENT idea. Let’s do just that.

I started with some nested functions, like this:

…then realized I was breaking the rule of DRY (Don’t Repeat Yourself). Let’s get a bit more object-oriented, shall we?

that’s better, now I don’t need to pass on the width to all those functions, I can use the object’s instance-accessible @width property.

Coded correctly, the pattern passes with the default cast-on width, and breaks when a width breaks the pattern.


Doesn’t work:

I used the guess and check method to find a variety of cast-on options that don’t break the code, including 107, 99, 87, 75, 63, 51, 55, 7, 11. What do all these numbers have in common?  And how can we identify them without testing via an elaborate visual chart?

There must be a more mathy way to solve this, right?

Option 2: Ask Mary’s Mom

My mom is a skilled seamstress and knitter/crocheter, not to mention a Mensan, so I knew she would know how to reduce a pattern without all that hub-bub above.  I sent her the pattern and asked her what my cast-on options are. She said:

Looks to me like the pattern is just 4 stitches +3 on the edges, so you could cast on 7 or 11 or 15 or 51.

4 and 3… going back to our tested numbers, we find that they are congruent modulo 4, meaning they give the same remainder (3) when divided by that number. Put another way, any multiple of 4 (the pattern), plus 3 (the stitches on either side), will work (4 * 10 + 3 = 43 = works).

Don’t forget to remove the blanket from the crib once baby falls asleep.

If you all have any additional knitting or math questions for my mom I am happy to pass them along.

try rails 5

Hey folks! Last week wrapped up my second teaching assistant commitment, and while I managed to get myself invited back (barely) (I have more to say about this), I’m taking a break to focus on building skills and job seeking.

On the menu for today: let’s talk Rails 5. This’ll be short, since I need to dive into it.

Screen Shot 2016-02-03 at 3.21.29 PM


BUT FIRST… version control.

Since I finished my Ruby on Rails training in 4.something, Rails released a beta version of 5.0, and Ruby has also released a new version, from 2.2 -> 2.3. I’ve fought hard against installing a ruby version manager after disastrous attempts with rvm and rbenv, which hate each other, and will leave your development environment totally FUBAR if you’re not careful. So I nuked everything and avoided any Ruby version control, until now– and now I know better, and there’s no longer any excuse. My instructor says “try chruby!” so chruby it is!

I followed these instructions… including the setup for powder, which is my Rails development server of choice. I installed Ruby 2.3.0 as default and 2.2.4 as a “so then we’ll have it”. Apparently I had been using a version of ruby called 2.2.3p173.  Gross. No more!:

(Oh right, I have to update to El Capital also. Dammit.)


So now we have software version control, sweeeeet. However, that version control does not extend to Rails, so how to play with the new version without destroying my current install (most recent stable version)?

Option 1: Clone the Rails repo and create a new Rails app from that starting point. 

I followed this guide for how to clone the Rails repo and then create a new Rails API app using the latest beta version (“edge”):

Fun! This worked as expected. I did have to run a bundle install before the bundle exec rails new etc would work. If you go this route, at the end your gemfile will contain this line:

gem 'rails', github: "rails/rails"

Option 2: Create a Rails app like normal and then update the gemfile with desired Rails version

Do you really have to clone the entire Rails repo? Probably not, right? In my second attempt, I tried to teach an existing Rails app to use the new version. The latest beta release in has this language for your gemfile:

gem 'rails', '~> 5.0', '>= 5.0.0.beta2'

However, that did not work. This did!

gem 'rails', '5.0.0.beta2'

I had to run a bundle update after bundle install, but otherwise everything went smoothly.


Well, my install worked a bit TOO well, and now all new Rails apps are initiating with 5.0. That was not my intention, but it should be easy enough to switch back if needed. Funny enough, when I run a new Rails app now, this is what the gemfile looks like:

gem 'rails', '>= 5.0.0.beta2', '< 5.1'

YMMV. Gentle reminder: Rails 5 is not currently recommended for production environments.

reindeer games

Screen Shot 2015-12-26 at 10.52.12 PM

Happy December, readers! Christmas has come and gone and you’re probably over it already. I, on the other hand, am determined to keep making progress on the Advent of Code challenge, which has served as a happy distraction and learning opportunity this month. When I haven’t been teaching, applying for jobs, getting prodded by doctors (long story), and trying to land my first contract gig, I’ve been helping Santa and his team deliver the goods.

In the process, I learned about (and/or got more practice using):

  • object-oriented programming (OOP)
  • string manipulation & regular expression matching
  • MD5 hash conversion
  • bitwise logic operators
  • arrays and hashes
  • functional programming
  • algorithmic efficiency (Big O notation)
  • and more!

Over time, I built out my repo to include testing (for easier code refactoring) and input files (for cleaner code), as well as a README detailing my approach to each problem. I know it sounds silly–and did not impress my career counselor–but this was truly a great professional learning exercise, and I’m enjoying the opportunity to see how other people solved the problems and how to optimize my own solutions. In some cases, my approach works, but takes a long time to run. In other solutions, my approach works in theory but takes too long to return a solution. I’m still tinkering and will read up on the problems I didn’t solve before I put it away until next year.

One of my favorite exercises was Day 14, Reindeer Games, in which a set of reindeer are racing, and the objective to to find how far the winning reindeer has travelled after a given number of seconds. Each reindeer travels at a set speed (x kms/second) for y seconds, and then needs to rest for z seconds. To solve this challenge I took an OOP approach and considered “what are the Nouns involved here?”

  • We have Reindeer, each flying on a track, organized by a race. Reindeer have a name, a distance they travel every second, a fly-time and a rest-time.
  • Each reindeer flies on a Track, which belongs to one reindeer. The track knows whether its reindeer is flying or resting at any given point, how long it has been in that state, and what index it’s at on the track (how far it’s gone). The track knows how to advance a reindeer once per second depending on the reindeer’s state.
  • Organizing all this we have a third class, Race, which registers the reindeer as racers and has a “run_race” method that advances each reindeer for a given number of seconds. At the end of the race, it checks each reindeer’s track position to see who has travelled the farthest, and returns a distance.

This is my favorite type of programming to do, as I enjoy thinking through the “who knows about / controls what” in a given problem set. My solution isn’t necessarily the most efficient (though I have no real reason to believe that it’s inefficient, besides having to carve out an array with ~5,000 entries for each reindeer to mark the “track” on which they travel), but it’s straightforward enough that a non-programmer should be able to look at it and basically understand what’s going on.

Well, see for yourself:

Continue reading

build something with socrata’s api — check

weed violations screenshotTop of my to-do list has been to build something using data from the City of Seattle data portal (, powered by Socrata. This one is not particularly useful, but I’ll share with you anyway!

One of the things I like least about homeownership is the need to keep up a yard. Thankfully I’ve never received nastygrams about yard care, but I’ve heard some horror stories. One couple in Texas was in the process of removing a dead tree from their yard — they had just cut it down and into transportable sized pieces, and piled and covered the logs up with a tarp, and THE NEXT DAY they got a note demanding they remove “tree debris” from their yard within three days or pay a penalty.

Anyway, in that frame of mind I giggled through the “weed and vegetation code citations” available via public record. Since Washington legalized marijuana last year, I had an idea in my mind to track code citations like these:

  • Large overgrown blackberries and vegetation encroaching sidewalk
  • Hazardous vegetation encroaching on sidewalk forcing pedestrians into street

…and present them as our city’s most pressing weed violations.

Clever? Maybe. Half-baked? Definitely. My first idea was to tweet out the description of the citation, with a google maps street-view image of the address in question. That might be visually interesting but seemed like a huge invasion of privacy, so I quickly shelved it. I have no interest in actually shaming the property owners.

So instead I started with the easiest path, tweet the generic descriptions, to see where that led me. Here are the “get-started” steps:

  1. Register for a developer key with Socrata
  2. Identify the data set you want at (for me: code violations)
  3. Use developer key to access the API (I used a Ruby gem from Socrata) to fetch that data set
  4. Filter (for code group: “weed and vegetation”) and collect results in an array
  5. Set up a Twitter API client to talk to twitter, via a new twitter account if needed (I recycled an existing bot!)

Continue reading

wait, wait, don’t tell me…

Background: I was sent a coding challenge via Codility, and before diving into the (timed) test, I spent some time working on the demo. I won’t be sharing the actual code challenge, but the demo is fair game to discuss, it’s featured in a public blog post. It took me a few tries, but in a nutshell, I went from 17 points out of 100 (incorrect answer) to 64 points (mostly correct answers, complexity too high), to … well, I’m going to make you read all the way through to find out.

Continue reading

reviewing the rails tutorials

so you want to build pizza dot net? try rails!

so you want to build pizza dot net? try Rails!

Hey everyone!  This is my last week as a ‘person of leisure’ before class starts up in full force next Monday.  I received a coursework invitation, and the first assignment is to answer the question: “How was your Rails tutorial?” to which I respond, “…which one?

Before I even saw the question I was considering a run-down on the Rails online tutorials I tried, what I learned, recommended order, and which ones are worth salt. So, here goes! These are roughly ranked in “do this first” order unless otherwise stated.

Michael Hartl – Rails Tutorial

oops my cow is upside down

oops my cow is upside down

Continue reading

diving into the oh heck

This is a process post. Or, how I think through possible courses of action when I hit a roadblock.

Screen Shot 2015-08-16 at 8.41.12 PM

I’ve been making my way through Ruby the Hard Way bit by bit and I had a lot of fun this weekend with exercise 45, “you make a game.” This book and the Python version are both great learning tools for the language, and now that I’m getting to the end I see it’s a great tool for learning the basics of web deployment as well. *More than once* I have gone off on a side tangent and scoured the internet for a solution to my problem, only to be redirected back to the book and find that it addresses my question several exercises later.

I like my game, a simple text adventure based on Adrienne Rich’s poem ‘Diving into the Wreck,’ so much that I want to share it on the web with you, and that kicked off the latest rabbit hole. I still haven’t found a solution to this, so if any of you out there know enough to help me out, I would greatly appreciate it!

Here’s where I’m at:

Continue reading

building the #notbot

It started with Peter and the Wolf.


I’ve been wanting to play with Markoved text for some time, using books available in the public domain, easily accessible via Gutenberg. The idea in my head was to create a Twitter bot that would mash Peter Pan together with Call of the Wild (although later I realized that Beowulf would be the better option) and tweet lines from the merged books. As I dug into this project, I realized that the mash-up text wasn’t really interesting enough to hold its own as a bot, but I did like combining different texts to see the results. After while I realized that the *more interesting* challenge would be to build an app where any two (or more) Gutenberg texts can be combined. Behold, the #notbot! Screen Shot 2015-08-15 at 7.55.06 PM

(And yes, I got my Peter and the Wolf in there.) Go play, and then come back and I will show you how I built it:

Continue reading

riding rails (for fun and profit)

At the end of my interview, the instructor asked, “Soooo… what are you doing in September?”

And just like that, I snagged a spot in Code Fellows coveted Ruby on Rails development accelerator, an 8 week full-time bootcamp designed to jump-start a career in web development. Hi-fives for everyone!

I was nervous but well-prepared going into the interview. Keeping this website and writing about what I’m learning has been a good way to internalize it and work out “talking points.” I was glad that I took some time to clean up my portfolio site ( since that was one of the first questions asked, “do you have a projects site we can look at?” Why YES indeed I do!

I have a month to prepare, so I updated The Plan with what I’m working on before class starts. In a nutshell:

  • get some more perspectives on Ruby on Rails, and learn as much as I can about Rails apps
  • review JavaScript (two weeks of the DA will focus on this) and practice it via some hands-on projects
  • bone up on algorithms and core programing concepts

I’m also going to try to take care of some of those pesky “life” tasks. I finally renewed the car registration (they give you two years in Washington before you have to get an emissions test), and I need to set up my new health insurance and convert to life as a married person.

At times throughout this process I’ve felt a bit aimless, so it’s good to be entering into a period of intense, highly structured time focused on becoming career-ready. And, much as I’m currently feeling “let’s get this show ON THE ROAD” it all happened exactly when it needed to, and not before.

Thanks for coming along for the ride. More adventures to come!

now for a moment of zen

Current status: refreshing my inbox every 15 minutes waiting to see when my interview is scheduled.

Currently working on: ruby koans. It is also test-driven development, but at least they’re sneaky about it!

Screen Shot 2015-07-20 at 10.17.16 AM

That “X” has a long way to go… maybe I will go take a nap instead.

Oh! And this! How stacked modules accelerate learning. This definitely resonates for me. (Great charts.) Why jumping back into Javascript was so jarring, because I haven’t used it with anything else I’ve been learning in months.

Older posts

© 2017 Mary Dickson Diaz

Theme by Anders NorenUp ↑