Ruby: Using Directories

Until this past week, my coding hadn’t expanded much past a repl environment. Last Monday, that changed very quickly because I started an immersive web development program at the Flatiron School.

My first week at Flatiron expanded my scope far beyond coding in my beloved environment. I was using tools like Terminal and the text editor Sublime Text to do things like interact with directories. Here’s how to use Terminal, explained a bit in an earlier post, and a text editor such as Sublime to create a directory and then output an array of files from it.

A directory is a collection of files (maybe music files or photos, for example) that can be accessed from a Ruby method. Ruby methods Dir.entries and Dir.foreach use the directory file path to return file names:

Let’s pretend I want to create a directory filled with images I could use as profile photos. Some of the files are jpegs and others are pngs (of fun, customizable emojis that I design on I’m going to build a method that will access my ProfileImages directory and output only files with a .png extension:

  1. In Terminal, I go to the place I want to store my directory: cd /Users/rachel/dev
  2. I Make a new directory, which will contain a directory of my images, as well as a Ruby file: mkdir “EmojiFinder”
  3. I change into the EmojiFinder directory: cd EmojiFinder
  4. I make a ProfileImages directory, where I’ll put my images: mkdir “ProfileImages”
  5. I change into the ProfileImages directory and copy in my photos: cp /Users/rachel/Desktop/emoji_mini.png /Users/rachel/dev/ProfileImages
  6. I change back into my EmojiFinder directory: cd ..
  7. I create a ruby file: touch “EmojiFinder.rb”

This method outputs an array of files from ProfileImages directory. From there, I could iterate through the array, outputting only files that contain the .png extension, but I think I’ll solve this a little differently.

This method iterates through the files in the directory, and will only output files with a .png extension. I called the method using the file path to the ProfileImages directory.

Et voila! Running ruby EmojiFinder.rb in Terminal outputs all image files with a .png extension.

Helpful resources:


An HTML Reintroduction

In college, I took one course in HTML, and sweated my way through the absolute basics (I had never even opened a plain text file before starting the class, and had definitely never heard of a “div.”) This week, I reintroduced myself to HTML, and was surprisingly delighted by how much I remembered, considering my general stress and feelings of inadequacy in that years-ago class.

For newcomers to coding, I’d highly recommend using HTML as a starting point, despite everything I just said about fretting my way through Intro to Web Development.

The trial-and-error of learning is different in HTML (hyper text markup language) and CSS (cascading style sheets) than other languages, because instead of getting a scary error message (like I would when improperly writing a function in Ruby), I’m opening my code in an actual webpage and checking out how it looks. The diagnosis is usually, “that looks like crap,” or “hey, that looks pretty good,” or “that looks alright, but I can probably make it better.” And by the way, no matter how bad everything looks, it’s still a very cool feeling, seeing my work displayed on the regal stage of a Firefox browser window.

Another beginner-friendly aspect, is that you can make quite a bit, knowing very little HTML. Here’s a page I made in about five minutes with some light Googling:

Calming pile of rocks

Here’s the code I typed into an HTML file:

HTML example

Starting with header tags (I used <h1> in the first line of code), paragraph tags (see the <p> in the second line), and–if you want to get fancy, some links or images (I inserted the rocks photo with the code in the third line), you can get pretty far in jazzing up a web page. Codecademy is a great place to pick up enough basics to get started.

I remember at the end of my Intro to Web Development course feeling a little boxed-in by HTML and CSS. While it makes a web page look nice, it can’t really do anything. That’s where other languages come in. Now, after pushing myself to learn languages such as Ruby, it’s oddly comforting returning to HTML.

Going to Meetups

When I first started learning to code, I felt way under-qualified to attend programming-related events. I felt like an outsider to the field, and I figured I wouldn’t have much to say or even understand what other people were talking about.

Plus, networking-type functions are intimidating in general. Honestly, any event that requires mingling with strangers on a work night, when I could be running in the park, or getting drinks, or at least going home to change into yoga pants and make mac n cheese, is tough to get motivated to attend.

In September, I pushed myself to go to two Meetup events hosted by the Flatiron School, one called “Women in Tech” that featured a panel of recent graduates working as developers, and another where teams of students presented their projects.

Both times I had some hesitations. (What if I have to make awkward conversation? What if everyone else knows each other? What if it’s not worth my time? Shouldn’t I be at home learning to code instead of standing around talking about it?)

My fretting mostly went to waste because: 1) Awkwardness wasn’t really a problem. All I had to say was “Hi, I’m Rachel. Are you a student?” and that seemed to get the conversation flowing. 2) I underestimated how helpful it would be hearing from people tackling similar challenges to me. 3) Being a part of the developer community (or some very small corner of the community) makes learning to code, in so many ways, just–well– better.

