Wednesday, October 29, 2014

(GitHub) Branching Out

I created a GitHub branch all by my lonesome. There's an assignment to update the To Do List project on Epicodus, and I wanted to keep things separate because the web page changes significantly. I rewrote the HTML in a copy of the file (so 90s, I know) before I made the branch.

I typed in what my cheat sheet told me to, and checked my account. There's the branch. I kept thinking I would get more files on my hard drive, but nothing was different. I was all confused and thinking something didn't take, but I I opened my HTML files and pasted the new code in and saved it, and checked the status. It changed!

I did my commit, checked everything was okay, then switched to my master branch. Opened the files. Old code is there. Everything's working as it should. I guess! My very first branch was someone else making edits and I just merged it after fixing the button that went wrong. This branch will stay completely separate. Learned more git commands today, back has been patted. Planning out the JS after I get the test out of the way. My mood's been funky and I need to turn up.

Lesson learned here: keep calm and follow the directions.

I need to delete that folder I copied. Old habits die hard.

Sunday, October 26, 2014

Lazy Sunday Coding

I went back to the old pig latin translator code and adjusted to handle sentences. It was in the back of my mind that I should finish that project up properly but I hadn't done so.

I started the revision on a whim, though, so it was rough going for a bit. I was fumbling like I was still not used to coding. That made me uncomfortable. I was starting to panic, with the "this is easy to add, I thought. WHY IS IT SO HARD!?" but I took a breath and went through the steps I needed to take in my head:

turn a sentence into an array with .split()
run the pigLatin function on each word in the array
put the words back together into a sentence with .join()
print it all to the screen

I commented out lines I thought were going to change, changed some variable names and added some new ones to keep things really, really clear, and plenty of reloading the page. I got hung up on trying to use an iteration method to apply the translator, but it wasn't going well and went with a for loop that worked fine. That might be something for another day. I thought that I should add a punctuation stripper to it in case people typed properly, but said nah, tell the user to leave that stuff out.

I didn't time it but it was under an hour. The time went quicker after I started digging myself out of the hole. I'm pleased with how well I handled my code anxiety.

I'm avoiding doing anything that has to be done so badly.I have the next week to to take my database midterm but I'm not in the mood to deal with it. Good thing I can take it three times. I need to review.

Saturday, October 25, 2014

Address Book: Finished and What I Learned From It

Okay, the address book form is complete. Looks good! Here's the Github repo.

Tonight, I went back to try and remove the extra form fields added for extra addresses, emails and phone numbers. The solution was to add a class to the additional fields (I named it 'extra') and add a .remove() method when a contact is added to the contact list. So it resets to one of each line after you add a contact.

Here's the wrap up:

The .each() and .forEach() loops: I had been hemming and hawing over the syntax for this function for a while, but this time it just made sense to use it. I was pushing objects to an array, so .each() was the tool for the job. I had arrays containing multiple objects and I needed to loop through them and do things to them, so .forEach() was the way to get this done.

.each() - Iterates over objects and arrays. It's a jQuery method.
.forEach() - Used to iterate over an array. Vanilla JS method.

Instead of poring over the syntax example and meditating on it until I can get full meaning of it, I just jumped in and used it. I didn't sweat the details and it started to make more sense. It slimmed the code down a little bit as well. I love a good for loop but the new methods look so clean. I hope as I gain experience with more methods my code will tighten up even more.

Getting more used to this: I can use it (correctly, I hope) but I don't always know why. It's honestly one of those "Using this would be handy here" situations. When I do get a chance to use it's more intuitive than anything. It might be because I haven't used it in some complex situation yet, so I can't lose track of what this is referring to.

Sometimes you need a little more class: Adding the 'extra' class helped me manipulate what needed manipulatin'. That's all I can say about it.

Get that little victory and go home: As I was working on this bit of code, I developed some self control and patience. I got something working the way I wanted, I pushed to Github and put it away. No all nighters. I feel like I'm more confident in my abilities and that they'll still be there the next day. I had to get some homework and some other things done, so it sat for multiple days, and that was okay. It also gave me room to unwind and do something unrelated to coding without feeling guilty. That bit of mental health time is important.

