Monday, December 14, 2009

Convert String

Example fo class to convert string in numeric type (int, short int, float, ecc.)

#include

using namespace std;

class Conversion
{
public:
static bool toInt(const char * value, int &returned);
static bool toUShortInt(const char *value, unsigned short &returned);
template static bool fromString(T& t, const std::string& s, std::ios_base& (*f)(std::ios_base&));
};





template
bool Conversion::fromString(T& t, const std::string& s, std::ios_base& (*f)(std::ios_base&))
{
std::istringstream iss(s);
return !(iss >> f >> t).fail();
}



bool Conversion::toInt(const char *value, int &returned)
{
return fromString(returned, std::string(value), std::dec);

}

bool Conversion::toUShortInt(const char *value, unsigned short &returned)
{
return fromString(returned, std::string(value), std::dec);
}

QMaemo5TimePickSelector

QMaemo5TimePickSelector example of use:


declaration :

timeEditEntrance = new QMaemo5ValueButton("Entrance");
timeEditEntrance->setValueLayout(QMaemo5ValueButton::ValueUnderText);
timeEditEntrance->setPickSelector(new QMaemo5TimePickSelector());
timeEditEntrance->setObjectName(QString::fromUtf8("timeEditEntrance"));

set:

QTime entrance;
..
..
timeEditEntrance->setValueText(entrance.toString("hh:m"));


get:

QTime entrance = QTime::fromString(timeEditEntrance->valueText(), "hh:m");

Wednesday, December 9, 2009

remove file control characters or special characters

To remove file control characters or special characters, delete it with inode number.
Get inode number with ls -il
thus delete it:
find . -inum inodenumber -exec rm -i {} \;

Monday, September 21, 2009

install firefox plugin

Whether you need install a firefox plugin without internet connection, use this tip:

1. Type about:config into Firefox’s address bar
2. Right-click on the Firefox window. Select New > Boolean.
3. Set preference name to type extensions.checkCompatibility.
4. Set value to False

Then, restart firefox and install plugin with open file

Thursday, September 10, 2009

makefile condition

If you need conditionl instruction in Makefile this is a example

KNL_VER:= $(shell uname -r)
KNL_MAJOR:= $(shell echo $(KNL_VER) | cut -c -3)

LDFLAGS = -p
RV = 2.6



ifeq ($(KNL_MAJOR), $(RV))
LDFLAGS = -lm
else
LDFLAGS = -lc
endif

Monday, June 15, 2009

/etc/password

To get home directory of the "user" from /etc/password:

echo $(awk -F ":" '/^user/{print$(NF-1)}' /etc/passwd)

Tuesday, April 14, 2009

play dvd+ubuntu

If you have a problem for play your dvd, run xine from shell, if you have this message: libdvdread: Encrypted DVD support unavailable. You can to resolve so:

cd /usr/share/doc/libdvdread3/
sudo ./install-css.sh

now restart xine or vlc...and enjoy

Tuesday, March 10, 2009

To get return code of a program: program; echo $?

loc

To count your loc i suggest http://www.dwheeler.com/sloccount/.
Count line in your code with find . -name \*.c | xargs wc -l

Friday, March 6, 2009

ure

On kubuntu 8.10 if you install 3.0 openoffice-dev and you want develop you must to create follow symbolik link:
cd /usr/lib/openoffice
ln -s ../ure/ ure

Tuesday, January 27, 2009

Simple JFileChooser

If you want a simple JFileChooser, without new direcotry, file list combobox, desktop button and button directory up, you can write this:

JFileChooser chooser = new JFileChooser(airportDir);

JPanel optionsPanel = (JPanel) chooser.getComponent(0);
optionsPanel.setVisible(false);