Monday, March 31, 2014

Shamed by a Tweet

So I was la-la-la-ing along, working through The(Terrific)OdinProject curriculum online and saw this on Twitter just as I was shutting down for the night:


And I started counting how many of my posts were all about how I'm going to blog every single day!

Yeah, about that. So.

I'm not going to blog every single day. But I'm blogging right now. :)

I finally have a Linux machine. (I've got a new-to-me laptop with hardware ...including DVD player/burner!... that will allow for a partition and dual-boot option.) It's wonderful and I wish I had been able to do this sooner. :) Once I had hardware that could handle it, it was a total breeze!!

I'm using The Odin Project as a curriculum and attending (through Hell or high water) the next Railsbridge event this month. I've applied for the Gnome Outreach Project for Women (results are announced on April 21st) and I'm working on getting a team going for Rails Girls Summer of Code. My first website after Railsbridge will be my FixMyList idea. (FML, you see what I did there?) :D

That's enough for now. :)

Tuesday, February 11, 2014

Overcoming Obstacles

Or, the day I felt like Thomas Edison.
"I have not failed. I've just found 10,000 ways that will not work."

Repeat visitors may recall the pledge I made to apply to the next round of the Gnome Outreach Program for Women. You may also recall a major stumbling block was the fact that my (rather old) laptop runs on Windows and lacks the hardware necessary to partition the drive and run Linux alongside it. For many reasons, including the apparent electrical death of the family's main PC over the weekend (I'll come back to that in a minute), I can't just kill Windows on this machine.

Since Friday, I've spent the all of my spar(s)e time attempting to set up a virtual machine. I started with a very helpful article on MediaWiki.org called How to Become a MediaWiki Hacker that I found through OpenHatch.org. I really thought I was getting somewhere!
So I started downloading. The list was short (Vagrant and VirtualBox) but the files were rather large. And I was still trying to make Cygwin work so I could get through the rest of the OpenHatch training missions (pro tip: Patch is not installed by default and you really have to dig to find it.) And Vagrant wants to cut all of your network connections during its install, so it had to wait a bit.

Several interruptions later, I finally finished the downloads and installs and opened up VirtualBox. I spun up an Ubuntu VM and then it demanded the Ubuntu OS which was not included in the install. Of course. So I got Ubuntu, saved it to my little jump drive and ...

VirtualBox apparently will only allow the OS to boot from a DVD. Several more interruptions later (including the whole family hunting down an odd plasticy-burning smell which turned out the be the machine I had downloaded all of this on), I restarted all the downloading and installing on my little laptop.

That's when Windows helpfully warned me that I have only 399 MB left on my hard drive. So I spent a few hours last night deleting and un-installing every bit of cruft that I could find. I successfully freed up about 14 GB. And this morning, I started again. Installing, loading, popped in a DVD to burn a disc image of Ubuntu and ...

I kept getting weird drive errors. The system kept complaining that Error code: 0x80004005 occurred.  A quick Google search led me to a Windows repair tool. So I ran the tool and it couldn't fix the problem. I tried again with a different DVD. Nada. Finally I tried a blank CD. Success! I could feel a little smile starting in the corners of my mouth when I tried again with the DVD. That didn't work. Finally I tried to simply play a DVD. That wouldn't work either. That's when I started to get suspicious.

After some digging around, I found the detailed properties for my drive. (Is that a spoiler?) It's imaginatively named "DVD/CD-RW Drive" but when I looked at the manufacturer's name, it said "CD-ROM Drive." The cute little DVD icon is on the front of it, but it is clearly only a CD drive.



So, here I am. It's now time for me to go to my "day" job. I haven't pushed anything to GitHub. I haven't gotten email working on the Splash page. I haven't even finished that tutorial I was working on (I killed Cygwin, optimistic that I was going to get Ubuntu working in the VM.) But, I have found 10,000 ways that this won't work.

Tomorrow, I may find the 10,001st. I hope not, though.

Edited to add:  And then I found this!!  In short: RTFM! I'll have a sequel to this post shortly. (Ok, long-ly. I'll be honest.)

