Learning to hack, one day at a time

Category: Learning to Hack (page 1 of 2)

Regular Expressions

When I was first learning about what regular expressions are and how to use them, I was having a harder than average time finding good resources to explain the basics. Luckily for me, I have an amazing community that came to my aid. Erin Call wrote this awesome post, and Cory Kolbeck wrote this one explaining the bones of using regexes.

I wanted to write about regexes, but the write ups from Erin and Cory are far and away better than any intro I could write. So, I wondered for a while what I could contribute to the discussion. Then a friend who just graduated from Epicodus mentioned that she understood how to construct regexes (use Rubular!), but not really how they would integrate with an actual program. And I have done that! So, here is a description of how my pair partner and I used regexes as an integral part of solving PCS’s code challenge 4.

For our code challenge, we had to parse and clean a text file of data in this format:

[prefix] [first_name] [middle_name | middle_initial] last_name [suffix] phone_number phone_extension

where anything in square brackets is optional, and then appropriately assign the parts that are present to the correct column in a CSV. We used OptionParser to create our own flags to run a command line script that would do all this.

The way my pair partner and I ended up solving this problem was by creating two scripts. The first script read in the raw data, stripped off the first word in every line of that data and created a reverse sorted histogram*, and then wrote that histogram data to a CSV. We then examined the output and determined which of the words were legitimately prefixes. This is the script we used:

histogram = Hash.new(0)
while line = gets
  prefix = (/^S*/).match(line)
  prefix = prefix.to_s
  histogram[prefix.to_sym] += 1
histogram = Hash[histogram.sort_by { |prefix, count| count }.reverse]
histogram.each { |prefix, count| puts "#{prefix} #{count}" }

We needed to do the same for the suffixes, so we had to split the raw data into the name portion and phone number portion in order to expose the last word of the name section. At this point, we used a regex to match the tab whitespace separating those two parts of the data, saved the first part to a variable, then ran it through a similar script to create a histogram for the suffixes.

Once we’d done that, we set up OptionParser to take the prefixes and suffixes files as input, used those lists to break up the name parts of the data, then used digit matching regexes to both match the existing phone information and reformat it in a consistent way. You can see the source code for the cleaning script. Please forgive our horribly verbose code. Hopefully I’ll get around to refactoring it soon, but for now, done is better than perfect.

So, hopefully this will be helpful to someone looking for some way to actually use regexes in their code! If you feel like playing around with the scripts we wrote, the regexes therein, and OptionParser, you can clone the project and run it in your command line. In your terminal, follow these steps:

shawnacscott in ~/Code on master #%
+ git clone https://github.com/shawnacscott/pcs_code_challenge_04.git
Cloning into 'pcs_code_challenge_04'...
remote: Counting objects: 128, done.
remote: Compressing objects: 100% (86/86), done.
remote: Total 128 (delta 54), reused 103 (delta 32)
Receiving objects: 100% (128/128), 382.55 KiB | 541.00 KiB/s, done.
Resolving deltas: 100% (54/54), done.
Checking connectivity... done
shawnacscott in ~/Code on master #%
+ cd pcs_code_challenge_04
shawnacscott in ~/Code/pcs_code_challenge_04 on master<>
+ ruby clean.rb --prefixes prefix_words.txt --suffixes suffix_words.txt --input raw_customers.txt --output customers.csv

*a hash where the first word is the key, and the value is the count of how many times that word is present.

Portland Code School, Month 2

The confluence of my horrible default theme, needing to troubleshoot upgrading/downloading anything WordPress related, as well as, you know, all the classwork I’ve had conspired to make it easy not to keep up here. I’m sorry for that! Luckily, thanks to a friend at Hacker School, I got the poke I needed to get back over here:

You may have noticed that my theme is not horrible anymore, that my links are prettified, and that I’ve disabled all comments, in addition to actually writing. If I keep going at this rate, I’ll be blogging from my homemade space station in no time! In all seriousness, though, what I hope to do now is write something every day. What I will probably achieve is something every week, but I’m shooting for every day. As you can see from above, poking at me will get me to do things, so feel free!

