What are gradients in CSS3?

What is linear gradient in CSS?

  • Gradient allows for smooth transitions between colors, which helps to reduce download speed and lowers bandwidth requirements.
  • It is applicable on the background property.
  • There are two types of gradient in CSS3: Linear and radial
  • For linear gradient you must specify 2 colors and direction in which the color. For ex: background: linear-gradient(top, red, blue); //This will make the color change from red to blue starting from top to bottom.
  • Different directions can be: top, left, right, bottom
  • Top to bottom is default value for the linear gradient. In that case the definition looks like: linear-gradient(red, blue). If direction is omitted, by default top direction is assumed.
  • For different browsers linear gradient property is referred as:
    • -webkit-linear gradient: For Safari
    • -0-linear gradient: For Opera
    • -mox-linear gradient: For: For Firefox
    • linear gradient: For standard syntax
  • To specify gradient direction as diagonal 2 endpoints are supposed to be mentioned.
  • For ex: linear-gradient(to bottom right, red, black) //It will move from bottom right starting with red color and gradually change it to black
  • You can specify angles in the linear gradient as follows: linear-gradient(180deg, red, blue)
  • You can specify multiple colors too like this: linear-gradient(red, green, blue, black)
  • Gradient can be made transparent to generate a fading effect. For transparency, rgba function with 0 to 1 can be added.
    • 0 indicates: full transparency
    • 1 indicates: full color and zero transparency.
    • For ex:
      • linear-gradient(rgba(255,0,0,0), rgba(255,2,3,1))



What is radial gradient in CSS?

  • Linear gradient allows you to transform the color from the sides and corners of a shape. However, radial gradient allows you to transform color from center.
  • It is similar to linear gradient wherein you have to specify at least 2 colors. 
    • For ex: radial-gradient(red, blue)
  • You can specify different width for the color stops like this: radial-gradient(red 5%, blue 95%) //Red will only occupy 5% and blue will occupy 95%
  • If you have to repeat the result of a radial gradient across an element then you should use, repeating-radial-gradient. 
    • For ex: repeating-radial-gradient(red, blue 40%, green 35%)

Explain border radius property of CSS3


  • border-radius property of Css3 allows to give a web page element the looks of rounded corners.
  • You can specify it like this:
    • border-radius: 10px
  • You can specify different radius value for each corner of the element. You can specify 4 values for each corner, 3 values, 2 values, and 1 value for all corner:
    • If 4 values are specified then 1st, 2nd, 3rd, 4th value will apply to top-left, top-right, bottom-right, bottom-left corner respectively.
      • For ex: border-radius: 40px, 30px, 20px, 10px; top-left = 40px top-right = 30px bottom-right= 20 px bottom-left = 10px
    • If 3 values are specified then 1st, 2nd, 3rd value will apply to top-left, top-right, and (bottom-left & bottom-right) respectively. For ex: border-radius: 40px, 30px, 20px;
      • In above ex: top-left = 40px top-right = 30px bottom-left and bottom-right = 20 px
    • If 2 values are specified then 1st and 2nd value will apply to following 2 sets respectively. For ex:
      • border-radius: 40px, 30px;
      • In above ex: top-left and top-right= 40px bottom-left and bottom-right = 30px
    • If only value is specified then all corners will have the same value: 
      • For ex: border-radius: 40px;
  • You can create elliptical corners too: 
    • For ex: border-radius: 40px/20px;
  • If you have to specify only one border than you can specify it as follows
    • border-top-left-radius
    • border-top-right-radius
    • border-bottom-left-radius
    • border-bottom-right-radius

Special Features of C Language

Enums
enum shape {circle=10, square, rectangle};

shape a = circle;
shape b = square;
shape c = rectangle;

enum gender {female, male};
The same functionality can be achieved using macros. However, macros have global scope. Enums could have local(Inside a function) or global(if outside of all functions) scope.

Typedef:
struct node
{
 int data;
 node *link;
};

typedef node N;

N *root = new N;
root->data = 10;
root->link = NULL;

cout << root->data << "\t" << root->link;

Bit Fields:
struct employee
{
 unsigned gender: 1; //The colon tells the compiler that we are talking about the bit field
 unsigned id: 4;
 unsigned status: 3;
 unsigned efficient: 2;
};

enum gender {female, mae};
enum id {One,Two};
enum status {Single, Married, Committed};
enum efficient {Yes, No};

int main()
{
 gender gg = female;
 id gi = One;
 status gs = Committed;
 efficient ge = Yes;

 employee e;
 e.gender = gg;
 e.id = gi;
 e.status = gs;
 e.efficient = ge;

 cout << e.gender << endl;
 cout << e.id << endl;
 cout << e.status << endl;
 cout << e.efficient << endl;

 getch();
 return 0;
}

Function Pointers:
void display()
{
 cout << "Display\n";
}

int main()
{ 
 void (*fptr)(); //Pointer to a function
 fptr = display; //Pointer now contains the address of the function
 cout << "Address of the function: " << fptr << endl; //Outputing the address of the function
 (*fptr)(); //Invoking the function; //Invoking the function

 getch();
 return 0;
}
Useful for: Dynamically binding a function to the pointer. Dynamically invoking the function too.

