All Posts

On Teaching and Patience

I’ve just finished teaching two back-to-back web development summer camps for high school students at the Flatiron School, and was recently hired as a full-time instructor for the upcoming Flatiron after-school coding program. I’m incredibly excited to be back in the classroom, working with great students, a strong team, and interesting content. As such, I’m going to pivot here for a while and post insights, best practices, and thoughts on teaching kids to code.

Today I’d like to talk about teaching – and practicing – patience. It’s one of those intangible soft-skills that you’re automatically supposed to have as a teacher. We preach the virtues of patience in class on a daily basis. We are supposed to be able to sit with a student who ‘isn’t getting it’ for as long as it takes, until a concept clicks and suddenly everything is clear. Teachers are the epitome of patience, right?

written in Read on →

Using the ‘Apply’ Function in Javascript

My foray into javascript has not been easy – It’s meant working hard to get out of the mindset of Ruby and forcing myself into the discomfort of a relatively new language. Sort of like switching to French if you speak Spanish – there are many similarities, but relying on your knowledge of one language can actually be a debilitating crutch if you aren’t carefully about what knowledge you transfer over.

I’ve been stuggling with understanding the .apply method in javascript. There isn’t any really analogous function that I’ve found in Ruby (there probably is, but I just don’t know it yet…).

One way .apply is used is to apply the elements in an array as arguments in a function. For example:

1
2
3
4
5
Math.max(1,2,3,4) //=> 4

//but

Math.max([1,2,3,4]) //=> NaN

Instead of looping through each of the numbers in the array using for we can use the apply method to take the elements of the array and populate them into the function’s arguments:

1
Math.max.apply(null, [1,2,3,4]) //=> 4

Javascript is clicking. Slowly.

written in in apply, functions, javascript

How to Split an Array Based on a Fixed Length (Hint: You Don’t Use .split)

Say you have a string that you need to split up based on a fixed length of characters (in this case, every five: "jamesjonesspiesrabidbirds". Unfortunately, the split method doesn’t help us here.

Instead, we can use .scan. This method looks for regex matches and adds them to an array, rather than taking a string and breaking it up based on a delimiter. It’s a useful method in those cases where .split just can’t handle the job.

1
"jamesjonesspiesrabidbirds".scan(/.{5}/) #=> ["james", "jones", "spies", "rabid", "birds"]

The regex /.{5}/ stands for “exactly 5 of any character” – the . means ‘any character’, and the curly braces with one number means “exactly this amount”. The scan method adds every five characters of the string to the array it returns, to give us [“james”, “jones”, “spies”, “rabid”, “birds”].

written in in arrays, fixed length, ruby, scan, split

Monday Learnings

I learned some cool things today, which I’d like to share here.

1) The each_cons method. It’s great. While working on Project Euler #11 with a friend, he showed me this method. It is applied to an array and takes an argument for n elements – it then returns an enumerator with the different variations of 3 consecutive elements from the array. I’m not sure I’m doing it justice, so here is an example:

1
2
array = [1,2,3,4,5,6,7,8]
array.each_cons(3).to_a 3 # => [[1, 2, 3], [2, 3, 4], [3, 4, 5], [4, 5, 6], [5, 6, 7], [6, 7, 8]]

This was very helpful in finding the products of each possible set of four consecutive elements (horizontally) in the problem’s grid. Nice.

written in in ampersand, methods, pry, ruby, shortcuts Read on →

Optimus Prime Optimizes Prime

Optimus Prime

Hi there folks. Optimus Prime here. Few of you know this, but when I’m not out blowing up bad guys with my ion-blaster and swinging my energon-axe, I enjoy solving Project Euler problems over a bowl of oatmeal and a cup of coffee at breakfast. Weird, right? It’s like seeing your teacher walking out on the street, or bumping in to your shrink at the grocery store. Anyway…

I wanted to talk to you about a piece of a Euler problem that I particularly enjoyed optimizing (the problem itself is here). It’s the method I call is_prime?, which, as it’s name suggests, checks to see if a given number is prime. Sure, I could use the built in ruby method Prime.prime?(n), but where would the fun be in that?

written in in optimization, prime numbers, project euler Read on →

Project Euler - Pythagorean Triplets

