Monday, June 2, 2014

Day 16: CSV files, pagination, and Object-Oriented Programming

This morning started off with a lecture about security, namely preventing SQL injections. The whole concept is very simple and the way to prevent this is to just wrap it in a function that will make any inputs into Strings and not be read as a SQL query. However the funny part is that some studies say that 80% of web applications do not protect from SQL injection. Seriously? I was shocked.

After putting in at least 15 hours of coding over the weekend, I ended up being quite ahead of most of my classmates so I began working on an optional assignment. This assignment was to take a CSV file and make it print to a nice table.


In addition to presenting the information on a nice table, we also had to paginate the data. This is a view that's limited to 50 pages. You can also see the link on the top left. The pagination was made possible without using a database by using the $_GET superglobal that you can see on the URL. By passing in what page we wanted to see, I used that variable to get the right scope of data. This assignment took so much longer than I expected. Although CSV files are not a common thing to see, developers may be given a task like this and are expected to know how to extract the data so it can be put to use.

Another quick thing to note is that I once again used Bootstrap to make the form look nice. There's a group of 3 of us in the class that literally use Bootstrap for every assignment. Me and my fellow 'bootstrappers' really see the value and the power of this library and definitely try to get as much practice as possible.


Up next we have Object-Oriented Programming. Now before we started this chapter, we have been doing things "procedurally". Although Object-Oriented Programming might take a little longer, this method saves us much more time and lines of code once our applications become much more sophisticated.

I did wonder why we didn't introduce this concept much earlier, but I trust in the curriculum. I already have a solid understanding of classes so it wasn't hard to pick this up.


Here is an example of the power of OOP. The Dog class below doesn't have to repeat all the code that the Animal class has. Instead it can just inherit all the data. From that point on, you can modify and make changes as necessary.

That's it for today. On Friday of next week, I'll be taking my green belt exam. However I do have the option of taking the red belt exam. If I am able to take that exam and pass, I'll be given a green belt as well. Students can get a black belt as soon as week 8 and a "2nd degree" by the end of the program. I'm shooting for it all!

Saturday, May 31, 2014

Week 3 Weekend: Putting it all together: Database, forms, validations, etc. and preventing SQL injection

Today I met up with some classmates to get some extra work done on our assignments. We worked on one of the big checkmark assignments: The Wall.

In this assignment we were to create a "wall" which acts as a public bulliten board. Users can register for an account and post on the wall. All data is stored of the database with proper connections between tables.