Last time, I gave you a quick and dirty rundown of where we were in the Portland Code School: Ruby on Rails class, so let’s keep a good thing going. In week five we finished up our Sinatra app and our intro to routes. We also cleaned up some of our last vanilla Ruby learning tools, finishing up the Codecademy Ruby track, the Treehouse Ruby deep dive, and Ruby Koans.

Week six had us diving into Michael Hartl’s Ruby on Rails tutorial, and getting a brief overview of database structures and design. We’re on track to finish up Hartl by next Monday, and I have to say, thank goodness. Personally, I haven’t liked it overly much. It’s a great bird’s-eye view of a lot of different built-in Rails functions, but because it tries to really hit everything, it lacks a certain depth, in my opinion. It’s been a slog for me. Once I finish, I’ll write up a more in-depth overview of my thoughts on it.

In our seventh week we kept working through Hartl and started our fourth code challenge, learning more about scripts, regular expressions, and Ruby’s OptionParser class. That continued through week eight. A lot of us PCS students were a bit confused, I think, about where we were heading with this one, but once we got into the groove of it, I think we learned a lot. I love that we now have an understanding of regular expressions (which are awesome, and totally not scary!), a taste of what’s necessary to clean and parse incoming data, and a framework for writing scripts to automate processes.

As an aside, the OptionParser class has some terrifically bad documentation, but it’s worth it to slog through. It’s quite a powerful and easy to use (once you eventually figure out how) little tool. It allows you to create your own command line flags and do all sorts of fun manipulations of files quickly.

Week nine is where we are now, and this week was all about getting us ready for our capstone projects! Can’t lie, I am excited for this. We actually pitched our project ideas last week, but this week we wrote our briefs, user stories, wireframes, and page flows. The tl;dr is that I’m making an ally email moderation app. It will allow people who receive a lot of hate mail to filter out harassing messages and let their trusted allies catalog them. The allies can then immediately alert the intended recipient if there are any actionable threats in a message, and log all the rest.

I’m a little nervous, since I’ll be writing this app on my own, and it will require a lot of different and somewhat complex Rails functionality. I’ll need to be able to use encryption, authorization, authentication, and any and all general security chops I can muster to make this a thing that could be used some day. I’m confident, though, that I will learn a huge amount of practical Ruby on Rails knowledge by implementing all of these things, though, and that is really thrilling!

What I’ve Learned So Far

The days (and hours, and weeks!) are flying by now that I’m able to make learning and coding a priority. I can’t believe my time at Portland Code School is one-third over!

I haven’t been as diligent as I would like to be about blogging here, so I wanted to skim the surface, and make sure I’m keeping some perspective on how much I’ve learned and how far I still have to go. So, here’s the run down:

We started out with the basics in week one. Getting our environment fine-tuned, installing things, learning about version control, and getting hooked in to the Portland developer community by leveraging social media and local user groups. I had already gotten a lot of those things done in the weeks leading up to school, which gave me time to focus on Treehouse and Ruby basics.

In the next week, we got our first code challenge, and I had a lot of fun finally getting in the mud with some actual Ruby. Well, actually, I had a lot of hair-pulling and late nights reading and watching screencasts to force the basics of methods and classes in my brain. But fun too! We learned to create classes and methods and started working with simple internal data structures like arrays and hashes. We built our knowledge base on other basic programming constructs like loops, iterators, and branching, as well as working on our git workflow to learn more about pair programming and working with remotes. We started getting our feet wet with the concepts of debugging and test driven development, too!

Our second code challenge (and third week) introduced us to modules and extending the Kernel, and worked to mentally reinforce the amount of room and flexibility that Ruby has. Everything really IS an object! Unit testing became an integral part of writing our code. We continued the basic introduction to Ruby concepts we’d been working through.

Currently, we’re on code challenge number three, and about to head into our fifth week. We jumped headlong from the end of our Ruby concepts (procs, blocks, lambdas, libraries, and core!) to building a basic Sinatra app and manipulating HTTP requests. We’ve gone from taking stairs two at a time to four at a time, and I can only imagine we’ll be leaping whole flights by next month!