With my brief experience, I’d say going to these types of events is like anything else: the more you do it, the less intimidating it becomes.




Course Report Podcast


While reseaching the numerous code schools in New York and deciding which ones I’d like to apply to, I have found Course Report articles and reviews very helpful. Yesterday, I discovered that they also launched a monthly podcast with updates about bootcamps, such as new schools opening and articles published about code school outcomes.

Podcasts are my favorite way to consume news (I listen to them while I make beaded jewelry for my Etsy shop,) so I’ve already blown through the May and June episodes, and plan to listen to the latest episode, July 2016, later today.

I like that the podcast gives a bird’s eye view of the ever-changing code bootcamp landscape. Before finding this podcast, I found it difficult to stay on top of bootcamp news while I focus in on my own learning and preparations. These brief (15-20 minute) episodes summarize relevant information effectively.

Beading and podcast-listening


My Strategies for Learning to Code

When I first started learning to code, I didn’t have much of a strategy. I floated between podcasts, Codecademy, and talking to my friends who worked in the industry. It wasn’t a bad approach, but after taking a few months to learn some basics and look into code bootcamps, I started developing a more organized strategy.

Often, I have felt adrift in my learning process–not sure of what is most important and what I might be missing completely. But lately, I’ve been getting glimpses of the big picture: what code bootcamp will be like, and more distantly, what working as a programmer will be like. That’s given me some confidence in my approach and helped me use my time more productively.

Here are the strategies for learning to code and preparing for bootcamp admissions that have worked best for me:

  • Using a variety of learning tools to find the ones that work best for me (and to switch between when I need a change in scenery.) I’ve used W3Schools, Codecademy, Udacity, Codewars, Coderbyte, Codefights, and Flatiron’s free lessons on, as well as podcasts, blogs, and Twitter.
  • Taking notes on anything that may be useful in the future. I created a .txt document so that I can easily add and search for bits of code. I also define terms, summarize concepts, and paste in websites that I may need to refer back to.
  • Being open to both long and short study sessions. Sometimes, I can get wrapped up in involving code challenges for a couple hours without noticing the time pass, but for tasks that I’m dreading, it’s tough to get motivated to push through them. I try to set aside 20-30 minutes to chip away at tricky or otherwise untempting tasks.
  • Identify recurring concepts and mastering them. Recently, I created a 24 problem “quiz” for myself that covered concepts, such as recursion, that I had encountered but not fully mastered. With help from Google, I solved (and then re-solved) the problems until the solutions came easily to me.
  • Trying to finish a study session on a high note; it’s a morale boost that makes it easier to get back to work later. (That said, if I get stuck on a problem that seems unsolvable, I take a break from it. More than once, I have returned to a coding challenge with fresh eyes and quickly noticed an easily fixable mistake.)


In a followup to my post about CodeWars and Coderbyte (two sites that offer coding practice problems), here are my notes on the latest site I’ve been using: CodeFights. CodeFights has several types of challenges, including quizzes, “Tourneys,” and “Head to Head” competitions, but I’ve been using only the the “Code Bots” feature so far.

I like the setup. Each challenge has three parts: one problem fixing broken code, one problem adding to partially written code, and one problem to solve from scratch. At the end, my scores are matched against a “bot” to see who won. It’s nice having a warmup to the hardest problem at the end, and I liked that I’m pushed to stay focused through three problems. The challenges I have finished so far are comfortably within my ability level, and completing each set unlocks a new (presumably harder? If so, the increase in difficulty is marginal) challenge.

I’ve found it user-friendly and glitch-free so far. Occasionally the instructions for problems are a little unclear.

JavaScript Cheat Sheet Updated

After working through several of CoderByte‘s easy challenge problems, I have added quite a bit to my JavaScript Cheat Sheet. Most additions are built-ins which I have become more familiar with using (such as array.reduce(), array.sort(), and Math.floor() /Math.round() /Math.ceil()). I also added the basics of using regular expressions, which I had not encountered until reviewing CoderByte’s provided challenge solutions.

JavaScript Cheat Sheet_Updated

(p.s. these are my personal notes, not any sort of official guide.)