Monthly Archives: August 2013

Big Data, Data Mining and Machine Learning: Under the Hood

Big Data, Data Mining and Machine Learning: Under the Hood.

Advertisements

Data Compression: What it is and how it works

Data Compression: What it is and how it works.

Euclid’s algorithm

Delete all duplicate elements from a singly linked list with O(n) time complexity and O(1) space.

Delete all duplicate elements from a singly linked list with O(n) time complexity and O(1) space..

Double Buffering technique in MFC for Flicker Free drawing

Visual Programming

Flickering is caused in a window,  by painting,  in two steps.

(1) Erasing the window contents in OnEraseBkgnd.  By default MFC does this.

(2) Painting new contents in OnPaint or OnDraw.

Double buffering eliminates this two-step process by overriding OnEraseBkgnd and including the erase in OnPaint/OnDraw to an off-screen image.

1. Overriding the OnEraseBkgnd function:

  • Add a message handler for WM_ERASEBKGND in your Windows application.
  • Once added it looks like the below one:
  • BOOL CExampleView::OnEraseBkgnd(CDC* pDC) 
    {
          // TODO: Add your message handler code here and/or call default
          return CView::OnEraseBkgnd(pDC);
    }
    
    Now change the return value to any non-zero value and comment the default proced-ure.
    BOOL CExampleView::OnEraseBkgnd(CDC* pDC) 
    {
          return TRUE;
    }

2. Now In the OnPaint/OnDraw do the following steps:

1.  Create a Memory DC for the View DC as below:

               CreateCompatibleDC(pDC);

2.   Create the bitmap in memory…

View original post 78 more words

Break…?

This is a replica of the code that caused a major disruption of AT&T phone service throughout the U.S. AT&T’s network was in large part unusable for about nine hours starting on the afternoon of January 15, 1990. Telephone exchanges are all computer systems these days, and this code was running on a model 4ESS Central Office Switching System.
It demonstrates that it is too easy in C to overlook exactly which control constructs are affected by a “break” statement.
network code()
{
switch (line) {
case THING1:
doit1();
break;
case THING2:
if (x == STUFF) {
do_first_stuff();
if (y == OTHER_STUFF)
break;
do_later_stuff();
} /* coder meant to break to here… */
initialize_modes_pointer();
break;
default:
processing();
} /* …but actually broke to here! */
use_modes_pointer();/* leaving the modes_pointer
uninitialized */
}
This is a simplified version of the code, but the bug was real enough. The programmer wanted to break out of the “if” statement, forgetting that “break” actually gets you out of the nearest enclosing iteration or switch statement. Here, it broke out of the switch, and executed the call to use_modes_pointer() —but the necessary initialization had not been done, causing a failure further on.
This code eventually caused the first major network problem in AT&T’s 114-year history. The saga is described in greater detail on page 11 of the January 22, 1990 issue of Telephony magazine. The supposedly fail-safe design of the network signaling system
actually spread the fault in a chain reaction, bringing down the entire long distance network.
And it all rested on a C switch statement.

Const Keyword in C and C++ (A few interesting points)

Consider following code snippet. Does it even compile?

foo (const char **conChar) {}

main (int argc, char **argv)

{

foo (argv);

}

This code will not compile with an error message of incompatible type. This is true in both c and c++. (don’t forget to add return type to foo in c++)

Now consider below snippet,

char * cp ;

const char * ccp;

ccp = cp;

  • The left operand is a pointer to “char qualified by const”.
  • The right operand is a pointer to “char” unqualified.
  • The type char is a compatible type with char, and the type pointed to by the left operand has all the qualifiers of the type pointed to by the right operand (none), plus one of its own (const).

(Note that the assignment cannot be made the other way around. Try it if you don’t believe me.

cp = ccp; /* results in a compilation warning */)

here apparently we are doing the same thing while assigning a non const qualified pointer to to a const qualified pointer but it run without an error for both c and c++.

So why the first code is not compiling and second one does?

const char ** denotes a pointer to an unqualified type. Its type is a pointer to a pointer to a qualified type.

Since the types char ** and const char ** are both pointers to unqualified types that are not the same type, they are not compatible types. Therefore, a call with an argument of type char ** corresponding to a parameter of type const char ** is not allowed.

Now what will happen, if I don’t use * or **….?

Consider below code,

int cp ;

const int ccp;

ccp = cp;

You will have compile error in both c and c++ compilers… as you cannot assign a new value to a variable declared const…

Is it really so?

Consider following C code,

int cp = 12;

const int ccp =  10;

int * alter;

alter = &ccp;

*alter = cp;

printf(“value is %d”, ccp);

We can always take address of a const variable in C and can assign it to another pointer variable, which is not a constant pointer. Now we have the access of memory location of the constant variable and can change the value using our pointer.

This is not true in C++ as it prohibits, any kind of assignment to a constant variable.

“Genetics is complicated”

franzcalvo

“Genetics is complicated”
Introduction to psychology.
Lesson 03. Biology of Behavior.
August 5, 2013
San Jose State University
https://www.udacity.com/course/viewer#!/c-ps001/l-207152500/m-206819111

related:

View original post