Crochet · Programming

Starting a Nanodegree at Udacity

While I’m still looking for a job this summer (which is almost halfway over already… Blah!) I took a cue from Y who started to work on some side projects and I decided to be a little more productive. Since I have a free month of Udacity from the GitHub Student Pack. Udacity is basically an online learning hub where you can take courses that are related to the tech field.

Since I am an aspiring full stack web developer, I decided to go with the appropriately named, “Full Stack Developer” Nanodegree. I am probably around 20% completed the degree and it’s been pretty much a week since I started.

So far I have done some basic Python programming and responsive web development. I didn’t learn much with the Python programming part because it was all very basic and I’ve done a lot of Python programming. Basically I made a movie trailer website that is composed of static web pages generated with Python. The web pages are composed of movie trailers that are pulled from The Movie DB using their API. You can check out an example here or take a look at it on GitHub.

Right now I’m working on a responsive web design. It’s taking a little bit more time because I’ve been busy the past couple of days. I had my first counselling appointment with a new counsellor, went to some Stampede breakfasts, and hung out with family and Y. But I think I’m pretty much done it all except for making sure everything complies with Udacity’s style guides. I keep tripping up on them wanting being lowercase instead. It’s hard to break old habits.

One thing I really like about their format is that there are a lot of videos. That way I can take my time to weave in ends for my temperature blanket that I’m working on. July is turning out to be a rollercoaster for weather. I had my first solid colour square the other day. It was pretty rainy on that day which explains why it was so much cooler. Now the rain spell has mostly ended and we’re back to low 30s weather. I don’t know which I prefer the most…

A post shared by Edel Altares (@edelgraceme) on

Programming

Udacity Programming Fundamental Lesson 5: Take a Break Mini-Project

Seeing that I am now unemployed and have a lot of time on my hands, I decided to utilize the free month of Udacity I received from Github’s Student Pack.

This mini-project’s goal is to create a simple program using Python to open a web browser at an interval of ten seconds three times in a row.

Here is my answer:

import time
import webbrowser

break_duration = 10
break_num = 3
break_count = 0

print("This program started at: " + time.ctime())

while(break_count < break_num):

    time.sleep(break_duration)

    webbrowser.open("http://edelgrace.me/blog")

    break_count += 1

First I will explain the first two lines. In Python, there are many different modules that you can utilize to achieve specific things. Think of them as apps that you use on your phone. You have apps for calendars, contacts, games, social media, etc. Just like apps, we don't really need to know how exactly modules works, just how to use them to get what we want. In this case, we use modules to get information about the time and to use the web browser on the computer.

import time
import webbrowser

Next, I initialize some variables. Think of this as giving something a name. For example, I am 22 years old as of writing this. This would be my age. In the code, I am declaring that the break_duration (how long to wait to open a web browser) is 10 seconds. The break_num determines how many breaks to take, which is 3. Lastly, the number of breaks taken so far, break_count, is 0.

break_duration = 10
break_num = 3
break_count = 0

This line will print out a message to the console with the print function. Inside print, it uses a function from the time module that we imported earlier. The function we use is ctime(), which grabs the value of the current time.

print("This program started at: " + time.ctime())>

The last chunk of code is a while loop. Think of while loops as a set of instructions to repeat until a condition is met. I will break this down line by line.

while(break_count < break_num):

    time.sleep(break_duration)

    webbrowser.open("http://edelgrace.me/blog")

    break_count += 1

The first line determines the condition. This loop will keep running as long as the number of breaks taken (break_count) is less than the number of breaks that should be taken (break_num, which is 3). When this condition is not met, the code inside the while loop will stop running.

while(break_count < break_num):

Then we use the function time.sleep() to essentially wait for the number of seconds and essentially do nothing. From the official Python documentation, we can see that this function will accept numbers in terms of seconds, which is what we are using in break_duration.

time.sleep(break_duration)

Once the 10 seconds has elapsed, the next line of code will run. This uses the webbrowser.open() function. It essentially does what it says: open a web browser. Here, we indicate which site to open. In my case, we open up my blog for a quick break. 🙂

webbrowser.open("http://edelgrace.me/blog")

After that is all done, we have finished a break. Therefore, we increase the variable break_num by one to indicate that a break has been finished.

break_count += 1

The code then goes back to the start of the while loop and checks the condition. break_count is now 0+1=1 which is still less than break_num (which is 3). This repeats two more times until break_count is 3 and then the condition fails and the while loop is skipped over. Since there is no more code after the while loop, the program ends.

Programming

TIL: How to Add a MySQL User

CREATE USER 'user'@'server' IDENTIFIED BY 'PASSWORD';
GRANT PRIVILEGES ON database.table TO 'user'@'server';

I recently bought a VPS from Ramnode and started tinkering on it. I needed to create a database for my fanlistings. Back when I was on shared hosting, I would use cPanel and phpMyAdmin to do all that. This is admittedly another TIL that I didn’t learn today but, rather, relearned today because the information slipped my mind. Maybe I need to rename this little segment to “TIRL.”