Wednesday, January 29, 2014

OMG It Worked!

So what did I do wrong? :)  I'm half-way between the two points on this comic:



Here is part one of the second iteration of my word count script/mini program:

word_count = {}
File.open('test_input.txt', 'r') do |f1|
  while line = f1.gets
    words = line.split(" ")

    words.each do |word|
      word = word.downcase
      if !word_count.has_key?(word) #word not in hash?
        word_count[word] = 1        #add it and count it
      else
        word_count[word] += 1       #only increment count
      end                           #if it's there
    end
  end
end


Next up, I need to figure out how to feed it html pages. I could just feed it straight up html files, but I ultimately want to word count blogs and such. On to the next!

Sometime later, we rejoin our hero:

So I added a line to allow me to alternatively feed the wc any file I like via the command line:
File.open( ARGV[0]? ARGV[0] : 'default.txt', 'r' ) do
I'm using ARGV[0] ? to check to see if there are any arguments sent along with the request to run the script. If there are, we use them. If not, we use my creatively-named 'default.txt' so that we don't blow a gasket and throw an error for not having anything to work with. I snagged some HTML from a random website and fed it to the wc program.

Next up: parsing out the tags so that all we're left with is the actual content of the site. After that, I need to figure out how to get the generated HTML in the first place. I've heard of screen scrapers (and usually not in a positive way) but I think that's what I need to build here. Ultimately, I would like to give this little program the urls for two different websites and have it compare the two. I'm a long way from there, but it's nice to have a goal. :)

Tuesday, January 28, 2014

Because I Promised

Here is a very rough first run of the word_count script.

input_text = "The quick brown fox jumped over the lazy dog. And then the sun shone down on everyone and the little girl smiled. This is the end of this story, this is the end of this story."

words = input_text.split(" ")
word_count = {}

words.each do |word|
  if word_count.has_key?(word)
    word_count[word] += 1
  else
    word_count[word] = 1
  end  
end

puts word_count.inspect

My next steps will be to turn it into a separate method and open a file and count the contents. After that, I want to be able to strip out the text from and html document. I'll need to create tokens for tags to ignore things like <p>, etc. Or I can just count them and then ignore things at the end that have a < as the first letter. We'll see when we get there. I may also go back and refactor the logic so that the `if` is when the key does not already exist (it's a little more human-logical that way, I think.)

Tomorrow's a new day. Good night for now.

Thursday, January 23, 2014

Mind Your P's & Q's, or Rather, Your I's & You's

I have a theory about blogs. Based on nothing other than intuition and my own anecdotal and subjective reading experience, I suspect that blogs that are more author-centered (use "I" and "me" a lot) are less popular than reader-centered (use "you" more).

To test my theory, I'm planning a little word-count program that one can feed some texts and it will compare them. (A more advanced version will allow the user to feed the program a url, but I'm not there yet.)  Details will follow soon. :) 

The first post I will run through the word-count will be this post!

Sunday, January 19, 2014

In Confidence

Lately, I've been thinking about confidence. Partly because whomever curates the Elance Twitter feed seems to have the same theme running through their mind recently. Partly because it's simply a recurring theme in most articles and books about starting out in new fields. At my "day" job, however, I frequently come across a certain paradox about confidence.

For many people, someone with a lot of confidence inspires trust. They are speaking with someone providing (or wishing to provide) them a service and if their service provider is confident in their abilities and value, the customer will believe them.

Except when they don't. Perhaps this is getting confounded with power relationships (I have a very low-power role when dealing with my customers - "the customer is always right" reigns supreme in retail and there's no room for a Vancome Lady attitude!) Even when I am confident about an answer, I feel the need to hedge it and say things in the most wishy-washy "I believe" (instead of "I know") sort of way. Anything more confident is treated to a "well, check anyway!" anger-filled reaction.