Here is the registration/login page, made beautiful using Twitter Bootstrap (I'm glad I finally get to post "pretty things" after doing database stuff for a week). The form displays messages when errors are made on the form.


Here is the actual wall where users can post information on the "wall". Furthermore users can make comments on posts all made possible by associations created on MySQL.


One thing I really like about Coding Dojo is the reoccurring talk about security. Here we are taught how to prevent malicious attacks by hacker trying to ruin information in our database.


The more I learn about security, the less safe I feel about using web applications. How many of these apps are actually doing things like encrypting my password or preventing things like SQL injections? From what I'm gathering from the web and those in the industry, it is much less than I think.

With security there really is no 100% hacker-proof application. All a hacker needs is one open window. But the thing is... you don't to have the safest house on the block, you just have to be safer than your neighbors. Why would a hacker bother to go through all the loops you set up, when other web applications don't have those security issues?

Well 6 days of coding in a row has made my brain extremely exhausted, I think I'll take it easy tomorrow and rejuvenate my brain for next week when we start learning OOP and MVC frameworks.

Friday, May 30, 2014

Day 15: Connecting PHP to MySQL

Today's morning lecture was a demonstration on how to write these PHP programs efficiently. Michael really emphasizes writing up the HTML and making it look like the desired output before starting anything else. This may be opposite of what many developers do. I know when I was doing Rails tutorials, I was taught to think about models and how they connect to the database before I even write a line of HTML. There really are benefits either way but I really do see the benefit of the way Coding Dojo teaches it. There is a reason why we start with wireframes. Also clients and designers may change their minds about how things look and if we can agree on that, we're in a pretty good spot before we make hefty changes to the back-end.


Today we added on top of our original understanding of PHP and validations but now we were adding a database to work with.


Here is a snapshot of my MySQL workbench where I have data.


And once again the usual registration and login page.

Today was the first day I truly begun to feel "powerful". I have the ability to create a web page that users can submit forms store user input into databases and output data on a profile page. I even started daydreaming of being Mark Zuckerberg's character in The Social Network when he first started coding Facebook.

Speaking of Facebook, our next assignment is to create a facebook-like application where users have a profile where you can make posts and others can comment on the posts.

This is really really exciting. I'm only a 1/4 of the way done. I can't stop coding!



What I love about this bootcamp is the pace at which we learn. The gas pedal is always hitting the floor. There are some students that are falling behind and aren't picking up the concepts as quick as others but there are always TAs available if they need it.

Thursday, May 29, 2014

Day 14: More sophisticated form validations

Alrighty so no morning lecture today so we dived right into the material. Yesterday I showed you an example of a really simple email validation page that directed to another page when successful and displayed error messsages when something didn't look right with the email. Today we took it up a notch (again) and made form validations for numerous input fields each having their own quirks.


This page (apologies for the lack of style) has numerous features. First it ensures that each input field has some valid data, makes sure the name fields don't have numbers in them, password has to have at least 7 characters, the birthdate has to be a valid date, and there needs to be a file chosen for upload. When any of these requirements aren't fulfilled, error messages are outputted and the respective input fields are highlighted. This pretty much is about what you'll find on the majority of web applications.

I'm starting to get very very comfortable with PHP. I gotta say it's extremely easy to use because you can simply enter your PHP code right into the HTML section (or wherever its needed). Up next we are going to learn how to connect these types of forms and store them into the database and also retrieve them. Exhausting but very exciting!

Wednesday, May 28, 2014

Day 13: PHP Forms and Validations

Today at the Dojo we really kicked things up a notch learning how to use superglobals to validate form inputs and protect hackers from malicious attacks. I have previous experience with rails but I never really understood how it validated the data. All I really did was put validates: presence: true, etc. in the model and all the validation really takes care of itself. Through PHP, I'm having to create a file commonly called process.php that checks all the form inputs to see if they meet criteria.




Our first assignment was to create a simple site (top pic) that consists of a input field that validates the data. If the data was not valid, the page would redirect to the original page and display an error message above the form (middle pic). If the input values were valid, then it would redirect to a success page. Although it was a very simple app, it's just the first stepping stone to more sophisticated applications.

Here's an example of my PHP code that validates the data.


Tuesday, May 27, 2014

Day 12: Advanced sorting algorithms and CSV

This morning lecture was just a quick demonstration on how to write PHP more accurately and with minimal bugs. Ultimately you write out all your code to get a good idea of where the repetition occurs so you know where to put in loops. Another important thing that was noted was to make sure that you work on one feature at a time. A lot of times when we're coding we get really ambitious and work on a bunch of features and then all of a sudden our code doesn't work. If we were working on one feature at a time it would be much easier to figure out what we did wrong. I'm personally still working on it because a lot of times when I'm coding I'm almost certain that every thing will be fine. To be fair it usually works out great when I do that. However the times that it doesn't and I end up spending hours trying to figure out my code is not worth it.

As I made steady progress through the PHP, there were some optional assignments for me to work on. They were sorting algorithms which were more advanced than what we had. We had the usual selection sort, bubble sort, and insertion sort, but there was one in particular that took me at least 90 minutes to get working with all cases: the Radix Sort.


Although it took me an incredible amount of time to figure this out, this is all about "paying your dues". Every great programmer has taken their time to figure out these algorithms to train their brains to think like a machine. These algorithm-type challenges seem to be very common during interviews and I want to make sure that I am a beast when it comes to these.


The learning platform wanted us to post these solutions up on github. I know one day I'll become a great programmer and look back and laugh at how I used to solve these algorithms.


After figuring out the 4 algorithms above and writing them in PHP, Ruby, and Javascript, I was off to working on additional optional assignment. On the top-right, you'll see a CSV file. Although they aren't commonly used by developers, once in a blue moon you might run into them and Coding Dojo wants us to at least have an idea of where to look when dealing with these types of files. The code listed below shows how I pulled data, line-by-line, from the file and echoed the HTML with proper formatting.

What's interesting about this assignment as well as some of the others recently is that there wasn't much guidance and I think it's all intentional. When we leave Coding Dojo and enter the workplace, we aren't going to have a learning platform that has a list of the necessary functions. The places that we look are the documentation as well as google. It seems like great developers are extremely good at using search engines to solve bugs. 

There is a lot to be learned with PHP and I feel a lot of my classmates are getting exhausted. I heard Michael Choi say, "Wow you guys are all working on the optional assignments? I think that's a first!" We are all probably very exhausted because we are extremely determined. I get a sense that as a class, we have a culture of over-achievement and are perfectionists. When I'm not "plugged-in", I glance around the room to see classmates practicing algorithms over and over again on the white board. On the other side of the room, a pair would be having a discussions about cryptocurrency while another pair would be reviewing each other code.

Although my brain is fried at the end of each day and the amount of learning can be overwhelming, I'm glad to be a part of this experience. It's so easy to quit when you're learning all this material on your own, however being with all my classmates and having this culture of perfectionism really keeps me going every day.

Monday, May 26, 2014

Day 11: Beginning of PHP

Woke up this morning and opened up my email to be notified that I passed my yellow belt exam! When I arrived to class today I received one of these cool stickers to show my accomplishment.


 I just now need to get green, red, and the difficult-to-obtain black belt that only about 15% of students get within the 12-week timeframe.

So after focusing primarily on front-end development with HTML, CSS, and jQuery, it was time for us to learn our first back-end language, PHP. This language has honestly gotten a bad reputation (I don't know exactly why) but all I know is that a lot of people know how to use it and since there are more programmers that are proficient in PHP, the pay is much less than what you'd expect from a developer. Furthermore I heard there are some weird quirks about it but nevertheless it remains a very popular tool.


After watching a bunch of videos talking about PHP and how to use it we first started off with a series of algorithm challenges to make sure that we know what we're doing before moving onto the assignments. The most annoying thing about PHP really is syntax. It's so funky and unique from the others. I've had programming experience primarily in Java, Javascript, and Ruby. PHP is quite different. But I must say, the way you use PHP is mighty impressive.


Here I am embedding PHP directly into the HTML and generating content by extracting data from an array and "echo"ing HTML blocks. This method may look a little ugly but it seriously reduces your code significantly.


Not only can you use PHP to generate HTML, you can pretty much generate anything. On the picture above I'm using PHP inside a CSS stylesheet and allowing the color attribute of the h1 and p tags to be randomly chosen using the rand() function.

We've only started PHP today so there really isn't much to report. It was honestly a pretty exhausting day of learning an entire new language and syntax. A lot of my classmates were also having some brain overload of knowledge. But we all know that we just gotta keep pressing forward.

For the rest of the night I'll be working on the next assignments which are a bunch of sorting algorithms like Radix sort, Selection sort, etc. Coding Dojo wants us to write them in 3 languages: PHP, Ruby, and javascript. Fun stuff!