FER razredbeni ispit rijeseni zadaci (mat 1, 2, 3, ViS)


U prilogu se nalaze riješeni zadaci sa razredbenog ispita (ispit za upis na diplomski studij) FER-a.

Zadaci ukljucuju gradivo matematike 1, 2, 3 zajedno sa predmetom vjerojatnost i statistika.


In the attachment below you can find solved problems for the masters study exam which student from other faculties and those who have studied more than 4 years for a bachelor degree have to take in order to enter the masters study of the Faculty of Electrical Engineering and Computing.

Solved problems part 1 (mathematics 1, 2, 3 along with probability and statistics).



Node.js REST, Mongo tips

  • In express library functions: post(), get() will stop the execution of code if you write return. It’s like in any other function in programming. keyword return will always stop the function execution.
  • When you write (res is the response callback function) res.end(), res.json(), res.send(), in other words when you end the response you cannot utilize res callback again it becomes irrelevant since you completed your restful service with a response. If you have any code after res.something() it will execute till you specify a return but res will not be available anymore. If you use it however, it will throw an error.
    Refer: Execute code after res.end() (StackOverflow)
  • You don’t need to return res.end(), json(), send() if you don’t have code which needs to execute after it.
  • If you don’t have anything to send to the Frontend side then use res.end() to complete the service action.
  • Use next function, specified at the end of restful service callback function:
    .get((req, res, next) => {action}

    to catch errors and forward them to the middleware:

    if (err) {
        return next(err);

    the return next() will go to the already built in error handler and will result with a 500 XHR failed request on the Frontend. Also applies for catch() blocks, having next(err) will also result with Node.js built in error handler execution giving 500.

  • A Node.js mongoose query is not a JS Promise. They just represent a async operation which returns a then so that you can apply: query().then(res=>console.log(res));
    Refer: Mongoose async queries (StackOverflow)
    If you want a real instance of JavaScript Promise then put an exec() after your “fake” Mongoose query promise: query().exec().then(res=>console.log(res));
  • The default status for res.send(), res.json() is 200 thereby no need for res.status(200).send() or res.status(200).json();
  • In Mongoose findOneAndUpdate query
    User.findOneAndUpdate(findQuery, updateData, {
    upsert:true represents that if the record doesn’t exist a new one will be created/inserted
    useFindAndModify:false removes deprecation warning
    new:true gives the response of updated data, otherwise you get the data of the current findQuery record.
    I like to specify those parameters for each query so that I know what to expect from it.
  • ObjectId(userId) vs
    new ObjectId(userId) are the same, use whichever one you like but be consistent once you pick one.
  • Do not close your mongo database connection after terminating your query and then reopen upon querying database. You should have/define a pool of connections instead and closing it in Node.js process termination
    process.on(‘SIGINT’, mongo.mongoDisconnect).on(‘SIGTERM’, mongo.mongoDisconnect);
    Refer: Closing a Mongo connection (StackOverflow)
  • Do not use query.remove() for deleting data from the database it’s obsolete, use deleteOne, deleteMany instead.
  • For clearing the session and destroying the browser cookie use:
    req.sessionOptions.maxAge = 0;
    (I use it to logout the user)

Unique web-application on proton pump inhibitors (stomach acid reducing drugs)

For those who wish to see the app immediately click here

At around November 2016, I decided to build a web-app that would encompass scattered data across the web on proton pump inhibitors into one single place with the adding of a unique input form which once populated would yield beneficial data.

Proton pump inhibitors are acid reducing drugs. They are usually taken on an empty stomach to provide maximal benefit to the consumer. Basically, they shut down the little proton pumps in your stomach thereby decreasing stomach acid output. In that way your stomach lining is able to heal more rapidly, and your oesophagus is protected since a low amount of acid in your stomach isn’t able to find its way up to the oesophagus anymore.

The drugs have been released in the late 80’s and brought a revolution in gastro disease treatment. However, around 2014/2015 lot of studies starting to come out showing that these drugs could be harmful if taken for a longer period of time.

I myself had stomach issues at the age of 19 and had been given these drugs to treat my gastritis. Of course, I Googled them and to my surprise found a lot of data. At that time negative studies hadn’t come out yet although there were quite a few people preoccupied with them. I got quickly interested and decided to devote more attention to them.

As already said, studies started coming out swiftly blaming PPIs for sequence of events that they may produce if taken over a longer period of time.

According to the studies PPIs could cause: dementia, kidney disease, cardiovascular disease, stomach polyps, clostridium difficile infection, vitamin deficiency, stomach cancer, even premature death. One gets pretty frightened after hearing all of these elements being associated to them.

Anyway, I decided to get my hands dirty in terms of building a unique software in order to create something beneficial for the gastro disease patient’s community.

The first goal was to collect posts http://ppisforlife.com/#/posts from all around the web and put them into one place.

The posts were collected from various sources, but most of them were retrieved from the following sites: Patient.info, Peoples Pharmacy, Daily Mail, The Telegraph, Reddit, CBS, The Sun, Crohn’s Disease Forum, Chris Kresser, Barrett’s Wessex, The Healing WELL, The New York Times etc.

The main criteria whether the post was chosen or not was the duration of the therapy. If the duration was specified, the post was analysed and stored in the database.

Apart from patients expressing their opinions the doctor opinions were also collected. You’d be amazed how much of a non-consensus exists among them. Some of them claim that PPIs are super safe while other say that they may yield more damage than steroids. Because of that the input form which I’ve created could solve these problems if a good amount of people decides to give out their data on their therapy.

With the data collected, I generated a statistic http://ppisforlife.com/#/statistics page which shows trends in terms of most prevalent conditions, drugs usage, side effects, nutrient deficiency, natural supplements etc.

Likewise, info pages are provided on PPIs. This page should answer most of your questions:  http://ppisforlife.com/#/faq

As mentioned multiple times in the article the form page: http://ppisforlife.com/#/form represents the crucial part to demystify if these drugs pose a threat or not. Those of you who are taking PPIs, please fill the form. By doing that you’ll make a great contribution.

If you have any questions concerning the app feel free to ask via mail: eugen.sunic@gmail.com



Disable browser forward button in JavaScript

I’ve been trying to find some code recently to disable the forward button in the browser. Unfortunately, there has been no success with googling thereby I had to create a custom function to execute after the web-page has finished with content loading.

For those who are uninterested why this whole bunch of code had to be written and how the “button navigation disabling” actually works, just copy and paste the code into your app. The code had been tested in a manner of clicking and navigating back on a custom application, however, I urge you to test it extensively before going to production with it.

There are however 3 things which should be considered:

  • it won’t work on IE<10
  • it wont’ work using a hashlocation strategy (popular in react and angular frameworks)
  • if HTML5 history.replaceState() is used anywhere in your application then the code below might not work because of the replaceState canceling pushState() behaviour in the below code.

function for disabling the forward navigation button:

(function() {
  // function called after the DOM has loaded

function disableForwardButton() {
  var flag, loop = false;
  window.addEventListener('popstate', function(event) {
    if (flag) {
      if (history.state != null && history.state.hasOwnProperty('page')) {
        loop = true;
      } else {
        loop = false;
    } else {
          page: true
    flag = loop ? true : !flag;

  window.onclick = function(event) {
    flag = false;

Code Explanation:

In order to appropriately tackle the problem you first have to understand what is at your disposal and how these tools/commands work inside back navigation event (‘popstate’).

We’ll be using the following code:

  • history.go(-1), history.back() –> navigate backwards
    history.pushState(arg1, arg2, arg3) –> adding an extra entry element to our browser navigation array
  • ‘popstate’ event –> catches back, forward navigation click
    ‘onclick’ event –> catches any click event on the window object (needed to reset variables if the ‘popstate’ event occurred)

First, have in mind that there isn’t a switch off JavaScript code which would disable either the navigation forward button or the backwards button, therefore you have to take another approach which would prevent the app-user to click on the forward button.

The crucial thing to use here is the history.pushState() HTML 5 history API. Basically what it does (once used) is putting your current page at the end of the browser navigation array. In other words, if you execute this code in the ‘popstate’ event it would create another history and push it to the end of the array therefore disallowing the click of the forward button since you are on the last position (last item of the array). By doing this you haven’t disabled it at all you just appended an item to the array. Since you are now located at the end of the array then obviously you cannot go further (click forward).

To illustrate it a little bit more let’s create array states before the implementation of the pushState and after its implementation.

We’ll be using the following presumption of page history [page1, page2, page3]

  1.  let the current page we are on be page3. Once someone clicks the back button the ‘popstate’ event listener catches the event action and moves to page2
  2. Now again, let the current page be page3. With the pushState() function being implemented inside our ‘popstate’ listener the following transformation will occur inside our array [page1, page2, page2]. The page3 has been removed from the history and once landing on page 2 we pushed that exact page once more in the array and from that we’ve got no where else to go, our array doesn’t permit us to navigate forward like it did in the previous example. Because of the “no where going” the forward button in the browser is disabled or better to say inactive.

Once pushState() is implemented in our ‘popstate’ event we can now use the history.go(-1) function which helps us navigate to our previous page. The reason why we need it, is because pushState() will constantly push states (populate our browser page history) like the method name indicates therefore we will once be able to navigate back and after hitting the back button again we’ll be stuck on the current page. In order to evade this scenario we have to trigger a second back button click by using history.go(-1) or history.back(). The history.go(-1) will again trigger an event as we hit the back button and go through our code inside the popstate eventlistener. As you can see, we toggle between the history.go(-1) and pushState() in order to keep our forward button disabled and being able to navigate back.

The last thing which needs clarification is the code below:

if (history.state != null && history.state.hasOwnProperty('page')) {
  loop = true;

Without this peace of code the forward button disabling would still work but you could run to a “never ending” back button navigation. This means that if you navigated back and have appended a vast number of elements inside your browser navigation array like for instance

[page0, page1, page2, page2, page2, page2, page2]

you would have to click the button numerous times in order to navigate to page1. Of-course, no one wants that, but such situation is very plausible and occurs often (the accumulation of pages in the array).

It happens because you might stop back navigating at some point (remember, pushState function executes at every back navigation button click) then click on some url within the webpage and then again navigate back going through page2 all the way to the starting page for example. Let’s say that you create this precise scenario:

[page0, page1, page2, page2, page2, page2, page2]

Having a bunch of same pages in the array and wanting to just jump to the target page which is page0. In this case we need to execute history.go(-1) until we reach the page1 (we cannot magically jump to it, we need to go through each and every element that we’ve created unwantedly) and then stop. this is done by setting the loop variable to true so that we don’t pushState() until we reach page1 where we pushState() again to disable the forward button.

That’s basically it. The HTML5 history API doesn’t allow you to explicitly look at their navigational array because of that we need to implement this dirty code to have our forward button disabled for the entire application.

If you notice a bug or have some uncertainties on how to implement the code, feel free to contact me.

Link to my stackoverflow answer

Blockchain average user pros and cons


  • It is secure (referring to blockchain not wallets which are outside the blockchain network)
  • Once you store your data on the blockchain network, it will be there forever.
  • data cannot be deleted/removed, modified, replaced, tampered.
  • Everyone can see your data (it’s public) but no one knows who’s behind it, which person does this data belong to even if they write their name inside it is hard to prove that this person did it. The only way others can learn the transaction is yours is by you telling others that it’s yours or you interacting with them in ways which let others conclude that they may be yours.
  • Since no one knows who’s behind the data, Privacy is therefore guaranteed on the blockchain
  • You have to have a wallet in order to send any data to the blockchain because you have to pay for it
  • If you access/retrieve already existing data you don’t have to pay anything in crypto money
  • Confidential transfer of assets/state to another person,
  • The blockchain database cannot be hacked
  • No one governs over the blockchain database/storage.
  • It’s much easier and less costly to transfer crypto money from one place to another. It’s faster, less expensive and requires no central authority no matter how big the transaction is, fees are very low as well (Ethereum)
  • Blockchain eliminates third parties when making deals. For example you don’t have to go to some company which would just sign some papers and allow you to do something. Instead, someone can deploy an application on the blockchain which would then automatically solve these issues by giving you or not giving you the permission which would had been given from that company previously. In theory all the bureaucracy could get eliminated and put on the blockchain as an application which will automatically solve these problems.
  • People can earn big money on it because of the price which can go up tremendously. Then convert it to Fiat via coinbase or trading.



  • You have to pay crypto-money in order to store data on the blockchain. If you want to store big amounts of data you’ll have to pay even more money whereas on a centralized system you pay once (most often monthly or yearly) and you get unlimited storage. If you wanted to store data, you’d have to pay for the storage (a song of 4MB would be around 7500$ for May 18th 2018, 1ETH=570$)
  • If you lose the access key for your wallet, you’ll never be able to retrieve your money again. You can’t call a centralized company like you do when you lose your bank card and tell them what happened so they may react quickly in order to block your card and disallow potential thieves to spend your money. There is no customer support for the blockchain
  • You have to use a wallet in order to store data on the blockchain (example: MetaMask) that is cumbersome you can’t just interact with the blockchain without such utility.
  • Because of price volatility users are often discouraged to spend money to store big amounts of data on it because one day this crypto could go up and they would probably be disappointed because of it.
  • If you invest in it you can lose a lot of money  if the price drops down or the blockchain project becomes valueless
  • You can lose your money instantly if someone steals your private key. Once the thief has your private key of your wallet/account and you do not  react quickly in order to transfer your money to another secure account be prepared to say goodbye to your assets/ crypto money.
  • The blockchain is hard to use, it’s not user friendly yet. you have to first buy some crypto with Fiat money ($, eur …) then you would probably transfer it to some wallet since it’s not advisable to keep the money on the same place where you bought (possible hacks may occur), then you have to manage your passwords, plugins…
  • If you are not an IT guy most of the terms won’t be familiar to you, like hashing, miners, proof of work, proof of stake, nonce, hard fork, full node, light node, some protocol names, smart contracts etc. You would have to invest a decent amount of time to comprehend all of the above mentioned. Instead, a centralized system has some nice user interface and you interact with it quickly without worrying about its functionality
  • Governments don’t accept the blockchain regardless of what you’ve read on the news. They don’t offer an exchange service where you could buy dollars, euros using crypto-money. Private companies don’t accept it either. You cannot buy goods, brand new cars, assets with crypto.
  • Scalability is an issue, The problem with the blockchain is that it can only get bigger. Picture it as a huge file which is shared across the network and re evaluated every time a new file comes in. Centralized systems don’t have a problem with that.
  • Which problem can the blockchain solve in contrary to centralized internet systems? Only real world problem I can think of is centralized money movement/transfer, lower fees considering the Ethereum blockchain (Bitcoin has higher fees) relatively fast transaction time compared to centralized system transactions (depends on the blockchain) also legal issues can be avoided which may be good or bad.
  • Applications that are currently impossible to be built on top of the blockchain are: Social networks, data storing services, healthcare systems, traffic systems pretty much everything which would require high amounts of data to be stored.



Decentralization is a great thing in general. However, we’ve seen that people don’t really complain having their private data on some unknown addresses like Facebook, Twitter, Google, etc.. Why would they if it has proven to work well: security, customer support, trust…

The problem isn’t privacy. People will use whatever they can under some condition: It has to be simple, useful, reliable, fast and secure. Blockchain doesn’t meet these conditions apart form security and anonymity while on the blockchain.

Another problem with the blockchain is that you have to explain it to someone. This means that you have to convince other people in using it. Convincing often assumes that something isn’t right in the system. People don’t like that, they want to hear what it is good for in one sentence.

Blockchain can acquire critical masses only if it finds a way to solve a problem which the centralized system is not able to solve. Now the question is here, which problem hasn’t been solved by the centralized system? Nevertheless, we’ll have to wait for quite a long time until the blockchain establishes the new, decentralized Internet.

People often compare the beginnings of the Internet with the blockchain. They argue how the Internet had to take some time to emerge. That’s true because the infrastructure did not exist and was introduced gradually. The blockchain is the Internet but another architecture of it. Now we come again to the first paragraph of the conclusion, why would someone want to use the same thing with another structure….. Why would someone use Minds social network over stable, big, secure, user-supported, with extremely minor issues Facebook, Twitter, Instagram.

Despite all, why do most of people “like” or so to say talk about the blockchain? They want to make big money fast. Literally you’ll see people on Reddit, Quora and other popular discussion communities asking about the short-term and longterm predictions regarding particular cryptocurrencies. They want to know which is the right one to invest in so they could get “rich” quickly.  This is how they start their journey on the blockchain… Unfortunately there only exists a low percentage of people who really care about decentralization and making the blockchain work smoothly, trying to solve problems, in order for it to become powerful one day and open the gates for mass adoption.


Angular 2 Jasmine unit testing (quick overview)


  • describe: optional, describe the entire unit testing class
  • it: must include it when writing isolated unit test
  • async: tell the test framework to wait until the return promise or observable is completed before treating the test as completed. when all async operations are completed the next test (if exists) is able to start executing
  • beforeEach: for creating new instances for another test to start from the beginning
  • TestBed: creates components instance, configure module, simulate module
  • Access field/variable: fixture.componentInstance.some_variable_name OR if already instantiated then component.some_variable_name
  • detectChanges: only triggered when an property change occurs inside a .ts file
  • configureTestingModule: configures a “fake” module
  • toBe vs toEqual: toBe object(general) equality vs deep equality
  • fixture.whenStable().then(() => {}); executes after all async operations are executed/finished
  • tick() simulates the passage of time until all async operations above are finished. Must go with fakeAsync keyword, otherwise error will appear
  • fixture.whenStable() vs tick();
    They both do the same. tick() is more prudent to use because you have to give it (in the header of the test) a fakeAsync which means that everything is called synchronously inside the test. The code after the tick() method indicates that all code above has executed (async operations above) and that you can now proceed with testing the result of these above async operations.
    Fixture.whenStable() however can give a false positive if async() is omitted in the header of the test. Therefore the test will complete before fixture.whenStable executions.
  • A Spy is a feature of Jasmine which lets you take an existing class, function, object and mock it in such a way that you can control what gets returned from functions.

Configuring Test Module



    let fixture= TestBed.createComponent(AppComponent);
    let element1= fixture.debugElement.query(By.css(".heading")).nativeElement.textContent; //must include the point prefix (.)


  it ("test input innerHTML example", async()=>{
     let fixture= TestBed.createComponent(AppComponent);
     let element2= fixture.debugElement.nativeElement.querySelector(".heading");

input HTML tag

    it ("test input input-value attribute example", async()=>{
     let fixture= TestBed.createComponent(AppComponent);
     let element1= fixture.debugElement.nativeElement.querySelector("input");

CSS style

    it ("test input input-value attribute example", async()=>{
     let fixture= TestBed.createComponent(AppComponent);
     let element1= fixture.debugElement.nativeElement.querySelector("input");
    it ("test css style", async()=>{
     let fixture= TestBed.createComponent(AppComponent);
     let element1= fixture.debugElement.nativeElement.querySelector("h1");
     expect(element1.style.backgroundColor).toBe("blue"); // style attribute is the key for testing css

Class property testing

import { TestBed, async } from '@angular/core/testing';
import { AppComponent } from './app.component';

beforeEach(() => {
           declarations: [AppComponent]

it('check title class property', async()=> {
  let fixture= TestBed.createComponent(AppComponent);

Service testing

import { TestBed, async, inject } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { AppModule } from './app.module';
import { AppComponent } from './app.component'
import { MyServiceService } from './my-service.service'

beforeEach(() => {
let userServiceStub = {
isLoggedIn: true,
user: { name: 'Test User'}

//simulate module
declarations: [ AppComponent],
providers: [ {provide: MyServiceService, useValue: userServiceStub } ]

it('should test service object property value', inject([MyServiceService], (userService) => {
let fixture=TestBed.createComponent(AppComponent);


Pipe testing

import { TestBed, async } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { AppModule } from './app.module';
import { AppComponent } from './app.component'
import { TryPipe} from './try.pipe'

it ("should check pipe content", async()=>{
    let piping= new TryPipe();  //create an instance of the pipe
    expect(piping.transform("")).toEqual("something"); //transform returns something initially

Directive testing

import { TestBed, async } from '@angular/core/testing';
import { AppComponent } from './app.component';
import { By } from '@angular/platform-browser';
import { FirstOneDirective } from './first-one.directive'
import { NO_ERRORS_SCHEMA }  from '@angular/core';

beforeEach(() => {
    declarations: [ AppComponent, FirstOneDirective ],
    schemas:      [ NO_ERRORS_SCHEMA ]

it('should have skyblue css background, set from the directive', async()=> {
 //checking the code from the directive implementation
  const fixture=TestBed.createComponent(AppComponent);
  const de = fixture.debugElement.query(By.css('.nesto'));
  const bgColor = de.nativeElement.style.backgroundColor;

([ngModel]) testing

  it('should pass twice, passes but because of two way data binding ngModel', async(() => {
    const fixture1 = TestBed.createComponent(ChangeRestApiComponent);
     fixture1.whenStable().then(() => {
       let input_val = fixture1.debugElement.query(By.css('#first')).nativeElement;
       input_val.value = 'localhost';

       input_val.dispatchEvent(new Event('input'));


Check something to be false (not to contain a substring)

  it('should not contain full url paths, protocol e.g. http://', () => {
    component.array.forEach((item) => {
        expect(item.url.indexOf('http') === 1).toBe(false);

Checking html CHECKBOX element “checked” attribute

  it('check if checkbox checked attribute changed from default false to true', async() => {
    const input = fixture.debugElement.query(By.css('.className')).nativeElement;
    component.testing = true;

Check value after BUTTON onClick event executes

it('check if on-button (click) event changes the value in the HTML', async() => {
     const div = fixture.debugElement.query(By.css('.clicking')).nativeElement;


Check new INPUT value after change event executes

  it('change input value and check if change occured', async() => {
   const input = fixture.debugElement.query(By.css('.inputlast')).nativeElement;
   component.changeMe = 'changed';

EventHandler(‘click’) testing


Routing testing


Local storage testing


Državna matura riješeni zadaci- matematika A (viša razina), LJETO 2017. god. (postupak)

Napomena: ukoliko ne znate riješiti neki zadatak iz matematike otiđite na: https://math.stackexchange.com i dobiti ćete rješenje u roku od 15 minuta. Naravno, prije toga morate pokazati pokušaj u rješavanju zadataka. Jedino što morate znati je engl.jezik i po mogućnosti (nije obavezno) malo Latex-a. Latex je jednostavan za naučiti i uči se brzo.


U prilogu se nalaze riješeni zadaci (Matematika A razina) sa državne mature, ljeto 2017. god.
U prvom prilogu se nalazi prvih 15 zadataka dok su u drugom ostali zadaci.

Ukoliko imate kakvih nejasnoća pošaljite mail na eugen.sunic@live.com

Link na maturu, Matematika A razina 2017, ljeto: https://www.ncvvo.hr/drzavna-matura-2016-2017-ljetni-rok/


In the attachment below you can find solved problems from the 2017 (summer) math exam, level A.
Students across the country must pass this exam in order to inscribe them-self to a desired faculty.

If you have any question, reffer to eugen.sunic@live.com

Riješeni zadaci s postupkom, 1.dio/solved problems with steps, first part:
MAT A, viša razina, ljeto 2017.god. 1.dio
MAT A, viša razina, ljeto 2017.god. 1.dio

Riješeni zadaci s postupkom, 2.dio/solved problems with steps, second part:

MAT A, viša razina, ljeto 2017.god. 2.dio
MAT A, viša razina, ljeto 2017.god. 2.dio