Archyvas

‘Programavimas’ Kategorijos archyvas

Drupal – White Page of Death

I was programming with Drupal and got a very ugly mistake – totally blank (white) screen. After some Googling I found that this can be fixed by increasing PHP memory size. Nope, it didn’t helped.

Then I tried some other tricks, like making a redirection to other page. But no.

The solution was very simple: I had to change text encoding to “UTF-8 without BOM” (I used Notepad++ for that). It worked – no white screen ;)

P.S. It took about 5 hours to understand that :)

Can not login to Joomla administrator page

Vasaris 19th, 2010 Ernestas Kardzys Nėra komentarų

Yesterday I had a problem: I couldn’t connect to administrator page of Joomla.

After some gooogling I found out, that there has to be no blank lines in configuration.php file and (in my case): THIS FILE HAD TO BE ENCODED AS ANSI, NOT AS UTF8.

I have no idea why…

Ubercart images do not show up!

Vasaris 19th, 2010 Ernestas Kardzys Nėra komentarų

I have installed latest version of Ubercart (currently – 2.2.) and I had one problem.

I posted a new product, attached image to it, but those images do not show up. Well, and solution is quite simple.

For Drupal 6 you need to enable: CCK, Imagefield, Imagecache, ImageAPI modules and (that was my problem) ImageAPI GD2 OR ImageAPI ImageMagick. I suggest enabling ImageAPI GD2, but it’s up to you and your server configuration.

My impressions about Drupal CMS (or should I say CMF?)

Vasaris 2nd, 2010 Ernestas Kardzys 4 komentarai

The more I read about Drupal Content Management System (Framework?) – the more I like it :) It’s very flexible, provides good API and well documented :)

But why it’s not object oriented?..

Kategorijos:Programavimas, Studijos KTU Raktažodžiai:, ,

Howto. Show slash screen in JavaME

Gruodis 29th, 2009 Ernestas Kardzys 4 komentarai

I was trying to create a splash screen in JavaME. And here it is:

package info.ernestas.guicomponents;

import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Graphics;

/**
 * @author Ernestas Kardzys
 */

public class SplashScreen extends Canvas implements Runnable {
    private Display display;
    private Displayable next;
    private long splashTime = 0;
    private Thread thread;

    public SplashScreen(Display display, Displayable next) {
        this.display = display;
        this.next = next;

        this.display.setCurrent(this);
    }

    public SplashScreen(Display display, Displayable next, long splashTime) {
        this.display = display;
        this.next = next;
        this.splashTime = splashTime;

        this.display.setCurrent(this);
    }

    protected void paint(Graphics g) {
        int width = getWidth();
        int height = getHeight();

        // Set background color
        g.setColor(0×006000);

        g.fillRect(0, 0, width, height);

        Font font = Font.getFont(Font.FACE_MONOSPACE, Font.STYLE_BOLD, Font.SIZE_LARGE);
        g.setColor(0×555555);
        g.setFont(font);

        g.drawString("Hello, World!", width/2, height/2, 0);
    }

    // Closes the screen
    private void dismiss(){
        if (isShown())
          display.setCurrent(next);
    }

    public void showSplash() {
        thread = new Thread(this);
        thread.start();
    }

    public synchronized void notifyDone() {
        notify();
    }

    public void keyReleased(int keyCode) {
        // Do something if a key was pressed or dismiss(); …
    }

    public void pointerReleased(int x, int y) {
       // … or with pointer – dismiss();
    }

   

    public synchronized void run() {
        try {
            // Splash time set – splash until time ends
            if (splashTime > 0) {
                Thread.sleep(splashTime);
            }
            else {
                // No time set – wait until notified
                wait();
            }

            dismiss();
        }
        catch (InterruptedException ex) {
            ex.printStackTrace();
            dismiss();
        }
    }

}

You can call it like that:

SplashScreen splashScreen = new SplashScreen(Display.getDisplay(this), new Form("New form!"), 2000);
splashScreen.showSplash(); // Show splash screen for 2 seconds (1 second = 1000 milliseconds)

Or if you prefer to manually close the form:

SplashScreen splashScreen = new SplashScreen(Display.getDisplay(this), new Form("New form!"));
splashScreen.showSplash();

// Some code here…
splashScreen.notifyDone();

Kategorijos:JavaME, Programavimas Raktažodžiai:, ,

Howto. Send SMS with JavaME

Gruodis 28th, 2009 Ernestas Kardzys 4 komentarai

Here is our second program with JavaME. As I promised this program sends SMS messages by using your mobile phone && JavaME.

The program looks like that:

The application looks like that

To send the SMS you need to select Menu->Send (ok, it was probably very difficult to guess that :D ).

The code looks like that:

/*
 * File SMSSender.java – the GUI for our application
 */

package info.ernestas.smssender;

import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.AlertType;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.TextField;
import javax.microedition.midlet.*;

/**
 * @author Ernestas
 */

public class SMSSender extends MIDlet implements CommandListener {
    //
    private Display display;
    private Form mainForm;

    private Command cmdExit;
    private Command cmdAbout;
    private Command cmdBack;
    private Command cmdSendSMS;

    private TextField tfSMSMessage;
    private TextField tfPhoneNumber;

    //

    public void startApp() {
        display = Display.getDisplay(this);

        cmdExit = new Command("Exit", Command.EXIT, 1);
        cmdSendSMS = new Command("Send", Command.SCREEN, 2);
        cmdBack = new Command("Back", Command.BACK, 1);
        cmdAbout = new Command("About", Command.SCREEN, 3);

        tfPhoneNumber = new TextField("Phone number:", "", 20, TextField.PHONENUMBER);
        tfSMSMessage = new TextField("SMS message:", "", 320, TextField.ANY);

        mainForm = new Form("SMS Sender v.0.1");
        mainForm.addCommand(cmdExit);
        mainForm.addCommand(cmdSendSMS);
        mainForm.addCommand(cmdAbout);
        mainForm.append(tfPhoneNumber);
        mainForm.append(tfSMSMessage);
        mainForm.setCommandListener(this);

        display.setCurrent(mainForm);
    }

    public void pauseApp() {
    }

    public void destroyApp(boolean unconditional) {
    }

    public void commandAction(Command c, Displayable d) {
        if (c == cmdExit) {
            destroyApp(true);
            notifyDestroyed();
        }
        else if (c == cmdBack) {
            display.setCurrent(mainForm);
        }
        else if (c == cmdSendSMS) {
            String phoneNumber = tfPhoneNumber.getString().trim();
            String smsMessage = tfSMSMessage.getString().trim();
            if (phoneNumber.length() > 0 && smsMessage.length() > 0) {
                SMSClient client = new SMSClient();
                client.sendSMS(phoneNumber, smsMessage);

                tfPhoneNumber.setString("");
                tfSMSMessage.setString("");
            }
        }
        else if (c == cmdAbout) {
            Alert about = new Alert("About…", "Created by Ernestas Kardzys, ", null, AlertType.INFO);
            about.setTimeout(Alert.FOREVER);
            about.setCommandListener(this);
            about.addCommand(cmdBack);

            display.setCurrent(about);
        }
    }
}
// ————————————————-
/*
 * File SMSClient.java – the class for Sending SMSes
 */

package info.ernestas.smssender;

import javax.microedition.io.Connector;
import javax.wireless.messaging.MessageConnection;
import javax.wireless.messaging.MessageListener;
import javax.wireless.messaging.TextMessage;

/**
 *
 * @author Ernestas Kardzys
 */

public class SMSClient implements Runnable, MessageListener {
    private String phoneNumber;
    private String message;

    public void sendSMS(String phoneNumber, String message) {
        this.phoneNumber = phoneNumber;
        this.message = message;
        new Thread(this).start();
    }

    public void run() {
        try {
            String address = "sms://" + this.phoneNumber;
            MessageConnection smsConnection = (MessageConnection) Connector.open(address);

            TextMessage smsMessage = (TextMessage)smsConnection.newMessage(MessageConnection.TEXT_MESSAGE);
            smsMessage.setPayloadText(this.message);
            smsConnection.send(smsMessage);

            smsConnection.close();
        }
        catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    public void notifyIncomingMessage(MessageConnection mc) {
        synchronized (this) {
            notify();
        }
    }

}

The program can be found here: http://www.ernestas.info/projects/java/javame/smssender/smssender.zip
Don’t forget: you’re using it at our own risk ;)

Kategorijos:JavaME, Programavimas Raktažodžiai:, , ,

Howto. Calculate PI.

I have the Applied Mathematics course in my university. The question: how to calculate the value of PI (3.14159265358979323846264338327950288…)?

The answer: use Leibniz series:

Small program for doing that:

ernestas@ernestas-laptop:~$ cat calculate_pi.cpp
#include <iostream>
#include <math.h>

using namespace std;

double getPI(int k) {
double pi = 0;
for (int i = 0; i < k; i++) {
pi += 4 * (pow(-1, i) / (2 * i + 1));
}

return pi;
}