Looking back, I’m so excited to see all the things I’ve been able to encounter, struggle with, and then finally understand. It has given me a lot more confidence in my ability to learn. Now when I encounter something complicated and foreign, I feel more often like the reason I don’t instantly understand is that I need to read and ask more questions, rather than thinking that I must just be inherently flawed and unable to comprehend.

I don’t have any illusions that I will come out of this program with the ability to write brilliant code as an island. But I am confident that I will come out of it with well-developed tools to write what I can, collaborate well, and keep learning voraciously. It seems to me, those might be the best tools I could have.

Community is Everything

This past week has been a whirlwind. I’ve had tons of demands on my time from my personal life, on top of watching the firestorm that has been the Ruby community on Twitter these past few weeks*, and trying to learn ALL THE RUBY for Portland Code School.

I have to say, in a week where community has not been safe for many people*, I have never felt more supported. The men and women who are part of my network of friends who are also in tech have gone above and beyond to help me learn and grow in the ways that I need to succeed.

This week, I struggled mightily in understanding the chain of events in Ruby. Classes and methods and instance variables had me all tied up in knots, and I was stuck. A friend directed me to the online overview of Chris Pine’s Learn to Program, and I finally started to trace the threads. I’ve now received the updated, paperback version (as well as Eloquent Ruby!) as a birthday present, and I can’t wait to dive in! The next day, another friend lent me her copy of the PickAxe book by Dave Thomas.

Later, while trying to work through the Code Challenge this week from Portland Code School, I got myself all twisted in knots again thinking I needed to use regular expressions. Turns out I didn’t, but as a result of mentioning I had had trouble finding good resources for beginning to use them, three different members of the community started writing blog posts to fill that need. So far, Erin Call, and Cory Kolbeck have both written up some awesome stuff about them, which I still need to carefully read and review!

Then this past weekend, I hacked on stuff with other awesome people for seven hours in various parts of town. To be able to have so much knowledge and such generous giving of time and expertise so readily available is a gift I will never be able to repay.

So thank you.

Thank you to Christie, who founded Women Who Hack, the first technical event I ever attended. Thank you to all the amazing women I met there. Thank you to Melissa and Ian who donated to my fundraiser so I could even go to Code School. Thank you to Liene for studying Python with me and sending me well-timed resources. Thank you to Rachel for her unending kindness and consideration matched with extreme insight. Thank you to Kronda for her WordPress wizardry and generally amazing sense of humor. Thank you to Michelle, the founder of Code Scouts for helping me meet even more amazing people. Thank you to Ashe and Julie and Shanley for doing the blisteringly hard work of carrying us all forward. Thank you to Chuck and Erica for creating Portland Codes School and for helping me find a direction. Thank you to Sam, for inviting me into his home to help me learn. Thank you to Cris for giving me the benefit of the doubt. Thank you to Al for always working to be accountable and give us the best possible class. Thank you to Erin for being the most generous and understanding technical lead, mentor, and friend. And thank you to Emily, who pestered me into attending that first Women Who Hack meeting, and has been there to cheer me on every step of the way, and to walk me through the scary parts.



*I will not be discussing the details of that here. Please go google around if you want to know and don’t already, but be forewarned, massive trigger warning for everything bad you could say to and about sexual assault

First Week at Portland Code School!

This week has been quite the whirlwind!

Monday was my first class with Portland Code School for their Ruby on Rails class. We spent a lot of time getting to know each other, since the plan is to spend the next three months eating, sleeping, and coding together. We talked about the tech experience (or lack thereof) we each have, and discussed the structure of the class to follow. As I feared, I’m the only woman in the class, and possibly the only queer person (though that’s much harder to determine). Overall, our class of seven is somewhat more diverse and somewhat less privileged than I expected, so I actually think it won’t be a barrier.

Tuesday we were asked to attend the Portland Ruby Brigade meeting, which was not my first time to their events, but was my first time attending one of the sessions featuring speakers. Overall, I liked the first speaker, Markus, the best. It’s hard to even describe the topic of his talk, since he seems to integrate his thoughts across multiple topics quite deeply. Overall, he was discussing this forum post. Definitely worth a read.

