Professional Documents
Culture Documents
Answer For Questions
Answer For Questions
Answer For Questions
Voting
Each voter can vote in zero or more referenda. Each referendum has one or more questions, and
each question is a yes/no vote. Write the simplest normalized schema to describe this in generic
SQL statements or as an entity-relationship diagram. Point out where the indexes would be if
you want to quickly know the results of a given referendum question, but you never expect to
query a single voter's voting record. In what way does the nature of the application affect your
design judgment about privacy, and what effect would that have on normalization
considerations?
Answer:
Answer:
First we have to move to the coolapp repo, and write the following command:
Then change the commit message of the last commit, means “M”, by using the following
command:
3. Service Container
Consider the following Laravel controller:
In the above code the MyController needs to retrieve provider from a data source. So we will
inject a service that is able to retrieve provider. In this context, our MyContentProvider most likely
uses Eloquent (an object-relational mapper (ORM) that makes it enjoyable to interact with the
database) to retrieve provider information from the database. However, since the repository is
injected, we are able to easily swap it out with another implementation.
4. We’re All Scratching Our Heads About This One
New code was released to multi-tier production environment and now the site is SO slow. But it
worked great on the single-server staging environment, which has only half the CPU and half
the RAM of the production servers!
Obviously the person who wrote this isn't a Laravel programmer. How would a Laravel
programmer have written the code?
Answer:
This code calculates the ids of all comments and put it in array
This code loops over the array and finds the post comment one by one
It makes the process slow in multi-tier production environment because client and database are
in different location. The client makes request to the server and the server executes the above
code and fetch data from database. While in staging environment, client and server are in single
(case-insensitive), and list them all in order from most-recently created to least-recently created.
Answer:
$: find /tmp –type f –iname “*foobar*” –print
6. CSS
Usage of the "!important" CSS declaration is often frowned upon by front-end developers. What does the
"!important" CSS declaration do? Why do front-end developers suggest using it with caution? What are
some cases in which it makes sense to use it?
Answer:
The ‘!important’ role in CSS is used to override all previous styling rules for that specific property on that
element.
For example:
<html>
<head>
<style>
#myId {
Background-color: yellow;
}
.myClass {
Background-color: blue;
}
P {
Background-color: red !important;
}
</style>
</head>
<body>
<p>Inside paragraph</p>
<p class="myClass">Inside paragraph and myClass</p>
<p id="myId”>Inside paragraph and myId</p>
</body>
</html>
In this example all the three paragraph will get red background color.
7. JavaScript
Take a look at the following:
function *foo(x) {
while (x < 4) {
x += yield x;
}
return x;
}
var bar = foo(3);
console.log( bar.next(1) );
console.log( bar.next(1) );
console.log( bar.next(1) );
What is the output of this code snippet, and why does it behave in the way it does?
Answer:
Output:
Yield: this keyword is used to pause and resume the generator function.
The answer we get when we call the function ‘foo’ for the first time is
{value: 3, done: false}, because we initialize our x value to 3 and the yield
keyword pauses the function, so we get value: 3 and the loop iteration is not
completed so we are not done yet, so we get done: false.
The answer we get when we call the function ‘foo’ for the second time
is {value: 4, done: true], because the next function asks to increase
the value of x by one, so we get value: 4 and the loop iteration is
completed, so we get done: true, now we are done in the loop.
The answer we get when we call the function ‘foo’ for the third time
is {value: undefined, done: true}, because the loop is done so we get
undefined value.