I’ve been trying to crank through Project Euler questions over the past week or so. They are pretty challenging at first sight, but I’m finding that after looking at them for a few minutes, patterns start revealing themselves and the problem becomes much clearer. Today’s question is the following:

A Pythagorean triplet is a set of three natural numbers, a < b < c, for which,

a2 + b2 = c2 For example, 32 + 42 = 9 + 16 = 25 = 52.

There exists exactly one Pythagorean triplet for which a + b + c = 1000.

Find the product abc

written in in math problems, project euler, pythagorean triplets, ruby Read on →

Removing an Item With the Jquery-CSS-Ajax Trifecta

Recently I’ve been working on a basic dive logging application with my buddy Chris from caguthrie.com. The idea is to take the very manual booklet that divers have to fill out after a dive and bring it online. Similar products like this exist, but we wanted to make our own.

I’m using this project to beef up my javascript/ajax skills and as such, will be writing today about removing items from a page using javascript, and then removing those items from your database by making an ajax request to your server.

We built a section in the log where you can add fish that you’ve seen on your dive. It’s based on a scrape of common fish from wikipedia. Here’s an example:

written in in ajax, css, flatiron school, jquery, removing images Read on →

Implementing CarrierWave - a Simple Guide

This weekend I decided to add file uploads to a small project I’ve been working on (mostly to get some additional rails practice). After searching for a while, I came across Carrierwave, which is a simple ruby gem that sets you up with easy image uploading and processing.

The setup was a lot easier than I expected. First step was to add the carrierwave gem to the project’s gemfile and run ‘bundle install’. Straightforward. After this, run ‘rails generate uploader {uploader_name}’ (in my case, the name was guests (as in hotel guests). In your app file you’ll now find an ‘uploaders’ directory, in which you will find the uploader class that you just generated. Cool. Leave that there for now.

written in in carrierwave, coding, flatrion school, gem, rails, ruby, uploading Read on →

Launching a Sinatra-based Heroku App With Postgres

Friday was equally one of the most frustrating and satisfying days I’ve had since I’ve started at the Flatrion School. We spent the day working on our pending labs/personal projects and I picked up where I’d left off on my venture to scrape yelp and display museum opening and closing hours dynamically. Once I had my css where I felt like it was somewhat presentable, I decided to set up my application on Heroku, something I imagined would be a simple and painless process. Was I wrong. What followed was five hours of dealing with obstacle after obstacle to get my app launched – so much so that at one point I had four TAs gathered around trying to help me get through the myriad of issues I was facing. Anyway, I’m going to try to explain what I did to get my app up and running, hopefully this will be useful to other people trying to do the same thing.

written in in flatiron school, heroku, postgres, sinatra, sqlite3 Read on →

Notes From a Weekend of Hacking

I’m piecing together a little Sinatra app that scrapes Yelp and displays schedule data for the many museums in New York. It’s an interesting exercise and has been pretty challenging so far. It’s not finished yet, but here are a few thoughts and lessons from my work:

1) rspec – I had a lot of time getting rspec working, but I found that checking all of the dependencies and essentially testing each piece of the process was the best way to troubleshoot the bugs I was getting. Once I had spec working, I actually got into the groove of writing tests and then immediately solving those tests in the models I was building. The best way to go about it is to write the tests precisely and with a narrow enough scope that they don’t seem totally overwhelming when it comes to solving them. Also .to be is not the same as .to eq. ().to be() looks for an exact object match, as opposed to eq, which looks for the contents of the object to be the same.

written in in flatiron school, new york, nokogiri, scraping Read on →

How Legal Is Web Scraping?”

I’ve recently learned how to perform basic web scraping using nothing but Nokogiri, Open-Uri, Ruby, a paperclip, and the internet. It’s an awesome feeling – to be able to MacGyver your way deep in to the code of a massive website and pull out exactly what you need, throw it into a database, and then manipulate that data to your heart’s content. It’s like I’ve discovered that I have a secret superpower, and am only beginning to see what I can do with it.

MacGyver

How I felt when I scraped my first website

But, as the cliched superhero movie line goes: Son, with great power comes great responsibility. Cue John Williams music.

written in in flatiron school, internet law, law, nokogiri, open-uri, scraping Read on →