Tuesday, December 30, 2008
Sunday, December 28, 2008
Container Summary Complexity from StrousStroup
Vector
[] - const
List Operations - O(n)+
Iterators - Random
List
List operation - const
Front operations - const
Back operations - const
Iterators - Bi
Dequeue
[] - const
List operations - O(n)
Front operations - const
Back operations - const
Iterators - Ran
List operations include
- Insert
- erase
- clear
[] - const
List Operations - O(n)+
Iterators - Random
List
List operation - const
Front operations - const
Back operations - const
Iterators - Bi
Dequeue
[] - const
List operations - O(n)
Front operations - const
Back operations - const
Iterators - Ran
List operations include
- Insert
- erase
- clear
Saturday, December 27, 2008
StrousStroup Container Design : Review
Notes from Container Design Chapter in StrousStroup
- What is a container?
A Container is an object that holds other objects
- What is an iterator?
Iterator is a means of traversing objects in the container (Used to navigate containers)
- Important member of a Container for iterator
iterator begin() //points to the first element
const_iterator begin() const
iterator end() //points to one-past-last element
const_iterator end() const
reverse_iterator rbegin()
const_reverse_iterator ebegin() const;
reverse_iterator end()
const_reverse_iterator rend() const;
- Element access in a vector
reference operator[] (size_type n); //unchecked access
reference at (size_type n); //checked access
- Passing vectors
f1(vector &)
f2(const vector &)
vector v(1000);
f1(v) //pass reference
- reserve in vector allocates space in advance
- capacity() gives the current numbers of reserved memory slots
- size() gives the current number of elements
- Pointer cannot address a unit of memory smaller than a byte
- Link
Vector Code
- What is a container?
A Container is an object that holds other objects
- What is an iterator?
Iterator is a means of traversing objects in the container (Used to navigate containers)
- Important member of a Container for iterator
iterator begin() //points to the first element
const_iterator begin() const
iterator end() //points to one-past-last element
const_iterator end() const
reverse_iterator rbegin()
const_reverse_iterator ebegin() const;
reverse_iterator end()
const_reverse_iterator rend() const;
- Element access in a vector
reference operator[] (size_type n); //unchecked access
reference at (size_type n); //checked access
- Passing vectors
f1(vector
f2(const vector
vector
f1(v) //pass reference
- reserve in vector allocates space in advance
- capacity() gives the current numbers of reserved memory slots
- size() gives the current number of elements
- Pointer cannot address a unit of memory smaller than a byte
- Link
Vector Code
Thursday, December 25, 2008
Wednesday, December 24, 2008
C++ Abstract Base Classes
#include "string"
#include "sstream"
using namespace std;
class AbstractStatic {
public:
static std::string constructKey(int a, int b) {
std::ostringstream ostr;
ostr «« a «« ":" «« b «« endl;
return ostr.str();
}
virtual std::string makekey(int a, int b) = 0;
virtual ~AbstractStatic();
};
class AbstractConcrete: public AbstractStatic
{
public:
std::string makeKey(int a, int b) {
std::ostringstream ostr;
ostr «« a «« "+" «« b «« endl;
return ostr.str();
}
};
void foo(AbstractStatic* a) {
cout «« "In function foo" «« endl;
}
int main(int argc, char* argv[]) {
AbstractStatic* as;
AbstractStatic as; //this is an erro and foo(as) is also an error
string a = AbstractConcrete::constructKey(1,2);
foo(as);
cout «« a «« endl;
return 0;
}
#include "sstream"
using namespace std;
class AbstractStatic {
public:
static std::string constructKey(int a, int b) {
std::ostringstream ostr;
ostr «« a «« ":" «« b «« endl;
return ostr.str();
}
virtual std::string makekey(int a, int b) = 0;
virtual ~AbstractStatic();
};
class AbstractConcrete: public AbstractStatic
{
public:
std::string makeKey(int a, int b) {
std::ostringstream ostr;
ostr «« a «« "+" «« b «« endl;
return ostr.str();
}
};
void foo(AbstractStatic* a) {
cout «« "In function foo" «« endl;
}
int main(int argc, char* argv[]) {
AbstractStatic* as;
AbstractStatic as; //this is an erro and foo(as) is also an error
string a = AbstractConcrete::constructKey(1,2);
foo(as);
cout «« a «« endl;
return 0;
}
Saturday, December 20, 2008
STL MAP
From deez.info
"
Let’s say you have two STL std::maps with identical types, and you want to copy all the elements from one to the other. The easiest way to do this is to use map::insert():
typedef std::map map_t;
map_t map1;
map_t map2;
// Copy all elements from map1 to map2
map2.insert(map1.begin(), map1.end());
Alternatively, you could use the STL std::copy algorithm:
// Copy all elements from map1 to map2.
std::copy(map1.begin(), map1.end(), std::inserter(map2, map2.begin()));
Both methods’ performance should be an amortized O(n) because they insert records in sorted order and use the hinting form of map::insert.
Note that because both methods ultimately call map::insert they will not overwrite a preexisting key’s associated value. In other words, if map1 has the value V1 associated with key K and map2 the value V2 associated with the same key K, V2 will remain in map2 after the copy operation.
Let’s say you want to perform the copy but have map1’s values overwrite map2’s for identical keys. The first way to solve this problem that entered my mind was to write my own OutputIterator which performs an overwriting assignment and pass it to std::copy. However, there’s a far simpler approach. You can copy map2’s values into map1, relying on the fact that map2’s values won’t overwrite map1’s, and then swap the results:
map1.insert(map2.begin(), map2.end());
map2.swap(map1);
Thanks, Sam, for helping me figure all this out.
"
"
Let’s say you have two STL std::maps with identical types, and you want to copy all the elements from one to the other. The easiest way to do this is to use map::insert():
typedef std::map
map_t map1;
map_t map2;
// Copy all elements from map1 to map2
map2.insert(map1.begin(), map1.end());
Alternatively, you could use the STL std::copy algorithm:
// Copy all elements from map1 to map2.
std::copy(map1.begin(), map1.end(), std::inserter(map2, map2.begin()));
Both methods’ performance should be an amortized O(n) because they insert records in sorted order and use the hinting form of map::insert.
Note that because both methods ultimately call map::insert they will not overwrite a preexisting key’s associated value. In other words, if map1 has the value V1 associated with key K and map2 the value V2 associated with the same key K, V2 will remain in map2 after the copy operation.
Let’s say you want to perform the copy but have map1’s values overwrite map2’s for identical keys. The first way to solve this problem that entered my mind was to write my own OutputIterator which performs an overwriting assignment and pass it to std::copy. However, there’s a far simpler approach. You can copy map2’s values into map1, relying on the fact that map2’s values won’t overwrite map1’s, and then swap the results:
map1.insert(map2.begin(), map2.end());
map2.swap(map1);
Thanks, Sam, for helping me figure all this out.
"
Saturday, November 22, 2008
New York Times Time Machine
From
New York Times Machine
Interestingly good open source which is used:
a) JetS3T
b) iText
c) Java API for Image Processing
New York Times Machine
Interestingly good open source which is used:
a) JetS3T
b) iText
c) Java API for Image Processing
Saturday, October 18, 2008
Sunday, October 05, 2008
Don't make me think
Reading this book off late Don't Make me think , Will keep updating it with interesting things which I find
1. Sherlock holmes to Dr Watson (on earth revolving around sun)
"What the deuce is it for me? You say we go around the sun. If we went round the moon it would not make a pennyworth of difference to me or to my work"
2. Nothing important should be more than 2 clicks away.
3. Creating a site get rid of the question marks
- If you can create a button do that don't make it a link.
- Make pages self-evident
4. We dont read pages we just scan them
- How users read the web (www.useit.com)
5. We don't make optimal choices. We staisfice(Models of man:Social and Rational)
-How people make decisions
- We choose the first reasonable option.
6. We don't figure out how things work, we muddle through
7. If your audience is going to act like your're designing billboards then design great billboards.
8. Billboards design 101
- Create a clear visual hierarchy on each page
- Take advantage of conventions
- Break up page into clearly defined areas
- Make it obvious what is clickable
- Minimize noise
9. Three mindless unambigous clicks equlas one click that requires thought.
- Making choices mindless.
10. "Get rid of half the words on each page then get rid of half of what's left"
- Elemts of Style
- Eliminates instructions by making everything self explanatory
1. Sherlock holmes to Dr Watson (on earth revolving around sun)
"What the deuce is it for me? You say we go around the sun. If we went round the moon it would not make a pennyworth of difference to me or to my work"
2. Nothing important should be more than 2 clicks away.
3. Creating a site get rid of the question marks
- If you can create a button do that don't make it a link.
- Make pages self-evident
4. We dont read pages we just scan them
- How users read the web (www.useit.com)
5. We don't make optimal choices. We staisfice(Models of man:Social and Rational)
-How people make decisions
- We choose the first reasonable option.
6. We don't figure out how things work, we muddle through
7. If your audience is going to act like your're designing billboards then design great billboards.
8. Billboards design 101
- Create a clear visual hierarchy on each page
- Take advantage of conventions
- Break up page into clearly defined areas
- Make it obvious what is clickable
- Minimize noise
9. Three mindless unambigous clicks equlas one click that requires thought.
- Making choices mindless.
10. "Get rid of half the words on each page then get rid of half of what's left"
- Elemts of Style
- Eliminates instructions by making everything self explanatory
Friday, August 29, 2008
Java Timer and TimerTask
From java2s.com
"import java.util.Timer;
import java.util.TimerTask;
class MyTimerTask extends TimerTask {
public void run() {
System.out.println("Timer task executed.");
}
}
public class MainClass {
public static void main(String args[]) {
MyTimerTask myTask = new MyTimerTask();
Timer myTimer = new Timer();
/*
* Set an initial delay of 1 second, then repeat every half second.
*/
myTimer.schedule(myTask, 1000, 500);
try {
Thread.sleep(5000);
} catch (InterruptedException exc) {
}
myTimer.cancel();
}
}"
"import java.util.Timer;
import java.util.TimerTask;
class MyTimerTask extends TimerTask {
public void run() {
System.out.println("Timer task executed.");
}
}
public class MainClass {
public static void main(String args[]) {
MyTimerTask myTask = new MyTimerTask();
Timer myTimer = new Timer();
/*
* Set an initial delay of 1 second, then repeat every half second.
*/
myTimer.schedule(myTask, 1000, 500);
try {
Thread.sleep(5000);
} catch (InterruptedException exc) {
}
myTimer.cancel();
}
}"
Saturday, August 23, 2008
Olympics Mania!
Recently stumbled upon this article on USATF site
Performance and Responsibility
Key points which i really liked about this article
"The Olympics are about good timing, good luck, good preparation and good execution. All those things have to come together"
"Dropping a baton isn't bad luck, it's bad execution."
"When the men's marathon concludes on Sunday, we'll still be the World's #1 Team in terms of medal count. We can be a much better team. And we will be."
It's goals like these which can make things happen. I think perhaps the most disheartening part of olympics for me was looking at lolo jones crying after she lost, considering that she was winning all the way to hit the penultimate hurdle not sure whether to call that bad luck or bad preparation and I am almost sure it is bad luck.
Performance and Responsibility
Key points which i really liked about this article
"The Olympics are about good timing, good luck, good preparation and good execution. All those things have to come together"
"Dropping a baton isn't bad luck, it's bad execution."
"When the men's marathon concludes on Sunday, we'll still be the World's #1 Team in terms of medal count. We can be a much better team. And we will be."
It's goals like these which can make things happen. I think perhaps the most disheartening part of olympics for me was looking at lolo jones crying after she lost, considering that she was winning all the way to hit the penultimate hurdle not sure whether to call that bad luck or bad preparation and I am almost sure it is bad luck.
Friday, August 15, 2008
Monday, August 04, 2008
Tuesday, July 29, 2008
Saturday, July 26, 2008
Why Randy Paush is my hero
Simple reason I watched his video and haven't seen anyone with such energy
Saturday, July 19, 2008
What is your tax bracket?
From
http://www.bargaineering.com/articles/2008-federal-income-tax-brackets-official-irs-figures.html
"
2008 Tax Brackets
Tax Single Married Filing Jointly
10% Not over $8,025 Not over $16,050
15% $8,025 - $32,550 $16,050 - $65,100
25% $32,550 - $78,850 $65,100 - $131,450
28% $78,850 - $164,550 $131,450 - $200,300
33% $164,550 - $357,700 $200,300 - $357,700
35% Over $357,700 Over $357,700
"
http://www.bargaineering.com/articles/2008-federal-income-tax-brackets-official-irs-figures.html
"
2008 Tax Brackets
Tax Single Married Filing Jointly
10% Not over $8,025 Not over $16,050
15% $8,025 - $32,550 $16,050 - $65,100
25% $32,550 - $78,850 $65,100 - $131,450
28% $78,850 - $164,550 $131,450 - $200,300
33% $164,550 - $357,700 $200,300 - $357,700
35% Over $357,700 Over $357,700
"
Monday, July 14, 2008
What is equity
From financial-dictionary.com
"Equity is a term whose meaning depends very much on the context. In general, you can think of equity as ownership in any asset after all debts associated with that asset are paid off. For example, a car or house with no outstanding debt is considered the owner's equity since he or she can readily sell the items for cash. Stocks are equity because they represent ownership of a company, whereas bonds are classified as debt because they represent an obligation to pay and not ownership of assets."
"Equity is a term whose meaning depends very much on the context. In general, you can think of equity as ownership in any asset after all debts associated with that asset are paid off. For example, a car or house with no outstanding debt is considered the owner's equity since he or she can readily sell the items for cash. Stocks are equity because they represent ownership of a company, whereas bonds are classified as debt because they represent an obligation to pay and not ownership of assets."
Sunday, July 06, 2008
Friday, July 04, 2008
Amazing Quote :)
This quote I stumbled upon
"When a man with experience meet a man with money, the man with money gets the experience and the man with experience gets the money"
"When a man with experience meet a man with money, the man with money gets the experience and the man with experience gets the money"
Wednesday, June 25, 2008
Monday, June 23, 2008
What is Street Date?
Taken from Wikipedia http://en.wikipedia.org/wiki/Street_date
"In business, a street date is the date a particular product is to be released for sale to the general public.
Typically, retailers receive shipments of stock prior to its street date release, so that the product can be placed on display shelves for store opening that day. Shipments come marked very clearly with a "do not sell before release date" label designating a street date mandated by the distributor. Shipments may sometimes arrive up to three weeks in advance.
Retail outlets can be severely punished by manufacturers for releasing a product even a day before the street date. If a retailer breaches the contract establishing a street date, the manufacturer may impose fines, may withdraw privileges to distribute future products from that manufacturer, and may file a lawsuit to enforce the contract. However, there is no documentation of a retail chain or store being fined or any action taken against them."
"In business, a street date is the date a particular product is to be released for sale to the general public.
Typically, retailers receive shipments of stock prior to its street date release, so that the product can be placed on display shelves for store opening that day. Shipments come marked very clearly with a "do not sell before release date" label designating a street date mandated by the distributor. Shipments may sometimes arrive up to three weeks in advance.
Retail outlets can be severely punished by manufacturers for releasing a product even a day before the street date. If a retailer breaches the contract establishing a street date, the manufacturer may impose fines, may withdraw privileges to distribute future products from that manufacturer, and may file a lawsuit to enforce the contract. However, there is no documentation of a retail chain or store being fined or any action taken against them."
Friday, June 20, 2008
Wednesday, June 18, 2008
ByteBuffer to String
ByteBuffer bytebuff = ...;
byte[] bytearr = new byte[bytebuff.remaining()];
bytebuff.get(bytearray);
String s = new String(bytearray);
byte[] bytearr = new byte[bytebuff.remaining()];
bytebuff.get(bytearray);
String s = new String(bytearray);
Thursday, June 12, 2008
Wednesday, June 11, 2008
XML vs JSON
I always thought XML was too verbose, although XML acts as a great plumbing agent.
People using data exchange cannot afford to use such verbose data methods to transfer a vast amount of data over the wire.
JSON seem to be the way to go. Need to get more educated on it. JSON
People using data exchange cannot afford to use such verbose data methods to transfer a vast amount of data over the wire.
JSON seem to be the way to go. Need to get more educated on it. JSON
Cut Command in Unix
Cut command in unix can make your life a lot easier.
Most important of them are
-d (delimiter) by which the fields are separated
-f (fields) fields which you want to get it printed.
E.g w | cut -d' ' -f 1
Most important of them are
-d (delimiter) by which the fields are separated
-f (fields) fields which you want to get it printed.
E.g w | cut -d' ' -f 1
Saturday, June 07, 2008
Friday, June 06, 2008
What is the availability of blogspot?
I often find my site to be unavailable (no one mentions why was it down), i wonder blogspot availability is 95% :) seems to be a good number.
That is the price of using a free thingy would be :) ,
That is the price of using a free thingy would be :) ,
Sunday, June 01, 2008
IPL final
It is between Chennai vs Rajashtan!
No one expected :) this to be the case, I hardly watched all the matches :) but should to be able to buy one. Some free options from google search though not sure if they work
http://live-sports-streaming.blogspot.com/
http://picasa.tv
No one expected :) this to be the case, I hardly watched all the matches :) but should to be able to buy one. Some free options from google search though not sure if they work
http://live-sports-streaming.blogspot.com/
http://picasa.tv
Saturday, May 31, 2008
Gartner top 10
from ehomeupgrade.com
Gartner’s top 10 disruptive technologies 2008-2012:
* Multicore and hybrid processors
* Virtualisation and fabric computing
* Social networks and social software
* Cloud computing and cloud/Web platforms
* Web mashups
* User Interface
* Ubiquitous computing
* Contextual computing
* Augmented reality
* Semantics
Gartner’s top 10 disruptive technologies 2008-2012:
* Multicore and hybrid processors
* Virtualisation and fabric computing
* Social networks and social software
* Cloud computing and cloud/Web platforms
* Web mashups
* User Interface
* Ubiquitous computing
* Contextual computing
* Augmented reality
* Semantics
Wednesday, May 28, 2008
Java ByteBuffer
from java.sun.com
Invariants
The following invariant holds for the mark, position, limit, and capacity values:
0 <= mark <= position <= limit <= capacity
A newly-created buffer always has a position of zero and a mark that is undefined. The initial limit may be zero, or it may be some other value that depends upon the type of the buffer and the manner in which it is constructed. The initial content of a buffer is, in general, undefined.
Clearing, flipping, and rewinding
In addition to methods for accessing the position, limit, and capacity values and for marking and resetting, this class also defines the following operations upon buffers:
*
clear() makes a buffer ready for a new sequence of channel-read or relative put operations: It sets the limit to the capacity and the position to zero.
*
flip() makes a buffer ready for a new sequence of channel-write or relative get operations: It sets the limit to the current position and then sets the position to zero.
*
rewind() makes a buffer ready for re-reading the data that it already contains: It leaves the limit unchanged and sets the position to zero.
Invariants
The following invariant holds for the mark, position, limit, and capacity values:
0 <= mark <= position <= limit <= capacity
A newly-created buffer always has a position of zero and a mark that is undefined. The initial limit may be zero, or it may be some other value that depends upon the type of the buffer and the manner in which it is constructed. The initial content of a buffer is, in general, undefined.
Clearing, flipping, and rewinding
In addition to methods for accessing the position, limit, and capacity values and for marking and resetting, this class also defines the following operations upon buffers:
*
clear() makes a buffer ready for a new sequence of channel-read or relative put operations: It sets the limit to the capacity and the position to zero.
*
flip() makes a buffer ready for a new sequence of channel-write or relative get operations: It sets the limit to the current position and then sets the position to zero.
*
rewind() makes a buffer ready for re-reading the data that it already contains: It leaves the limit unchanged and sets the position to zero.
Java Basics
cretaeClassObject (String name)
{
Object retObj = null;
return(retObj = Class.forName(name).newInstance());
}
{
Object retObj = null;
return(retObj = Class.forName(name).newInstance());
}
Tuesday, May 27, 2008
Java NIO
http://exampledepot.com/egs/java.nio/pkg.html
http://java.sun.com/j2se/1.4.2/docs/api/java/nio/channels/Selector.html
http://www.cs.brown.edu/courses/cs161/papers/j-nio-ltr.pdf
http://java.sun.com/j2se/1.4.2/docs/api/java/nio/channels/Selector.html
http://www.cs.brown.edu/courses/cs161/papers/j-nio-ltr.pdf
Thursday, March 06, 2008
Wednesday, February 27, 2008
Thursday, February 07, 2008
Subscribe to:
Posts (Atom)