The second talk was honestly quite over my head, and I didn’t really have a framework yet for relating to it. Talking with others afterward, though, I discovered I definitely wasn’t the only one who felt a bit lost. Not to say the speakers weren’t engaging or funny or smart. They just had a target audience that didn’t happen to include me.

The last speaker was talking about different models of inheritance, and it was actually quite interesting. I’ll have to do some research at some point.

Wednesday was class number two, and we covered web applications, how the web works, the model view controller structure, and a bit of standards based development.

Thursday I went to the Green Mercury hack night, and proceeded to spend most of my time there fixing things I had broken on my own system. I was trying to customize my bash prompt in iTerm, and I managed to overwrite the contents of the .git-prompt.sh file (which I was using as a source) with the contents of my .bash_profile. Which resulted in an infinite loop, locking me completely out of bash. Which, by the way, makes it somewhat difficult to access your hidden files. Eventually, with massive amounts of help from Erin, we were able to use zsh to get into the files and change them in order to break the loop.

After that, I discovered that the link between my local Green Mercury repo and my remote was somehow severed, and had to spend a bit troubleshooting that. Then I made the brilliant move of deleting a file both through Github’s web interface, and also on my local branch and had to once again ask Erin to rescue me. Ultimately, I learned about git reset, my reflog, cherry picking, and how exactly git structures and conceptualizes branches, so ultimately it wasn’t so bad.

Between working and code related activities, I was outside my house at least fifteen hours each day this week, and I was glad we didn’t have anything planned for Friday! This weekend, I’ll spend a lot of time working on getting up to speed on all my homework, and hopefully getting a workspace set up for myself at home. This coding/learning while in bed thing doesn’t work for me. All in all, though, I can’t wait until class on Monday!

Adding Color Schemes to iTerm

This may seem ridiculous, but I had a lot of trouble trying to figure out how to add the zenburn color scheme to my terminal program, iTerm. Since I had trouble doing it, and it turned out to be way easier than any of my internet searching suggested, I figured I’d chronicle it here. Hopefully it’ll save someone else some time.

Searching for how to add zenburn produced a whole lot of results telling me to add one script or another to one of the various dot files for bash. I agonized over how to add it correctly, and when I did, why it didn’t actually affect anything. Then, I asked a friend. Turns out, the answer is this:

  1. Go to the iTerm 2 Color Scheme repo on Github
  2. Click, “Clone in Desktop” and save the file somewhere
  3. Open iTerm’s preferences, and choose the “Colors” tab
  4. Choose “Import…” from the drop down at the bottom that says “Load Presets”
  5. Choose the file from wherever you saved it
  6. Enjoy your new color scheme

Hope I saved you some time!

Streamlining My System, Part 2

My Ruby on Rails class through Portland Code School starts tonight, and I can’t wait! In preparation, I’ve been working on getting all those fiddly annoying things about my (I feel weird calling it this, but…) environment set up in a way that makes sense. I outlined some of my goals in an earlier post, so I wanted to revisit it to see how I did!

I did end up getting “subl” set up, which I’ve already started using pretty regularly, and its great. Vim is cool and all (no, that’s a lie), and I’m glad I can navigate my way around it if I have to, but modern text editors exist for a reason. I am happy to help myself out with tools anytime I can.

I ended up abandoning Colloquy, and went ahead and actually paid money for Textual. To anyone who knows me personally, I’m sure this is shocking. I never use paid software. Like, not ever. And yet, I paid a whole $5 for Textual, and it was totally worth it. It’s so much sleeker and more intuitive than Colloquy, the documentation doesn’t suck, and I can easily customize which (if any) noises I want it to make. I can’t tell you how many people I scared to pieces with Colloquy notifications.

