Sunday, March 25, 2012

Reading delimiter tab (\t) from request with PHP


If you give to user a possibility to enter freely for example a delimiter character for csv-file, and the user selects horizontal tab, '\t', you need to change it to "real" tab character yourself in PHP, at the server side.

The inputted value "\t" is sent to server as a string, which length is 2, and contains to characters '\' AND 't'. You need to change it to one single character '\t' for example with:

$delimiter = $_REQUEST["delimiter"]; // use here the input form name you have 
$delimiter = str_replace("\\t","\t",$delimiter);

You can make a function for replacing any of the special characters you allow the user to enter.

If you are sending a pre-formatted text which contains \t characters, they remain unchanged after sending the form to the server. That is because the user did not type the characters '\' and 't', but did use a program to type a single tab character '\t'.

Friday, March 23, 2012

Angry Birds soda cans

I was shopping at our local grocery store when I spotted these cans.

Even without my kids being there, I would have bought these. Just to know what they taste like.

The flavors are Paradise (tangerine and pineapple) and Tropic (tropical fruits).

The manufacturer is Finnish company Olvi and the price at out store was 1,14 e.





EDIT 2012-03-28

Okay, yesterday I visited another shop of the same brand and found the proper stands for Angry Birds soda. I took some pictures with my old Nokia (hence the image quality!).




Too bad, they had attached the pricing information on top of the Angry Birds logo. If you look at the lower image, you can see that the stand is labeled with "Olvi" and "Rovio". Also the price per soda can is higher in this shop...

EDIT 2012-04-04

The Finnish beverage manufacturer Olvi has made the official nutrient info for Angry Birds soda available here: http://www.olvi.fi/web/fi/angrybirdstropic and http://www.olvi.fi/web/fi/angrybirdsparadise. The pages are in Finnish. The company has also information in English but it looks like it is not up to date.

EDIT

The same text in Finnish:

Viikonlopun ruokia ostaessani huomasin Citymarketissa ison telineen Angry Birds limsaa. Vaikka lapset eivät olisikaan olleet mukana kauppareissulla, olisin silti ostanut molempia makuja.

Maut ovat Paradise (mandariini ja ananas) ja Tropic (trooppiset hedelmät), juoman valmistajana Olvi ja hinta "Sittarissa" 1,14 e / tölkki.


New Angry Birds soda cans!


Angry Birds candy


Angry Hockey Bird
Do you know Hockey Bird?



Thursday, March 22, 2012

Error in Eclipse and Android environment: The method X or type Y must override a superclass method

After importing two Android projects to Eclipse workspace, I received over 3000 errors!

* Some errors were removed after selecting the correct SDK from
Properties > Android > Project Build Target 

* Some errors were removed after clean and rebuild.


But still there were 600+ error with message:
"The method X or type Y must override a superclass method."


The solution was to set the Compiler level from 1.5 to 1.6. 

So, setting

Properties > Java Compiler > JDK Compliance level to 1.6

solves the problem.

EDIT 2012-03-24

You may need to"delete" the projects from the workspace and then import them again. You may need to do that more than once.

Sunday, February 19, 2012

Capturing webcam image with Java Media Framework

I have used Java Media Framework (JMF) quite a lot in the past, and recently I strarted to experiment again with some of my old algorithms. Having changed my computers during these years, I noticed that the old code did not work correctly. Especially, setting the webcam video capture format did not respond. This is the problem I noticed many people were still having, based on the question on the stackoverflow etc.

After some hours of debugging, I found out that the format needs to be set before the javax.media.Player is started. After the player has been started, the FormatControl.setFormat() has no effect.

Here is also a full source code minimal webcam image grabber. Please, let me know if you have problems with it. Please note that the initialization of the video capture device may take some seconds. If you are grabbing images as fast as possible, the first image captures will fail (the images returned have dimension 1x1) until the video capture device is ready.

Use class like this:

    FrameGrabber grabber = new FrameGrabber();
    if (grabber.init()==true) {
        BufferedImage frame = grabber.grab();
    }

And the class source code:
import java.util.Vector;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.image.BufferedImage;
import javax.media.*;
import javax.media.control.FormatControl;
import javax.media.control.FrameGrabbingControl;
import javax.media.format.VideoFormat;
import javax.media.format.YUVFormat;
import javax.media.util.BufferToImage;

