Saturday, October 31, 2015

Day 8

More SQL Queries


The homework for SQL Queries were actually pretty fun. Like I wrote in my previous entry, figuring out the queries and how to get the information you want from the databases is a lot like plotting a route in a maze. You look at tables and see what information they have and you look at the relationships to help you determine your starting point and your ending point.

Unfortunately for me, I always get screwed on easy questions because of a small thing that I overlooked. The question was write a query that will return all movies that are in the drama genre and has a rental rate of 2.99. Seems pretty straight forward, and I saw in the ERDs that I'm going to be joining quite a bit of tables to get my answer (shown below).



I would go from categories table all the way to the payment table. Or so I thought. The film table actually has a rental rate column that I overlooked. Which led to me scratching my head and doubting my confidence in my joining abilities.

I don't like looking at the answer sheet unless I am truly stuck. But after spending an hour trying to figure out where I go wrong, I gave in and realized how dumb my mistake was.

This just goes to show how merciless databases can really be. Or that I need better vision.
Anyways, I only had enough time to finish the mandatory SQL assignments. I plan on going back to it this weekend when I have time.

Day 7

MySQL Queries


And just when I thought I understood databases, SQL queries messed me up. Now I grasped SQL a lot easier than I did ERDs, probably because I spent so much time on ERDs. The trickiest part of SQL queries is joining tables. CodingDojo's website had .gifs showing each step of the query and how it is visualized. What I learned is that when creating queries for data that you want, it's like creating a trail through different tables. 

How queries works:
select (the data that you want from the query)
from (select a table - usually the table that you have a specifying feature)
(insert any sort, order, join commands);