Relatedly, I have progressed in my quest to have an IRC bouncer set up. I now have ZNC installed and configured (sort of) on my server, and now I just have to actually figure out how to add channels to it. Installing was a challenge, since nginx is apparently designed to be the least beginner-friendly and intuitive server on the planet, as is my AWS instance. I ended up having to create a swapfile in order to install all the things I needed, since apparently I was maxing out the capacity of my instance.  I may also have made a mistake in configuring ZNC, since I appear to have somehow disabled SSL (although I swear I followed ZNC’s instructions on enabling it exactly, so WTH). So, not a total success quite yet, but definitely significant progress made.

I did manage to add the zenburn color scheme to iTerm, which turns out to be ridiculously easy, and I am irritated that apparently no one on the internet knows that it’s easy. Or else, they just don’t bother to explain it because it’s so easy. Look for a post on that soon, since I can explain it easily and hopefully save someone else hours of time sorting through dot files to no purpose.

As you can probably tell, I didn’t make any progress on making this blog look less atrocious. I also didn’t have any luck figuring out how to edit a WordPress blog locally that is not run off of some sort of Apache server. I’m doing some more research on Vagrant after reading a bit about it and how it works with nginx, but have nothing to show so far.

Overall, I’m pretty happy with my progress. All the essential things are finished, and the rest is really just gravy. I’m sure I’ll eventually get around to it. Onward to code school!

Streamlining My System

Running Total Hack Time: 78.5
Topics: Portland Code School, streamlining workflow
Resources: Google, Team Treehouse

Through a completely unexpected chain of events beginning on Tuesday, today I signed the paperwork to start learning at Portland Code School on Monday! I am super excited to start their Rails class, and so I cancelled all the rest of my hacks for the week (except Women Who Hack, since it’s awesome and I help out with it). I did that so I can focus on getting myself set up well for the class. There are a few fiddly workflow issues I haven’t yet worked out, so I thought now was the time to do that, before I begin the whirlwind class-and-full-time-work schedule of the next few months.

One of the things I’ve been meaning to do (and which seemed like low-hanging fruit) was set up the “subl” command so that I can actually open things with Sublime Text 2 from the command line. I successfully accomplished this using this gist, although I changed this line:

ln -s /Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl /usr/local/bin/sublime

to just say “subl” at the end, because I didn’t want to have to type the whole word every time, and so that if someone else uses my computer, they’ll be familiar with the command.

Other goals before class time include finally getting ZNC to be connected to Colloquy and/or another IRC client. I managed to finally get it installed on my server last night after much ado. But I have no idea how to do the part that I feel like should be easy and hook it up to my client. Ah well. I’m sure I’ll get it soon.

I also want to fix my iTerm 2 setup so that it will actually be a decent color scheme, and be color coded in a useful way; work a bit on streamlining this site to my liking; and set up storage space on my AWS account. Once I do all those things, I’ll be working on the new Team Treehouse Git Basics tutorial.

I’m sure I’ll not get all of this done by Monday, but I can try and get it as close as possible. I doubt I’ll have much spare time after that!

EDIT: Check out Streamlining My System, Part 2 to find out how I did!

Learning to Hack: EC2, Server Configuration, and Finally Launching My Domain

Running total hack time: 71.5
Topics: AWS, EC2, server configuration, nginx
Resources: EmilyErin, Kronda

Ya’ll. If you plan on setting up a website? EC2 is pretty much the most labor intensive way you can do it. Seriously, I’m coming up on about ten hours worth of setting up the instance, configuring the instance, adding myself as a user in a non-irritating-to-use way, installing nginx and configuring it, installing MySQL and configuring it, and installing WordPress and configuring it. Actually, listing it out makes me feel a bit better about it. Apparently, a lot has gone into this.

I have to say a huge thank you to all the people listed in my resources, because they all sacrificed hours of their time helping me get up and running. I could’ve put a hundred hours into this on my own and not gotten to the place I am now. Emily especially is the EC2 instance goddess. She will straighten you out, come hell or high water. Although, this was all her idea in the first place. She just had to tell me that AWS was free for the first year. I am nothing if not penny-pinching!