The little victories add up. I feel good about things. Hope it lasts when I go back for a possible refactoring.

If you need some good JavaScript practice, head on over to Learn How to Program and get cracking! The founder of Epicodus has been very generous in sharing the bootcamp curriculum for free so that anyone can learn. I'm extremely grateful for it.

Thursday, October 23, 2014

Address Book project update: Progress has been made!

Oh man, this address book code has been fun. In a purely platonic way.

The code can be found at this link: Amy's address-book

First, there was the whole mucking it up and starting over thing, which I talked about before. Then I added buttons to add extra phone numbers and email addresses. I worked the code out fairly quickly. I added a form reset. Looking nice.

Then I noticed that when I showed the contact detail, it wasn't erasing the previous information! Last night, I was getting sleepy way earlier than usual, so I decided not to touch things until I felt alert. Slept on it.

Tonight, I started to get my hands dirty. I used jQuery's empty() method. It cleared the lists, but it left the list markers if the next contact had fewer entries. remove()? Nope. I think "If there was a way I could use an if condition here. That's got to be the way."

Here's the pseudocode I wrote out in my head:

For each li in the unordered list
If the li element is empty, remove it.

Not much to it, but I wasn't sure of what method to use to check for an empty element. I was thinking of plain JS and innerHTML and things like that, so I dug around the jQuery reference and found the html() method. Yay. (eta: I just saw that I used it before but completely forgot about it. Can't beat that 'everything is new' feeling, though)

I tested it out on the phone number fields first before trying to apply it to the entire page. When I finally got it working, I thought "I have to add this loop to every section. I should try to get it to work for the whole contact section. Using this ought to work, right?" So I replaced $('li') with $(this) and placed the each() loop at the end so that it cleans up after the information is replaced. Score!

I'm sort of kind of good with this. I know that it refers to the closest bit of code/function/whatever, but that's it. I can't explain it in a proper technical way yet. It's more of an hunch thing with me right now.

Now the last thing to do is to reset the form to one of each field. I did some good work tonight, and it didn't take as long as I thought! My process has sped up a little and that makes me happy.

Saturday, October 18, 2014

What I've been up to, week ending October 18 2014

I tried Ruby. It felt like I was cheating on Javascript. If this is wrong, I don't want to be right.

I mostly did it to go over some programming fundamentals from a different angle. The simple act of not typing semicolons at the end of lines was just GLORIOUS. Don't worry, I'm back on the JS wagon, but I'd like to keep going with this bit by bit.

