Have you every want to modify your car ? Well if you have then you already know the basics of what a extension is. Since you modify something that someone else has made (maybe you also made it too, but thats okay).
OR have you ever been in a situation where, you are working on something. And you thought “maybe I should write a new class to extend this other class, that way I add to the functionality”. You could do that, “could” being the keyword there. OR you could just use Extentions 🙂
Extensions let you add new functionality to existing classes, structs, enumerations, or protocols. All you have to do is extended them.
Your going about your normal programming life. Everything is fine, your using functions and classes and variables, and etc. And you’ll be thinking “I got this programming thing pretty much in the bag”
But then you see “it” what “it” is your not sure. Its something coming out the side of your function … OMG is looks like another function. A function against a function ???
We all know what a function is, it is just piece of code that we can use in different places. It some times takes in varables and spits them out. This is all “normal”, however what if I told you that you could return a function from a function ? Or even add a function as a input value ? Pretty crazy right ?
Some of you out there might be thinking, “why would you need this ? stop making things soo complicated !” Well if you want your applications to run asynchronously, your gonna wanna use closures when ever you do something that takes alot of time.
So the use case would go something like this:You wanna log someone in, and execute something else as soon as it finishs, without freezing up the UI (in a iOS app).
Instead of doing it the standard way of writing the code that needs to be executed right after the method call. You can just pass the login function, another function to execute once done.
The in depth code will come in part two.
Hope you found the theory behind it easy to understand 😅
This is a comparison of the three top frameworks out there summarized in a chart.
Most of the information came from this great lecture from the “Convolutional Neural Networks for Visual Recognition” course at Stanford.
Warning this only works on Mac OS.
Now before you start thinking your going to make the next WordPress, let me just say we are only going to be making the MVP of a blogging site, that’s right a MVP. What is a MVP you may ask ? It stands for Minimum Viable Product, this thing we are about to build is just a web app that has CRUD functionality. What is CRUD you ask ? CRUD is Create Read Update Destroy.
Don’t be afraid of the terminal, the terminal is your friend for life 🙂 you just got to treat it right.
Up and running:
- Install Home Brew, is manages the software you need to manage all the software, your going to use to make software. Just follow the instructions on here: https://brew.sh/
- Install Bundler, it manages the specific Ruby software libraries for your application. Type the following command “gem install bundler”.
- Install Nokogiri, it gives Ruby the ability to understand HTML and CSS among other things. Type the following command “gem install nokogiri”. This is going to take awhile, chill out and take a break you have been working too hard 🙂
- Install Rails, its the thing that you build on top of, to make your web application. Ruby the language has libraries for doing different things. Rails is just a really big library for making web based applications. As you may have guess just type in “gem install rails”.
Making a Rails App:
- CD into a folder you would like to be in and run the following command “rails new <name of your app here> -T “
- Now if you look into the folder you just ran this command in, you will see a folder with the name of your app. Open this with your favorite text editor, VSCode is always a good choice.
- CD into the newly created folder, and make your database. You can do this by running “rails db:create” and then running “rails db:migrate”. What this is doing is creating a database, and then populating it with boiler plate info.
- Now run “rails s” and go to the URL is gives you. You should see your app, YAY you made your first rails app 🙂 If the URL isn’t working try using http:127.0.0.1/8080 or http:127.0.0.1/3000.
Actually making the Blog:
- Run “rails g scaffold Blog title:string body:text”. What this command will do is create a Blog object, that has a title and a body and can be stored in our database. Rails knows this since “g” is for generate, “scaffold” is for create everything for me, and the rest is specify what type of things you want there to be, in the object you are creating.
- Now you got to let the database know about this blog object you made. To do so simply run “rails db:migrate”
- Finally the moment you have been waiting for, run your app with “rails s” and ta-da you go your self a working rails app 🙂
As you an Angular component has a life cycle, much life us humans. In the beginning we are nothing, we do a bunch in the middle and then we die 🙂 However if you want to call a certain service in your “ngOnInit” to dump some values into a var that appears in your html, your going to have a bad time. Or at least angular is by throwing a lot of errors in your console, I mean it will still work.
To get rid of these errors all you have to do it the following add a “?” at the end of the end of the var that’s in the html, and ta-da errors gone. This works since the “?” tells Angular to chill out there will be a value you there “eventually”. Hmm… but why eventually you may ask ? Its because two functions before “ngOnInit” get called , the very first one being the constructor of the class and the second being the “ngOnChanges” method. So for the execution of the first two methods its asking “WTF where is this thing in the html in the .ts file ?” which makes throw errors.
When you inherit from a class you have full access to it’s variables and methods. However what do you do when you would like to use one its methods, and then add to it ? Well you would try to override the method with your definition. This can be accomplished using the “Virtual” keyword on the function you want to override on the parent class. And then using the “Override” keyword on the function in the child class. After which you would then use the “Super” keyword to call the implementation of method found in the parent class.
A real world application of this is, when you want to override and add to the “BeginPlay” method.
Here we see that the TankPlayerController inherits from the APlayerController that inherits from the Actor class. The Actor class holds the initial implementation of the “BeginPlay” method.
Please note that I will not be covering the mathematical portions, but rather the big ideas.
Can come in different forms, however at the end of the day we are trying to learn a function in order to map or training. Such that it becomes a good predictor of an output given a inputs, this is a sort of regression problem. Where as functions who’s outputs are limited to a few discrete outputs, given various inputs are for classification problems.
These functions are used to measure the level of accuracy of our hypothesis functions (the function we learned), by measuring the difference between our predicted value and the true output. And then computing the average error by way of the “Mean Squared Error” function. In a single variable regression problem the hypothesis function reduces to being the equation of a line.
The objective becomes to minimize the cost (or error) function. If you have ever taken Calculus before you can do that easily by taking the derivate of the function, setting it equal to zero, solving for the parameter, and using that value in your learned function.
However its not always easy when given a large set of parameters. Therefor you can also use contour plots, that act like maps to the values that reduce cost function to zero.
An easy way to think about gradient descent is by, imagining your a blind person trying to find a ball in a hilly area. You don’t know where the ball is, but you know the ball has rolled into the deepest valley in the area. However your blind so you can’t see the depth in your surroundings. Therefor you have to use your feet to feel for the steepness of the ground in front of you. By doing so you take little steps in the direction of the most steepness. This is exactly what the gradient descent algorithm does as well. It takes little steps, gauges the steepness, and then moves in that directions till it finds the global minimum of the cost function’s derivative.
You can find the first part of this series here.