Noob to Hacker

A narrated quest - From ignorance to bliss

Recent Posts

  • All Moves for Each Pokemon Type (Fire, Water…) in Pokemon Go

    All Moves for Each Pokemon Type (Fire, Water…) in Pokemon Go

  • The best Pokemon Go tips and advice

    The best Pokemon Go tips and advice

  • Complete List of Moves and Attacks for Each Pokemon in Pokemon Go

    Complete List of Moves and Attacks for Each Pokemon in Pokemon Go

Day 12 – Getting harder – Finalized lec4 MIT – Specification, Recursion

March 18, 2016 by Noobtohacker

I start feeling that the amount of info taken in is too much to comfortably remember. I am getting a bit concerned of not being able to fully assimilate everything :S! At the same time I am happy I started this blog because I know that at any point I am lost I can go back look what I did before.

One thing today is that I learned that with triple quotes you can do specifications. Those help the user understand what a function does. “”” specification “””

Also I start feeling the pain and effort that is going to take to go forward! 😛 It’s not going to be easy. And MIT course, the assignments really are tough!

Also already touched Recursion in class. Recursion is pretty scare. Let’s see if I am able to assimilate it.

First recursive function:

I am quite happy because teacher talked about “Palindromes” and he wanted to use a recursive function to find if any string is indeed a palindrome. I paused the video before he showed how to do it and came up with the answer myself. I am happy cause it took me just 15 min or so to get it right.

def palindrome (string):
	if string[0] != string[-1]:
		print "Sorry not palindrome"
		return
	else: 
		if len(string) <= 1:
			print "this is a palindrome"
		else:
			string = string[1:-1]
			palindrome(string)

However, after seeing the teacher equation, I feel a bit bad. Because my code above is really not following the right order and its unnecessarily complex. the teacher function is much more ordered and fundamental.

def ispalindrome(s):
	if len(s)<= 1:
		return True
	else:
		return s[0] == s[-1] and ispalindrome(s[1:-1])

His formula is so good. Basically it says, if string length is less or equal to 1, then we have reached the end and thus is palindrome. If not then return the result to a logic comparison X with Y.

X is answering the question “Is the first and last letter the same?” if yes it will be “True” otherwise “False”. And remember that we are doing X and Y, so this means that if the condition X is not meant, the formula will return False, it’s not palindrome.

And Y is basically asking… is the word in between the first and last character a palindrome? (If yes, it will mean it returns True).

Still there is a big gap of truly understanding recursive functions for me. Basically there must be a base case, and we test stuff on smaller and smaller chunks until we reach the base case, once base case is reached, the function “unwraps” and goes back again one by one till the beginning point. 

Another explanation: https://www.youtube.com/watch?v=Mv9NEXX1VHc

Way too advanced, but this is a great video to go back in the future where it explains a real life scenario where recursion is needed: https://www.youtube.com/watch?v=k7-N8R0-KY4

 

Filed Under: Learning Computer Science

Day 11 – Google Analytics

March 15, 2016 by Noobtohacker

Day 11 – Google Analytics

Google Analytics is used to track different metrics regarding the traffic that comes to a site of yours. I am interested in learning more about it, so I am following the Google Analytics at this link.

So far it has been interesting. I am not going truly deep into it, but want to definitely have an overview on what to build afterwards.

One big point is that: There is no genius or magic formula to quickly derive good insight from data. Good insight from data comes from hard work, and a lot of trials, tests and time spent looking at it. 

I am quite happy with the lessons so far.  Tomorrow more.

 

Filed Under: Learning Computer Science

Day 10 – MIT 6.00 Assignment 2 Diophantine Equations Solution

March 14, 2016 by Noobtohacker

Day 10 – MIT 6.00 Assignment 2 Diophantine Equations Solution

Well, I tackled today the problem 2. It took me a long long time to get it right (about 3:30 hours), and it is quite interesting cause in essence the program is very simple. It’s less than 20 lines.

This shows how hard it is sometimes to think (Especially after a tiring day of work!), but at the same time, how powerful technology can be in helping solve a problem. If problems are looked in the right way, they can actually be solved in fairly simple ways thanks to iteration.

What was the hardest part?

Honestly, the hardest part was to understand how can I easily substitute numbers like this. Imagine you have 3 slots (a,b,c), and you want to test ALL the different combinations of numbers that can be put in those 3 positions, knowing that a,b,c can be any integer from 0 to 100, and use each one of those combinations to do some calculation.

At the end I realized I could just use 3 “for” loops and that solved it. First calculates all possibilities with 0.0.x, then 0.1.x, then 0.2.x etc… until… 0.100.100, then it does 1.0.x , 1.1.x etc…  until it reaches 100.100.100

You can easily test this by executing the following code:

for a in range (0,20):
    for b in range (0,20):
        for c in range (0,20):
            print " ({0} ,{1}, {2})".format(a,b,c)

Filed Under: Learning Computer Science

Day 9 – Version Control – GitHub

