Saturday, 17 August 2013

Missing asymptote in gnuplot

Missing asymptote in gnuplot

When plotting (x-1)/(x*x-1) in gnuplot the asymptote at x=-1 is obvious,
but at x=1 the curve looks smooth, see figure below. What settings should
I use to show the discontinuity at x=1?

Data flow in the classic Hadoop word count example in Python

Data flow in the classic Hadoop word count example in Python

I am trying the understand the Hadoop word count example in Python
http://www.michael-noll.com/tutorials/writing-an-hadoop-mapreduce-program-in-python/
The author starts with naive versions of the mapper and the reducer. Here
is the reducer (I removed some comments for brevity)
#!/usr/bin/env python
from operator import itemgetter
import sys
current_word = None
current_count = 0
word = None
# input comes from STDIN
for line in sys.stdin:
line = line.strip()
word, count = line.split('\t', 1)
try:
count = int(count)
except ValueError:
continue
if current_word == word:
current_count += count
else:
if current_word:
# write result to STDOUT
print '%s\t%s' % (current_word, current_count)
current_count = count
current_word = word
# do not forget to output the last word if needed!
if current_word == word:
print '%s\t%s' % (current_word, current_count)
The author tests the program with:
echo "foo foo quux labs foo bar quux" | /home/hduser/mapper.py | sort
-k1,1 | /home/hduser/reducer.py
So the reducer is written as if a reducer job's input data was like:
aa 1
aa 1
bb 1
cc 1
cc 1
cc 1
My initial understand of a reducer was that the input data for a given
reducer would contain one unique key. So in the previous examples, 3
reducers jobs would be needed. Is my understand incorrect?
Then the author presents improved versions of the mapper and the reducer.
Here is the reducer:
#!/usr/bin/env python
"""A more advanced Reducer, using Python iterators and generators."""
from itertools import groupby
from operator import itemgetter
import sys
def read_mapper_output(file, separator='\t'):
for line in file:
yield line.rstrip().split(separator, 1)
def main(separator='\t'):
# input comes from STDIN (standard input)
data = read_mapper_output(sys.stdin, separator=separator)
for current_word, group in groupby(data, itemgetter(0)):
try:
total_count = sum(int(count) for current_word, count in group)
print "%s%s%d" % (current_word, separator, total_count)
except ValueError:
# count was not a number, so silently discard this item
pass
if __name__ == "__main__":
main()
The author adds the following warning:
Note: The following Map and Reduce scripts will only work "correctly" when
being run in the Hadoop context, i.e. as Mapper and Reducer in a MapReduce
job. This means that running the naive test command "cat DATA |
./mapper.py | sort -k1,1 | ./reducer.py" will not work correctly anymore
because some functionality is intentionally outsourced to Hadoop.
I don't understand why the naive test command doesn't work with the new
version. I thought the use of sort -k1,1 would produce the same input for
both versions of the reducer. What am I missing?

Hosting with Amazon advice

Hosting with Amazon advice

I was looking into .NET hosting and came across the Amazon Windows
Hosting. I'm looking for a solution with IIS, ASP.NET & MSSQL.
The website will be accessed mostly for 2 particular months in a year so
there's no need to stay with the same specs for the whole year - I still
need it to be online for the whole year. For this I was thinking to
upgrade/downgrade accordingly from micro to small/medium when needed.
Guess I only need an EC2 instance only with everything on it? Or should I
opt for an RDS too?
Also, something else that I wanted to be sure of. When Amazon say that you
have to pay $0.09/hour, if for example:
Server is used 5 minutes between 07:00-08:00
Server is used 25 minutes between 08:00-09:00
Does that costs $0.18cents (2hrs) or just $0.0045cents (30 minutes)?

Sliding Menu with ViewPagerIndicator

Sliding Menu with ViewPagerIndicator

i my activity i'm extending Sliding Menu library and ViewPagerIndicator.
However my application works like this:
SlidingMenu launches a fragment that extends viewpager that also have 5
tabs in it.
Each tab extends a listadapter class.
Now this is how my activity works, but i'm experiencing a highly lagging
performance! how can i combine the sliding menu with view pager indicator
without experiencing any lag performance?!
if you want me to show your codes, just say in the description.
Thanks for your help!

how to display start from image using sprite animation in android

how to display start from image using sprite animation in android

I will develop one project ,In my project i had one sprite .

and want to display animation like
how to solve my problem .

Proving $\sum_{k=0}^{n}k{n\choose k} = n{2n-1 \choose n-1} $

Proving $\sum_{k=0}^{n}k{n\choose k} = n{2n-1 \choose n-1} $

I'm struggling at proving the following combinatorical identity:
$$\sum_{k=0}^{n}k{n\choose k} = n{2n-1 \choose n-1} $$ I would like to see
a combinatorical (logical) solution, or an algebraic solution.

Friday, 16 August 2013

Qt Signals and slots - No matching function for call

Qt Signals and slots - No matching function for call

I am learning QT and am trying to get my signals and slots working. I am
having no luck. Here is my Main
int main(int argc, char** argv) {
QApplication app(argc, argv);
FilmInput fi;
FilmWriter fw;
QObject::connect (&fi->okButton, SIGNAL( clicked() ), &fi, SLOT(
okButtonClicked() )
); //Error received Base operand of '->' has non-pointer type 'FilmInput'
QObject::connect(&fi,SIGNAL(obtainFilmData(QVariant*)),&fw,SLOT(saveFilmData(QVariant*)));
//Error received No matching function for call to
'QObject::connect(Filminput*, const char*, FilmWriter*, const char*)
fi.show();
return app.exec();
}
and here is my sad attempt at signals and slots:
FilmInput.h
public:
FilmInput();
void okButtonClicked();
QPushButton* okButton;
signals:
void obtainFilmData(Film *film);
Here is FilmWriter.h
public slots:
int saveFilm(Film &f);
Here is Film Input.cpp
void FilmInput::okButtonClicked(){
Film *aFilm=new Film();
aFilm->setDirector(this->edtDirector->text());
emit obtainFilmData(aFilm);
}
Here is FilmWriter.cpp
void FilmInput::okButtonClicked(){
Film *aFilm=new Film();
aFilm->setDirector(this->edtDirector->text());
emit obtainFilmData(aFilm);
}
Please assist me in getting the signals and slots to work, I have spent
hours but am no closer to getting it working. I have added the errors
received in my comments above.
Regards