This is quite a few topics to cram into one post, but while I learned a lot, I honestly couldn’t reproduce these results on my own. A step-by-step tutorial this is not. I did solidify some broad-stroke concepts, though, so let’s talk about those. This will probably seem silly to a lot of you, but I’ve committed to an honest description of my learning, so you’re gonna get it, warts and all:

  • The concept that a server is just a computer I can’t touch had never really clicked in a visceral way for me. Sure, conceptually I understood that, but now, having SSHed in and played around for a bit, I get it in a more concrete way.
  • I’m beginning to get a handle on the concept of a database as well. Again, makes sense on an intellectual level, but I’m getting close to that visceral understanding, too.
  • Using the command line as much as was required for this has helped me feel more like I’m doing things with it intentionally and with an understanding of the consequences, rather than just regurgitating something someone told me to type. Although, believe me, I did a lot of that in this process!
  • I used vim a decent bit during this project. I will no longer get stuck in my own terminal! I’m by no means efficient wile using vim, but I can add, delete, save, and (most importantly) quit. I doubt vim will become my one true love as far as text editors go, but I can navigate it without fear when necessary. That’s pretty flippin’ sweet, in my opinion.

All in all, I can’t say I would recommend this method of setting up your own hosting for a beginner (and if you don’t have someone in your life with prodigious knowledge of EC2 and time to spend with you, I would actively lobby against it), but I can say that I learned quite a lot, and am excited to see it all coming together. Still have a lot of work to do to make this a site I can be boast about, but for now, I’m pleased as punch that it all actually works!

Learning to Hack: Team Treehouse, Green Mercury, & Ruby on Rails!

Running total hack time: 34

Topics: Team Treehouse, Ruby on Rails, git, github
Resources: Team Treehouse, Ruby on Rails, omg so much StackOverflow, Erin Call, Emily Strickland

Over the last few days, I’ve been diving headfirst into Ruby on Rails. And what a dive it’s been. My friend described Ruby on Rails as like an iceberg. The code you see is only the tip, with this massive, inscrutable architecture underlying it all. I have to say, I’m finding the description apt.

My learning right now is simultaneously working through the Team Treehouse Ruby on Rails tutorial and also (attempting) to contribute to the green-mercury project to relaunch the Code Scouts member network. It should be really amazing once all is said and done, but for right now, I’m mostly just trying to keep my head above water. Erin Call, the technical lead on the project, has been really awesome, sending me little tidbits to bang on, and then letting me debug them when my eensy little pull request broke other stuff. As a result, Iet’s just say I’m having to get a lot more familiar with version control and the git commands that go along with it.
I can’t honestly say I have much idea what I’m doing at this point, but the longer I stare at the code, and the more I fiddle with it, the more familiar it becomes. It’s a concept I’ve found helpful about tech in general. It’s a much different kind of learning.
For example, when I was in school and learning other things, I felt like while I was learning I would understand 75-95% of what was going on in classes. I would do some readings, or ask some questions, and do a few assignments and voila, I was up to speed. Tech hasn’t been like that at all. At first, I thought I was just bad at it, and that was why I couldn’t understand what was going on around me. For a long time, I actively told people how “bad” I was at technical things, and that I was just “one of those people” that technology never works for.
Luckily, I had a friend, a CS major, who was really patient and really invested in sharing the things he was learning. So, he found ways to describe the concepts with metaphors and without language in a way that was comprehensible. I still only understood maybe 15-20%, though. But I listened to him, to be polite and show an interest in his life. Eventually, though, I started to realize I was understanding maybe 25% of what he said. Then 30%. And I realized that, unlike other subjects I was taught how to learn, tech just requires constant exposure. You are literally learning not just one, but multiple languages. Not just languages, but an entirely new framework and infrastructure. The more you immerse yourself, the faster and more thoroughly you understand.

I’m up to maybe 35-40% understanding at this point, I would say. My comprehension still lags behind, but I can occasionally ask pertinent questions, and I’m beginning to be able to have a tiny little bit of a frame of reference. I’m beginning to understand who in my life is the best person to bother about certain topics, and that not everyone has the knack for making things comprehensible to beginners. That has been such a huge leap forward in my ability to learn, and my ability to overcome my impostor syndrome And that is probably the most crucial thing necessary for me to see this through.