//
// source code by tejopa / popscan.blogspot.com, 2012
//

public class FrameGrabber {
 
    CaptureDeviceInfo    _cdi;
    Player               _player;
    FrameGrabbingControl _frameGrabber;
    FormatControl        _formatControl;

    public FrameGrabber() { }
  
    public boolean init() {
     Vector devices = CaptureDeviceManager.getDeviceList(new YUVFormat());
     if (devices.size()<1) {
      System.out.println("No capture devices available!");
     } else {
      _cdi = (CaptureDeviceInfo)devices.elementAt(0);
     }
     try {
            _player = Manager.createRealizedPlayer(_cdi.getLocator());
         _frameGrabber = (FrameGrabbingControl)_player.getControl("javax.media.control.FrameGrabbingControl");
         _formatControl = (FormatControl)_player.getControl("javax.media.control.FormatControl");
         _formatControl.setFormat(_cdi.getFormats()[0]);
         _player.start();
         return true;
     } catch (Exception e) {
      e.printStackTrace();
  }
     return false;
    }
    
    public BufferedImage grab() {
        if (_frameGrabber==null) {
            System.out.println("FrameGrabber is not initialized!");
            return null;
        }
     // Grab a frame from the capture device
        Buffer buf = _frameGrabber.grabFrame();
        // check that buf actually exists!
        if (buf!=null) {
            Image img = new BufferToImage((VideoFormat)buf.getFormat()).createImage(buf);
            // image creation may also fail!
            if (img!=null) {
         BufferedImage bi = new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_ARGB);
  Graphics2D g = bi.createGraphics();
  g.drawImage(img, 0,0, null);
  return bi;
            }
        } 
        // grab failed, still return image, but make it empty and small
        BufferedImage bi = new BufferedImage(1,1, BufferedImage.TYPE_INT_ARGB);
        return bi;
    }
}

Monday, January 2, 2012

GT5 freezing problem - fixed

I just bought PS3 320GB version and Gran Turismo 5 for Christmas. I played 2 days without any problems, but suddenly some menus stopped working.

Soon I was not able to play anything, the game just froze to different places, never finished loading for races or did not even go to "arcade" or "gt" mode menus.

I removed the game datas and loaded the updates again. With my 1 MB connection, it took 9 hours to download 12 updates! And what was the result? I did not work.

So I removed the game data again AND also the game save data. Yes, I lost my game progress, but I was not able to play anyway, so... I called my ISP and upgraded my internet connection to 10 MB.

Then I started the game again, downloaded updates (this time it took 55 minutes!) and finally started the game. The game started and has been running okay for now.

My conclusion is that the game save got corrupted... It would not be too hard to create some kind of check sum etc to see if the game save is valid or not...

So, the solution that might work also for you:
1. delete game data
2. delete game save
3. start game to upload updates
4. start game to create new game save

Friday, December 9, 2011

QT Linguist does not show plurals : solution

I have been using QT Linguist for a large software project. I have had a need to include translatable texts that are not yet used in the code itself.

For including texts for translation, QT Linguist manual suggests to use QT_TR_NOOP or QT_TRANSLATE_NOOP.

For some reason, I was unable to see plurals when editing texts in QT linguist. It took me few hours, but I found out that when using QT_TR_NOOP or QT_TRANSLATE_NOOP macros, the plurals will not be generated when running "lupdate" command.

So, instead of using:
QT_TR_NOOP("You got %n hellos");
you need to use to
tr("You got %n hellos");
get the singular and plural inputs to be shown in QT Linguist.

That pretty much destroys the idea for the macros... This might be version and/or language specific issue, but if you encounter this problem, try to change the macros to actual tr()-calls.

Wednesday, November 30, 2011

Mercurial answers remote:ssl required (simple mistake!)

Today I got my new laptop at work finally set up and running.

I made some changes to my C/C++ code and tried to push the changes to mercurial repository using Tortoise HG client. But the server just responded:
pushing to http://mercurial.company.com/code/hg/username/project
searching for changes
24 changesets found
remote: ssl required

Well, that was something I did not expect... 

I did found only irrelevant information from the web, and finally asked help from my colleague. He answered briefly, "Are you using ssh connection?".

Of course! That was it. I just needed to change the protocol in my repository address from http to ssh... Sometimes it is difficult to see obvious problem.

So, before doing any changes to your Apache or Mercurial server, check your address... :)