There's a voice in my head that says to go with the confident response anyway, despite the anger that it will sometimes elicit. Practice makes permanent and I have successfully convinced myself that I am frequently uncertain and dis-confident about what I really do know. Perhaps the positive response I will get from a portion of my customers will be worth the intermittent nastiness.

Hmmm... I hear the winds of change. If there's rioting at a certain drug store in Juanita, you'll know who caused it ;).

Friday, January 17, 2014

Bug Catching

Today was a day spent almost entirely on smashing bugs. Several mundane and one so blindingly obvious I could smack myself. (See Twitter, in case you missed it.)

My main goal for today was to make the background color of the sfs page coarsely change color based on the time of day (morning, midday, etc.) The logic of that was mostly straighforward:

def time_of_day()
    t = Time.now
    if t.hour >= 4 and t.hour < 10
      return "morning"
    elsif t.hour >= 10 and t.hour < 16
      return "midday"
    elsif t.hour >= 16 or t.hour < 4
      return "bedtime"
    else
      return "late"
    end
  end

I then used the returned string to set the class for the background.

<div class="<%= time_of_day() %>">

After that, I was a little stumped because it had been so long since I started this project that I couldn't remember where exactly to put the Ruby code! (I know, I know, I'm edupunkn00b, remember?) At first I tried to load it like I would a JavaScript file and I tossed this in the header of my index:

<script src="/helpers.rb" type="ruby/text" />   #this doesn't work!

First, yes, I need to refactor my views (you can see them in all of their sopping wet glory over on Github, if you like watching train wrecks :) ). Refactoring was planned for the second part of my morning, but that was used up with bug smashing. Second, regrettably, that didn't work. After playing around for a long, long time (I dropped the code right into the body of the index page at one point, just to be sure it would run) Finally, remembered app.rb. (Sigh, I know.)

# my_app.#!/usr/bin/env ruby -wKU
require 'sinatra'

class MyApp < Sinatra::Base
  # This is where your code will go

  def time_of_day()
    t = Time.now
    if t.hour > 4 and t.hour < 10
      return "morning"
    elsif t.hour >= 10 and t.hour < 16
      return "midday"
    elsif t.hour >= 16 and t.hour < 7
      return "bedtime"
    else
      return "late"
    end
  end
  
  get "/" do
    erb :index  
  .
  .
  .

The little "this is where your code should go" comment was a nice little dig. Maybe I should have named the file "this_is_where_your_code_goes_dummy.rb"

After all that, it worked! I got my little test <h2> tag that showed the logic. I created some CSS rules and ....

Nada. I tried F12 and Chrome had just drawn a big ugly red line through my CSS and called it invalid. What was going on? I tried renaming the colors (I once had a bug because I used 7 digits instead of 6 in a hex code.) Nope, that didn't help. I tried different selectors. Nope, the selectors were working just fine. Finally I decided to just try to change the background color and that's when I caught it. I had written the rule as:

body div.midday {
  background-color: #000000,  # <-- right there!
  color: #FFFFFF;
}

SMH, FML, STFU, D'OH and every other acronym you can think of. Do you see it? I stared at that code for almost two hours (well, not two hours straight, but you get the idea) before I caught it. The comma. Perfect if you're making a list or want to describe the dietary requirements of the giant panda, but very, very bad when trying to describe how you want your class to look in CSS. I fixed that bug and thought, great! Time for the Heroky Pokey and... it didn't work.

There seems to be a recurring theme here. It worked locally on Chrome, so I pulled it up in Firefox.

Nope.

OK. Time for coding with the world's most popular language: Google. It seemed to be a rather common problem. Try it - I got over 1.5 million hits. I felt a little better after that. After much digging and rechecking (nope, Firefox and IE were loading the CSS file, so I wasn't blowing it there), but neither browser would recognize them as CSS. Then I looked a little closer at what I had typed:

<link type="css/text" ... />  # wrong!

and not

<link type="text/css" ... />  # correct!

A little more typing (and even less swearing) later, I had it fixed and running: http://schatz-family-splash.herokuapp.com. It's ugly and, well, ugly. But it works. Kinda. Tomorrow's always another day. :D