Tuesday, September 7, 2010

How to play online streaming videos (Youtube, Metcafe etc.) on Ubuntu 64 bit.

The 64-bit version of Ubuntu has issues playing youtube and other streaming videos from browser. Reason being the browser shipped with the OS is itself a 64-bit browser. The Adobe Flash player 64-bit plugin is still under development and yet not released. A beta version of the same was included in Karmic Koala, which has now been removed for further improvement. .

One workaround would be to install 32-bit Firefox from Mozillla repository and install the 32-bit Adobe fFash player plugin. The other way would be to install the beta version of the 64-bit Adobe Flash player which is now available from other repositories. Following are the steps:
1. Remove all other flash plugin intallations. Use the following shell script

#!/bin/bash
apt-get remove --purge flashplugin-installer
apt-get remove --purge flashplugin-nonfree gnash gnash-common mozilla-plugin-gnash
apt-get remove --purge iceweasel-flashplugin mozilla-flashplugin firefox-flashplugin
apt-get remove --purge swfdec-mozilla libflashsupport nspluginwrapper iceape-flashplugin
apt-get remove --purge xulrunner-flashplugin midbrowser-flashplugin xulrunner-addons-flashplugin
rm -f ~/.mozilla/plugins/*flash*
rm -f /usr/lib/firefox-addons/plugins/*flash*
rm -f /usr/lib/firefox/plugins/*flash*
rm -f /usr/lib/iceape/plugins/flashplugin-alternative.so
rm -f /usr/lib/iceweasel/plugins/flashplugin-alternative.so
rm -f /usr/lib/iceweasel/plugins/npwrapper.libflashplayer.so
rm -f /usr/lib/midbrowser/plugins/flashplugin-alternative.so
rm -f /usr/lib/mozilla/plugins/*flash*
rm -f /usr/lib/xulrunner-addons/plugins/flashplugin-alternative.so
rm -f /usr/lib/xulrunner/plugins/flashplugin-alternative.so
rm -f /var/lib/flashplugin-nonfree/npwrapper.libflashplayer.so


Save the above script in a file say... remove_flash.sh and give it executable permission
$chmod u+x remove_flash.sh

Download

2. Add the following to the Software Sources:

http://ppa.launchpad.net/sevenmachines/flash/ubuntu lucid main

One way to do this is through Applications > Settings > Software Sources.
Once added issue the following command:
$ sudo apt-get update && sudo apt-get install flashplugin64-installer

Check opening firefox and opening up any youtube video.




Qt-Creator: Using native/platform specific library

Unfortunately, Qt-Creator so far does not provide for addition of native/platform specific dependencies from its UI. The only way to do it is by editing the .pro file manually.

An example:

If the Win32 API GetKeyState() contained in User32.dll is used in your code, append the following lines to the .pro file of your project:

win32 {

LIBS += User32.lib

}

Simlarly, an Unix specific dependency will go into a block like this&

unix{

LIBS += -L/usr/local/lib -lmath

}

Tuesday, June 22, 2010

C++ WholeNumber (BigInteger) container on way

Publishing something after quite some time…..

Well the new kid on the blog is a C++ container for a Whole Number (0 < n < ∞). This is much like the JAVA BigInteger class. It will enable you to perform mathematical operations on big positive integers/whole numbers with the ease of using a native data type. All mathematical and logical operators for supporting normal operations are being added.

Some examples for its use might be finding the results of:

100!

234^567

999777775558778115674556555555555555555555555/5678988909

No special operations are required, just use this class as a native datatype to achieve the above mentioned.

Insertion/Extraction operators have been overloaded too, enabling normal console I/O.

It is still under development, an initial working prototype is ready. Loads of operators still remain to be overloaded.

You can have a peek at it at http://bitbucket.org/agnit/wholenumber/ . It is hosted on bitbucket.org as a public mercurial repository.

You'll need to have mercurial installed on your system to create a local clone of the repository.

Currently, the project consists of 2main files:

WholeNumber.h

WholeNumber.cpp

and a test program.

Tuesday, August 25, 2009

A Steganography Tool

Check my cute little creation ;)

Stegosaurus 1.0 is a tool to perform steganography on 24-bit BMP files.

Use this to hide and recover any type of file to and from a selected BMP image, without altering the original size of the image

For details of the steganography process used visit

http://www.garykessler.net/library/steganography.html

A Combination Generator Class

//The Combination Generator Class
#include < vector >
using namespace std;

typedef unsigned long long uint64;

class CombinationGenerator
{
public:
CombinationGenerator(int, int);
uint64 getNumLeft() const;
bool hasMore() const;
uint64 getTotal() const;
vector getNext();

private:
void reset();
uint64 getFactorial(int) const;

vector indices;
int n, r;
uint64 numLeft, total;
};

//--------------------------------------------
//The Constructor: Arguments n and r of nCr
//--------------------------------------------
CombinationGenerator::CombinationGenerator(int n, int r)
{
if (r > n || n <>n = n;
this->r = r;
indices.resize(r);
uint64 nFact = getFactorial (n);
uint64 rFact = getFactorial (r);
uint64 nminusrFact = getFactorial (n - r);
total = nFact/(rFact*nminusrFact);

reset ();

}
//------
// Reset
//------
void CombinationGenerator::reset()
{
for (int i = 0; i < numleft =" total;" style="color: rgb(0, 153, 0);">//------------------------------------------------
// Return number of combinations not yet generated
//------------------------------------------------
uint64 CombinationGenerator::getNumLeft() const
{
return numLeft;
}
//-----------------------------
// Are there more combinations?
//-----------------------------
bool CombinationGenerator::hasMore() const
{
return numLeft>0;
}
//------------------------------------
// Return total number of combinations
//------------------------------------
uint64 CombinationGenerator::getTotal() const
{
return total;
}
//------------------
// Compute factorial
//------------------
uint64 CombinationGenerator::getFactorial(int n) const
{
uint64 fact =1;
for (int i = n; i > 1; i--) {
fact = fact*i;
}
return fact;
}
//--------------------------------------------------------
// Generate next combination
//--------------------------------------------------------
vector CombinationGenerator::getNext()
{
if (numLeft==total) {
numLeft = numLeft-1;
return indices;
}
int i = r - 1;
while (indices[i] == n - r + i) {
i--;
}
indices[i] = indices[i] + 1;
for (int j = i + 1; j < r; j++) {
indices[j] = indices[i] + j - i;
}
numLeft = numLeft-1;
return indices;
}

///////////////Test Program/////////////////////
#include < iostream >
#include "CombinationGenerator.h"
using namespace std;

int main()
{
int myints[] = {44,67,23,74};
vector myvector (myints, myints+4);

sort (myvector.begin(), myvector.end(), greater());

/////////Generate 4C3 combinations///////////////

CombinationGenerator x(myvector.size(), 3);
while (x.hasMore ()) {
vector indices = x.getNext ();
for (int i = 0; i < indices.size(); i++) {
cout << myvector[indices[i]] <<" ";
}
cout <<endl;
}
getchar();
return 0;
}

Download Source

Tuesday, March 24, 2009

Linux - Receiving daemon messages in your Mail Client Inbox

Daemon messages in Linux are mailed to the superuser. The good old command line utility mail always rocks to access these messages. But what if you wanted to receive these messages in your default mail client inbox and access them via GUI? The steps are really easy. I will show you how to do this configuring Thunderbird as my default mail client.

1. Download Mozilla Thunderbird on your Linux box.(The package will have a name like thunderbird.tar.gz)

2. Unzip the package using the following commands:
gunzip thunderbird.tar.gz

tar -xvf thunderbird.tar

3. Move thunderbird directory to the /opt directory.

4. Goto the /opt directory and run the application
cd /opt
./thunderbird

5. Follow the account setup instructions as shown:









(assuming you are root on the machine free.scoobydoo)








6. Click Finish and we are all set to go. The daemon messages from now onwards will be available in your inbox. Thunderbird will retrieve them from the system mbox, whenever it is started.

QSqlDatabase closing problem while using QSqlTableModel with QTableView

Problem:

I was working on a application that deals with multiple databases when I encountered a problem while closing a connection. Even if I close the connection it seemed to be active and hence was not letting itself to be copied.
The code I used typically was :

QSqlDatabase db(Conn);

....................................
....................................

....................................
db.close();



The copying problem caused due to the connection remaining active got solved after enclosing the queries in proper scope. eg.

{
QSqlDatabase db = QSqlDatabase::database("sales");
QSqlQuery query("SELECT NAME, DOB FROM EMPLOYEES", db);
}
// Both "db" and "query" are destroyed because they are out of scope
QSqlDatabase::removeDatabase("sales"); // correct

But the problem reappeared, after I implemented a QTableView with a QSqlTableModel:

QSqlTableModel *model =new QSqlTableModel(this, Conn) ;
model->setTable("student");
model->setFilter("student_id=" +QString::number(Cmn_Global::student_id ));
model->setSort(3, Qt::AscendingOrder);
model->setEditStrategy(QSqlTableModel:: OnFieldChange);
model->select();
............................
...........................
ui.tableView->setModel(model);//view is the QTableView object

Calling db.close() failed to close the connection as the real time querying between the Model and the View, which was not possible for me to enclose within scope.


Solution:
The only solution that emerged was to kill the connection manually, by deleting the QSqlTableModel pointer related to the view using the following code:
QSqlTableModel* model= dynamic_cast (ui.tableView->model());
delete model;

And then calling the close method on the database.

The database can then be smoothly copied as the connection was no more active.