How join works:
from table1
join table2 on table1.id (or whatever is the primary key's name) = table2.id (the foreign key)
join table 3 on table2.id = table3.id etc.

One feature that I learned for join is that you can join another table without referencing the previous table that is joined (which is the most common type of joins).

from table1 
join table2 on table1.id = table2.id
join table 3 on table3.id = table2.id

I also learned self-joins, which became very meta very quick. Self joins are basically tables referencing itself. Think of a table with users connected to a friendship table. You have a foreign ID from the users table in your friendship table to reference the users. But you also have a friend ID that is not referencing any other tables but itself (since you have the users, those are your friends). Confusing? It gets better; 

How self-joins work:
select 'something'
from table1
join table 2 on table1.id = table2.(foreign key #1)
join table1 as table1'  on table1'.id = table2.(foreign key #2)

This might not be the best illustration but if I find a better way to describe self-joins then I'll edit this entry!

Day 6

ERDs


I remember when I worked at ADP, I would use Access a lot to pull information from our databases. Today I learned how to set up those databases and pulling information is a lot easier than creating them... ERD are known as entity relationship diagrams. I learned about the 3 relationships: 
  1. One-to-one 
  2. One-to-many 
  3. Many-to-many
When first going through the videos, it makes a lot of sense; have unique IDs for every table, foreign keys in the tables you want information on, and many to many relationships have to have a joining table. Then the normalization rules:
  1. Each column have can only have 1 value (think address street, city, state, zipcode being broken up into separate columns)
  2. If not foreign or primary key, cannot repeat values. This prevents repetition of data.
  3. Non-key columns cannot be dependent on non-key columns. Meaning, that if you have a column in a table that affects other columns, (like zip codes determining state and city), then you must create another table for that column and have a foreign ID put into the original table.
Here's a picture to illustrate:


















Then, after learning just these 6 things, they start asking questions on the assignments that slowly didn't make sense. I don't know why it took me so long to understand these concepts. The only cure was to keep practicing and answering a variety of questions. But the one question that will stick to my mind is: can A have multiple B? Can B have multiple A? To determine what relationships the two objects have with each other.

The assignments weren't too difficult and didn't take a long time although the instructions could be clearer. All in all, the more assignments I finished, the more I understood the subject although now my issue is that I can't fully explain my decision about creating relationships between tables. I can't believe that most DBs can have 50+ different tables when I'm struggling with just 5!

Day 5

Yellow Belt Exam


So I absorbed quite a bit of information the past week. Today I took my yellow belt exam, which was just to re-create a website; pretty much the same as what I've been doing with the CSS assignments. I had 4.5 hours to finish the exam, and am able to use anything help me to finish the test. I got the website that had a lot of color gradients, which is irksome since I like to be perfect with what I'm creating. Anyways, I finished the exam in 2.5 hours. The one thing that I know I'm gonna get marked down for is using a div container for only one element. But for some reason, I couldn't figure out how to properly position my text next to the image. 

Anyways, the test wasn't that hard although it is disconcerting that I couldn't fix the text next to image issue. Probably going to go to Kris, my instructor, about how to fix the issue. For this weekend, I'm just gonna review over what I've learned so far - Git/Terminal + HTML/CSS.

Monday, October 26, 2015

Day 4

jQuery


Having done the CodeAcademy track for jQuery, I went through this section pretty quickly. jQuery is definitely a useful tool for adding cool animations onto websites. The section was pretty straight forward, learned the basic syntax of $(document).ready(function(){}); and the first homework assignment went through a lot of different methods (by having you write them). 

I was kinda surprised that we didn't use a separate file for jQuery scripts. But then again we didn't do too many animations. The first assignment that made me think was the one that had you click a picture which changes into another corresponding picture that fits like a puzzle (so think a picture divided horizontally 5 times. And when clicked, it would change to another picture that is also a puzzle. I'm pretty proud of being able to write it in one line of jQuery:

$(this).attr('src', attr('src').replace('ninja', 'cat'));

The attribute method allows for change, specifically in this case the source of my image. Since each image (ninjas0, cat0) have the same numbers to represent its vertical placement, I decided to just change the name of the image.

For the last assignment, it asked us to do a fade in/out of images as you hover over them and this is where I cheated a little and used the same pictures for the 4 images they wanted us to have. This part is where you get to use parameters and I wrote a pretty short piece of code. That's when a friend of mine in the cohort asked me, "what if all the images had to be different" and that got me to thinking about how you can have the same effects but not repeat the code. Obviously I had to use a variable but specifically do I put in it? A method? But with what parameters?

And thats when my friend and the previous assignments instruction started to make sense; use "data-alt-src" and store it as a variable so that it's hidden but the data is still there and use jQuery to surface it! There's an advanced jQuery section but that's not until later. The next unit is ERD and MySQL!

Day 3

Terminal and Git


Sorry for the late posts! Met up with Allen from my cohort today at the Regional Library. I worked on Terminal and Git for the longest time. The assignments weren't hard but for some reason I just couldn't understand how to do them that quickly. I think the weirdest part about Terminal is that you have to tell it exactly what to do and which directory to do it from. It was pretty annoying to have to change my directory all the time so I can change into the correct folders. For example, when I create a directory on my desktop and enter it, I can't just change into another directory, I have to go up one level (in this case, back to my desktop) and change into another directory that's a child of desktop.

That might sound really confusing to some, and maybe I'm just not explaining it well but think of it like branches (which ironically was another part I got stuck on in Git), you can't jump from skinny branches to another skinny branch parallel to it, you have to retrace your steps to a thicker trunk and then go into another smaller branch. I don't know if I made it more complicated but there it is!

Using Git and GitHub was interesting...and since we have been taught how to use terminal I decided to use terminal for the last assignment. What I ingrained in myself today is that process to do anything with a file in a local repository and how to export it (or push) into my GitHub account. 
  1. Always stage the file via git add . or git add file.extension
  2. Then git commit -m "initial commit"
  3. Make changes.
  4. Repeat step 1-2.
That was the easy part..the confusing part for me was the last assignment when I had to clone a copy from GitHub, add then commit, then create a branch, enter that branch, make changes, then re-add and re-commit. Then finally push it out into GitHub. I spent FOUR HOURS on this assignment and the stupid thing is the very first step that I didn't do; I didn't freaking FORK the file. I was so confused why I couldn't add my edited file into the GitHub repository, re-did the assignment probably 20 times. I guess the only good thing that came out of it is that I have since became very comfortable using Terminal and Git...but the next unit is going to be jQuery so I'll update about that next!

Wednesday, October 21, 2015

Day 2

Git and Terminal...


Today we had our first lecture via Google Hangout. Our instructor, Kris, just went over the basics and the first assignment on the CSS sheet. I was half-listening and half trying to learn terminal commands. I was still able to see how Kris did his webpage in a much faster time than I did. One cool feature was his use of outline property on CSS to outline which containers are which. I've been using borders to see where everything is but outline was the property I was looking for since it outlines the edges of the container rather than the outside border. 

Kris used the inspect element A LOT. He actually just tested all his CSS on the inspect element and when he was satisfied with what he saw, he would just re-write the code on the editor. This was pretty neat since I think it saved a lot of time but also I think you have to be pretty adept at using html/css to be comfortable knowing where to put everything although it's definitely another way I can make webpages faster!

As mentioned in the yesterday's post, I kinda breezed through the twitter bootstrap and LESS optional assignments. I definitely need to find time this weekend to at least get a deeper look. Twitter bootstrap just seems to be a bunch of pre-set code and all you have to do is change classes and whatnot to fit your desired webpage layout. LESS, from what I understand is a principle of how to write less CSS code. Although you have to run it through a program so that it works. One thing I've read and am pretty excited about is the fact that you can use variables in your CSS. This makes editing your webpage later on so much better since you can insert a variable and just change the variable at the top and see it cascade through all your selectors!

Anyways I'm meeting up with a bunch of fellow cohort people tomorrow at the regional library for a study session. It should be a pretty good experience getting to know each other.