March 13, 2016 by Noobtohacker

By working on my MIT assignment, I clearly saw that there needs to be some way one should be able to see little by little what are the improvements one has made to a program.

If you are working on one file… then once you improve the program and you save it, you lose the previous version! And this can be quite annoying actually.

It is then that GitHub came to my mind. I don’t really know how to use it, but basically I know it’s a place where people put code, and you can see different versions etc. and it seems to be used quite extensively in professional coding, so I have decided to learn how to use it.

Learning how to use GitHub

To learn how to use GitHub, this video is the one that really helped me understand.

Basically I can see it is quite a rigurous program, that forces the user to pretty much document every change before it can be put up to the cloud. Then there are great tools in the cloud to see all the previous versions of the file etc!

To use GitHub I had to use the command line, which can always be a bit scary.

For windows I downloaded the program and then downloaded the Git Shell.

Creating a project.

Then there are some very basic comands really! After you have created your repository online on your GitHub account, you then just need to go to whatever folder in your computer you want to save your “repository” or project on, and type:

  • git clone <URL of the repository>

This will basically pass the project to your computer.

Uploading the changed files of a project.

Then, from the GitShell (and while you are inside of your project folder), there is a process to upload a file you changed online again.

First you can type:

  • git status

This will show you the status of the files on that project… have they been modified, but not uploaded yet? etc.

Then you can type the command below if you want to upload one specific file or all the files of that project.

  • git add <filename>
  • git add -A

The file won’t be yet uploaded though! For it to be uploaded it first needs to be commited. This forces the user to put a coment on what are the changes made etc.  You do this by:

  • git commit -m <“instert your comment here”>

Then, file won’t yet really be up! For it to be up you need to push it by using:

  • git push

And there you go! Your file will be up online, and all the changes and previous versions or versions from other people will still be accessible and all.

If you want to then update your files on your pc with the latest changes on the GitHub online, then you need to use:

  • git pull

Filed Under: Learning Computer Science

Day 8 – Looking at object oriented programming and classes again

March 12, 2016 by Noobtohacker

Day 8 – Looking at object oriented programming and classes again

Today also I wanted to refresh a bit the concept of classes etc…

Classes, objects and magic methods

What are those things like __init__ and other things like __x__? They are “Magic Methods” and they are too complex for now. In the future I can study them here.

When you start a class o initialize it, whatever attributes you put inside parenthesis, you WILL have to pass those attributes when you want to create a related object. All of them. If you miss one, you will get an error.

the def __init__ (self, name, age): basically says what happens whenever an object is created on that class. And as spoken, it demands x1,x2 whenever you create an object, otherwise it wont work. Self is just the name of the object, so “itself”.

so for a class Student, I can create and object like this student1 = Student(“Toni”,39).

the def __str__ (self): magic method basically tells the program what to do whenever an object is printed. So if I do print(student1), and I don’t have a str function, the program will return the address in memory where that object is stored. However if you have the str magic method on your class… then when doing print(student1), the program will do whatever you have told it to do under the method __str__

the def __del__(self): magic method, basically tells the program what to do whenever an object is deleted. You delete an object by saying del(). For example you can do del(student1) and the program will do whatever you want the program to do for that object in it’s class __del__ magic function.

Then I also learned that you can have variables and functions of the class, that don’t really depend on object. So you put thes ones before the def’s. Below for example there is a variable “population” that is independent on the objects.

At the same time, you can for example say that, whenever an object is created (__init__) , a certain class variable (even for another class) gets affected. Below, whenever a student object is created, the population goes 1 number higher.

Below you can also see that when I make a student object, it demands me to pass “name” argument. It is fine, but then you need to make sure that you “save” that. This is why below you can see that in the init method, whenever an object is created, self.name = name. This means that Object.name = (whatever “name” you passed).

class Student:
	population = 3
	def __init__ (self,name):
		self.name = name
		self.attend = 0
		self.grades = []
		print "Hi! My name is {0} and i have attend¨{1} ".format(self.name, self.attend)
		Student.population += 1
	def __str__(self):
		return "Hello"
	def __del__(self):
		print "You have deleted " + self.name

Curly Brackets to substitute

Indirectly also learned that curly brackets can be used to substitute certain variables inside of a string to avoid having to concatenate each variable.

I learned that this is actually a pretty good thing, because if you concatenate things with “+” you have to worry about str not concatenating with numbers etc…

In the case below, the first wouldn’t work because in the program we wrote beffore, attend is a number, and name is a string. The second one will work.

print “Hi! My name is ” + self.name + self.attend
print “Hi! My name is {0} and i have attend¨{1} “.format(self.name, self.attend)

I am not fully sure how the substitution works with the {}, but it seems that you basically just pass as many variables as you want at the end of the string with .format(x1.x2.x3.x4) etc… and then you can replace by those on the string by using {0}{1}{2}{3} basically.

Nice!

 

 

Filed Under: Learning Computer Science

  • « Previous Page
  • 1
  • …
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • Next Page »