Function returning pointers:
int* display() //This function is returning a pointer.
{
 cout << "Display\n";
 static int i = 30;
 return(&i); //It will actually be returning the address to an integer
}

int main()
{ 
 int *p;
 p = display();//The address is populated in a pointer variable
 cout << "Address : " << p << "\tValue: " << *p;

 getch();
 return 0;
}

Union:
typedef union
{
 int i;
 char c[4];
}test; //This union is not of 8 bytes(4 for int and 4 for chars). It is of 4 bytes only.

int main()
{ 
 test t;
 t.c[0] = 'A'; //The value assigned to the characters will get assigned to the integer i accordingly
 t.c[1] = 'B'; //As the 4 bytes of the characters are shared by the int too. 
 t.c[2] = 'C';
 t.c[3] = 'D'; 
 
 //t.i; // We can't assign value to both the data variables at the same time.
 //This is useful in hardware when sometimes we have to read only 1 value or all the 4 values
 cout << t.c[0] << "\t" << t.c[1] << "\t" << t.c[2] << "\t" << t.c[3] << endl;
 cout << t.i << endl;

 getch();
 return 0;
}

Finding absolute value

This question can be asked on a phone interview or during a job fair. It gives a quick idea of problem solving skills of the candidate. To find out the absolute of any number, you have to know its concept.

Concept is 'If a number's value is < 0 then its positive equivalent is returned or else the number is returned as it.
For value=0, the number is returned as is' that means 0 is return.

Examples:

  1. If n = -10 then its absolute value will be 10. 
  2. If n = 10 then its absolute value will be 10. 
  3. If n = 0 then its absolute value will be 0. Following implementation find a number's absolute value.

 
void int findAbsoluteValue(int n)
{
 if(n < 0)
  return n*-1;
 else 
  return n;
}


You might also like:
Find White Spaces in Character Array
Find a character in the String
Number is prime or not
Notes on Sorting and Searching Algorithms
Common String Functions
Reverse a String
Product of all array location expect its own
Find a cycle in the Linked List
Find a binomial co-efficient
Remove duplicates from the array
Telephonic phone technical interview questions - Part 2
Counting sort algorithm
B-Tree

Notes on Sorting and searching algorithms

This is a cheat sheet of sorting algorithms concept. It helps to answer the questions on phone interviews. This sheet explains the key difference between different sorting algos.

Sorting


  • If the no. of elements are small then we can use quadratic algo like: insertion sort
  • If there are more then 100 elements use: Heapsort, merge sort, quicksort
  • For items over: 5,000,000 we can use external memory sorting algorithms.
  • Stable algos maintains ordering in case of duplicates
  • Nlogn algos are not stable
  • If the data is partially sorted then insertion sort is better
  • If the data is uniformly or randomly distributed then bucket or distribution sort makes sense.
  • If the keys are long strings then it will make sense to use prefix for the intial sort and then use entire key for sorting. Or use Radix sort
  • If the range of elements is know and it is small. Then we can initialize an n-element bit-vector. Turn on the element that is present. Then scan from L to R and report the true bits.
  • For sorting requiring using the disk access we can use external sort or
    • Load the data in a B-Tree and do in-order traversal
    • Multi-way merge sort
  • Quicksort optimizations:
    • Randomize the permutations
    • b. Median of first, last, and middle element as a the pivot
    • c. Smaller subsets can use insertion sort. Stop the recursion at the n = 20
    • d. We use process the smaller partitions before the larger one. This way run-time memory needed will be less. Successive stored calls are at most half as large as the previous one.


Searching


  • We can use self organizing list, where the most recently accessed elements moves to the front.
  • The self organizing list can be used when we have multiple access.


You might also like:
Find White Spaces in Character Array
Find a character in the String
Number is prime or not
Finding Absolute Value
Notes on Sorting and Searching Algorithms
Common String Functions
Reverse a String
Product of all array location expect its own
Find a cycle in the Linked List
Find a binomial co-efficient
Remove duplicates from the array
Telephonic phone technical interview questions - Part 2
Counting sort algorithm
B-Tree

C++ Basic Concepts

What does a C++ compiler gets from a compiler?

  1. Default assignment operator
  2. Default copy constructor
  3. Default constructor
  4. Default destructor
  5. Size of operator
  6. Assignment Operator2

Virtual Function:
It is a special function that resolves to the most derived version of the function with the same signature.

Example:
Base *p;
Derived d;
p = &d; 
In the above example, if the virtual function is defined in derived class d then it will be called otherwise, base class function will be called. 
 
class shape {
int x;
int y;


public int findArea(int x, int y) {
   return x*y;
 }
}

class square extends shape {
   int x;
   
   public int findArea(int x) {
       return x*x;
}

class rectangle extends shape {
}

square s = new square();
int x = 10;
int y = 20;
s.findArea(x); //Its own virtual function is called. 
rectangle r = new rectangle();
r.findArea(x,y); //Base Classes virtual function will be called. 
}
What does new keyword do?
It create another instance(new object) of the class. It will allocate space in the memory(heap) for that object;
object o = new object(); 

NoSQL

This one is reviewed but I need to delete its copy from hubpages or somewhere NoSQL Data models: key-value  Aggregate model.  key or i...