It reminds me of when I thought about dropping Japanese and learning Korean instead. That ended up in "No, I've got time served in this. I can piggyback Korean off of Japanese later" (that's the way a lot of polyglots learn multiple languages; they learn the next language from the perspective of the previous one). I see how things are different and somewhat the same, which is interesting to observe. The little bit of Japanese I know is in hibernation though, because computer languages took over, but at some point...I'll know it all. Soon.

That ended creepy.

Today I'm mysteriously awake in the day time. I have taken some of that time to eat breakfast, listen to a self help book about growth mindsets, and banging out some more Epicodus projects. I started the Address Book project the week before, but I had homework and a midterm to take, so it sat on the sidelines. I came back to it last night, got to the second part where I'm supposed to expand it, and completely trashed the thing. I think I was too tired, mostly.

I started from scratch, walking through the first tutorial and explaining what I was doing to myself. It makes more sense than just copying it. It will be easier to get to the next part as long as I don't give myself enough time to forget. I commented the code, marked where my divs end so I don't break the layout again (sigh). It should be fine. I was never going to leave you, JavaScript. It was just an experiment.

About that: when something I had to code myself in JS had a method in Ruby, it tickled me. There might be a framework that does the same thing, but I'm not there yet. But it delighted me to no end that there was a capitalize method just for the first letter of a string.

That's all for now. Blogger doesn't want to save, so I'm copying this down for later if I need to.

Monday, October 6, 2014

countWords is finally a legit web app (heh)

I added a web form to the word counting program tonight. I needed that jquery refresh!

I learned:

How to iterate an array and display it on the page: Stack Overflow helped me on this. I tried a simple loop with .append, .text but I couldn't get it to show more than one item. The SO answer formatted the results and stuffed each result into another array, then pushed them to the screen with the .html() and join() methods. I used paragraph tags so that each result was on its own line. It works, so I'm glad. I also added a reset form button, so that you can look at the original text for a while if you want.

Most of my time was spent getting that part to work properly. The HTML went smoothly, just looking at Bootstrap docs to pick the right buttons. As much as I've done it, I still have to look at it. Ah well, that's what documentation is there for!

This was something that was nagging me and I felt I needed to do.

Of course, my Github repo is here.

The rest of the night will be spent reading and watching fun things. It's getting cold, so I should get used to hanging around the house even more than before.

Sunday, October 5, 2014

Pig Latin (one word at a time) complete and what I learned

I finished my Pig Latin translator for single words a couple of nights ago. I even set up a web page for it this time, something I didn't do in my last project because I was so glad to have code that works. Some things are better put away for a short while.

There's more reading and trying out code examples to do, of course. There's that study group on Google groups I need to look into. The monthly ache has started so it's been hard to sit for too long. This coming week I'll try to get things up to speed again.

There's some videos I downloaded that could use watching. I need to free up hard drive space but I haven't had much focus for coding videos lately, even though they'd probably help. The OOP side of things is something I'll need to understand well. Right now it still seems fuzzy and complicated.

What I learned from this coding project:

  1. Some new methods: I'd read about indexOf() and substring() before but never used them. They really came in handy. I stored indexOf in a variable so I could tell the code where to divide a string, since I had specific rules on where to cut things up. Substring helped me get the other half of the string stored, then I put everything together in the order I wanted. I wanted to use forEach(), but it never happened. I'll try harder next time.
  2. Testing, testing: Unlike the last project writing tests was easy. Thing is the structure really changed after I started writing the code that actually works. The tests gave me a little confidence that I was at least going in the right direction.
  3. Writing things down: After I did tests I went to the notebook and started writing. I'd code a little bit and then when I started to stare at the screen too much I'd go back to the notebook. I revised what I'd written. Just because you whiteboard/write pseudocode doesn't mean it won't change. I started trying to predict what variables I'd need too. Trying to figure out what I need so by the time I go back to the editor, I'm just putting the pieces together. 
  4. Checking string against an array: It's the nested iteration thing again, but I just like how it worked out the way I expected it to. I used this to find out where the first vowel in a word was in order to cut it. 
The next step is to work this out for sentences. I have an idea of what to do, but I wanted to stop for a bit because my homework needed to be done. I'm hoping it will be as easy to expand as I think it should be.

Thursday, October 2, 2014

mid-week learning updates

I started working on the Pig Latin translator project last night and got some basic code to pass some tests. Now that I started working on how to process a word, it got a little more hairy.

I've covered what to do for words with qu (squeal = ealsquay) and words that start with a vowel (and = anday). I have to do the words that start with consonants now. And then figure out how to translate a sentence.

I feel good on my progress tonight, though. I notice when I was switching between the console and Sublime, I got a clue on how to handle the consonants through a mistake. I hadn't updated the code in the file with what I was doing in the console and it was handling words that started with one consonant (like 'soon') like a champ.

I need to pursue this line of thought before I forget it. It doesn't handle words with multiple consonants at the start, so I still need to work out code for them, but I thought it was interesting.

I felt pretty good tonight because I'd made some mturk money (making up for yesterday, even) and still had the evening left.

The hardest part will come when I need to convert sentences. But I'm going to enjoy the fact that I'm plowing through the basic mechanics of this process pretty quickly. I might try to modularize it somehow. I know there's going to be a string array in there somewhere.

I'm going to have to write something out on paper to get me started. But that will be later.

There's still that homework to do! And a midterm in web server class, though I've got a week to before that's due.