int main() {
cout << “PI is: ” << getPI(10) << endl;
cout << “PI is: ” << getPI(100) << endl;
cout << “PI is: ” << getPI(200) << endl;
cout << “PI is: ” << getPI(300) << endl;
cout << “PI is: ” << getPI(400) << endl;
cout << “PI is: ” << getPI(1000) << endl;
cout << “PI is: ” << getPI(2000) << endl;
cout << “PI is: ” << getPI(3000) << endl;
cout << “PI is: ” << getPI(4000) << endl;
cout << “PI is: ” << getPI(5000) << endl;
cout << “PI is: ” << getPI(7000) << endl;
cout << “PI is: ” << getPI(10000) << endl;

return 0;
}
ernestas@ernestas-laptop:~$ g++ calculate_pi.cpp -o pi && ./pi
PI is: 3.04184
PI is: 3.13159
PI is: 3.13659
PI is: 3.13826
PI is: 3.13909
PI is: 3.14059
PI is: 3.14109
PI is: 3.14126
PI is: 3.14134
PI is: 3.14139
PI is: 3.14145
PI is: 3.14149
ernestas@ernestas-laptop:~$

So, the bigger k is, the more accurate value we get :)

P.S. If I’m not wrong, the value PI is defined in header <math.h> – but I’m not sure. :)

Kategorijos:Programavimas, Studijos KTU Raktažodžiai:,

Sony Ericsson SDK && Eclipse && JAVA

Lapkritis 25th, 2009 Ernestas Kardzys Nėra komentarų

I tried to install Sony Ericsson SDK with my Eclipse IDE.

I found awesome tutorial how to do that: http://randomconsultant.blogspot.com/2008/07/creating-j2me-app-with-eclipseme-and.html

WordPress RSS full entries do not show up!

Lapkritis 16th, 2009 Ernestas Kardzys Nėra komentarų

If you have a blog with WordPress, you probably use RSS for your website. Unfortunately, WordPress doesn’t want to show the full entries of RSS feeds – only summary.

To show the full blog post, you need:

  • Go to Settings->Reading  and select Full text.
  • The open a file wp-includes/feed-rss2.php. By default it has  this code at the end:

<…Other PHP code…>

<guid isPermaLink=”false”><?php the_guid(); ?></guid>
<?php if (get_option(‘rss_use_excerpt’)) : ?>
<description><![CDATA[<?php the_excerpt_rss() ?>]]></description>
<?php else : ?>
<description><![CDATA[<?php the_excerpt_rss() ?>]]></description>
<?php if ( strlen( $post->post_content ) > 0 ) : ?>
<content:encoded><![CDATA[<?php the_content() ?>]]></content:encoded>
<?php else : ?>
<content:encoded><![CDATA[<?php the_excerpt_rss() ?>]]></content:encoded>
<?php endif; ?>
<?php endif; ?>

<… More PHP code…>

  • Change it to look like that:

<…Other PHP code…>

<guid isPermaLink=”false”><?php the_guid(); ?></guid>
<?php if (get_option(‘rss_use_excerpt’)) : ?>
<description><![CDATA[<?php the_excerpt_rss() ?>]]></description>
<?php else : ?>
<description><![CDATA[<?php the_content() ?>]]></description>
<?php endif; ?>

<… More PHP code…>

So: remove additional if()s-else()s and instead of content:encoded write description

Happy blogging!

Problem with QTableWidgetItem and QTableWidget

I have a small problem with QTableWidget and QTableWidgetItem.

I have a QHash<QString, QString> downloadQueue. There is at least one entry inside downloadQueue. The point is, that items inside downloadQueue are not added to the QTableWidget. I don’t know  why.

void MDIChildWindow::regenerateTabs() {

m_ui->tableWidgetDownloadQueue->clearContents();

int row = 0;

// Added line

m_ui->tableWidgetDownloadQueue->setRowCount(this->favoritiesItems.count());

// End of added

foreach(QString key, downloadQueue.keys()) {

QTableWidgetItem *download = new QTableWidgetItem(key);

download->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);

m_ui->tableWidgetDownloadQueue->setItem(row, 0, download);

QTableWidgetItem *location = new QTableWidgetItem(downloadQueue.value(key) + “/” + key);

location->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);

m_ui->tableWidgetDownloadQueue->setItem(row++, 1, location);

}

}

Inside foreach() key and downloadQueue.value(key) returns valid values (QStrings).

Do you have any ideas why this is not working???

——–Edited—————-

I found a solution. The problem is, that you need to add a number of entries:

m_ui->tableWidgetDownloadQueue->setRowCount(this->favoritiesItems.count());