Thursday, 14 May 2015
Monday, 11 May 2015
Cool Computer Tricks
- Sometimes we have some process like copying/downloading running on our system and we have to leave for some work or sleep. We can use the below command and our system will shutdown automatically after the specified time. shutdown -s -t <time in seconds> eg: shutdown -s -t 180
- We have to open command prompt at a specific path and we dont want to follow the usual process in cmd by going into individual folder. So what we can do it we can go to the specified folder.
Just press shift key and right click on the folder
Just click on the "Open command window here"
- Using Browser as Notepad:Open your browser and Type in the address bar "data:text/html, <html contenteditable>" and Go. Using this, we can use browser tab as a Notepad.
Labels:
Command Prompt,
Computer,
Hacks,
Shortcuts,
Tricks
Sunday, 22 February 2015
Object Oriented Software(Programming) Explained by Steve Jobs
Below is one of the simplest explaination of OOPS i have read till now. Steve jobs explained it while giving interview to Rolling Stone's Jeff Goodel in 1994.
Here is an excerpt.
Jeff Goodel: Would you explain, in simple terms, exactly what object-oriented software is?
Steve Jobs: Objects are like people. They're living, breathing things that have knowledge inside them about how to do things and have memory inside them so they can remember things. And rather than interacting with them at a very low level, you interact with them at a very high level of abstraction, like we're doing right here.
Here's an example: If I'm your laundry object, you can give me your dirty clothes and send me a message that says, "Can you get my clothes laundered, please." I happen to know where the best laundry place in San Francisco is. And I speak English, and I have dollars in my pockets. So I go out and hail a taxicab and tell the driver to take me to this place in San Francisco. I go get your clothes laundered, I jump back in the cab, I get back here. I give you your clean clothes and say, "Here are your clean clothes."
You have no idea how I did that. You have no knowledge of the laundry place. Maybe you speak French, and you can't even hail a taxi. You can't pay for one, you don't have dollars in your pocket. Yet I knew how to do all of that. And you didn't have to know any of it. All that complexity was hidden inside of me, and we were able to interact at a very high level of abstraction. That's what objects are. They encapsulate complexity, and the interfaces to that complexity are high level.
Read More: www.rollingstone.com/culture/news/steve-jobs-in-1994-the-rolling-stone-interview-20110117
Here is an excerpt.
Jeff Goodel: Would you explain, in simple terms, exactly what object-oriented software is?
Steve Jobs: Objects are like people. They're living, breathing things that have knowledge inside them about how to do things and have memory inside them so they can remember things. And rather than interacting with them at a very low level, you interact with them at a very high level of abstraction, like we're doing right here.
Here's an example: If I'm your laundry object, you can give me your dirty clothes and send me a message that says, "Can you get my clothes laundered, please." I happen to know where the best laundry place in San Francisco is. And I speak English, and I have dollars in my pockets. So I go out and hail a taxicab and tell the driver to take me to this place in San Francisco. I go get your clothes laundered, I jump back in the cab, I get back here. I give you your clean clothes and say, "Here are your clean clothes."
You have no idea how I did that. You have no knowledge of the laundry place. Maybe you speak French, and you can't even hail a taxi. You can't pay for one, you don't have dollars in your pocket. Yet I knew how to do all of that. And you didn't have to know any of it. All that complexity was hidden inside of me, and we were able to interact at a very high level of abstraction. That's what objects are. They encapsulate complexity, and the interfaces to that complexity are high level.
Read More: www.rollingstone.com/culture/news/steve-jobs-in-1994-the-rolling-stone-interview-20110117
Monday, 16 February 2015
Mathematical Formulas for Programmer
Below are some of the formulas that can be useful while doing competitive programming.
Please comment if you find anything incorrect.
- 1∗1!+2∗2!+...+x∗x! = (x+1)!−1
- (A+B)%C = (A%C + B%C )%C.
- (A* B)%C = ((A%C) * (B%C))%C
- LCM(a, b) = (a * b) / GCD(a, b)
Please comment if you find anything incorrect.
Sunday, 15 February 2015
Maximum Frequency/Repeated element in a Vector/Array
Below is one of many algorithm to find maximum frequency of element in a Vector.
Algorithm Used:
#include<iostream>
#include <vector>
#include <map>
using namespace std;
int MaxFrequency(vector<int> v,int& freq)
{
int maxElement=0;
map<int,int> m;
for(int i=0;i<v.size();i++)
{
m[v[i]]= ++m[v[i]];
}
for(map<int,int>::iterator i=m.begin();i!=m.end();i++)
{
if((*i).second>freq)
{
freq= (*i).second;
maxElement = (*i).first;
}
}
return maxElement;
}
int main()
{
int x,n,max=0,f=0;
cin>>n;
vector<int> a;
for(int i=0;i<n;i++)
{
cin>>x;
a.push_back(x);
}
cout<<"Max Repeating element is: " <<MaxFrequency(a,f)<<" with Frequency: ";
cout<<f;
return 0;
}
Please comment if you find anything incorrect.
Algorithm Used:
- Take a map <int,int> where its key is vector element and value is element count.
- Iterate over the vector thereby incrementing element count in a map (map value by default is assigned to zero)
- Iterate over the map by checking its value with maximum frequency till now.
- Return the maximum repeated element and also get its frequency.
#include<iostream>
#include <vector>
#include <map>
using namespace std;
int MaxFrequency(vector<int> v,int& freq)
{
int maxElement=0;
map<int,int> m;
for(int i=0;i<v.size();i++)
{
m[v[i]]= ++m[v[i]];
}
for(map<int,int>::iterator i=m.begin();i!=m.end();i++)
{
if((*i).second>freq)
{
freq= (*i).second;
maxElement = (*i).first;
}
}
return maxElement;
}
int main()
{
int x,n,max=0,f=0;
cin>>n;
vector<int> a;
for(int i=0;i<n;i++)
{
cin>>x;
a.push_back(x);
}
cout<<"Max Repeating element is: " <<MaxFrequency(a,f)<<" with Frequency: ";
cout<<f;
return 0;
}
Please comment if you find anything incorrect.
Saturday, 31 January 2015
SetUp Google Mock (Google Test ) in Ubuntu 14.04
Google C++ Mocking Framework (or Google Mock for short) is a library for writing and using C++ mock classes. Google Mock:
In this post i will be covering the procedure to install GMock in Ubuntu. Below are the steps:
- lets you create mock classes trivially using simple macros,
- supports a rich set of matchers and actions,
- handles unordered, partially ordered, or completely ordered expectations,
- is extensible by users, and
- works on Linux, Mac OS X, Windows, Windows Mobile, minGW, and Symbian.
In this post i will be covering the procedure to install GMock in Ubuntu. Below are the steps:
- Download GMock from https://code.google.com/p/googlemock/downloads/list and extract it to a folder (Lets say $(GMOCK_DIR))
- GMock already has a copy of GTest inside it , so there is no need to get another copy of GTest.
- If cmake is not installed , install cmake using command sudo apt-get install cmake
- Go to GMock Directory using command cd $(GMOCK_DIR)
- Run command cmake CMakeLists.txt and then make
- This will create a library libgmock.a in your current directory.
- Now your GMock and GTest setup is ready.
Sunday, 7 December 2014
C++ Unit Testing Frameworks Comparison
Labels:
BoostTest,
C++,
Comparison,
CPPUNIT,
Difference,
Framework,
GoogleTest,
Unit Testing
Subscribe to:
Posts (Atom)
