JavaFX and Facebook, the solution

When I started this blog, I was rambling with Facebook, JavaFX and alternative technologies.

It turned out that JavaFX is not ideal for social application development, because of various reasons.
Let alone JavaFX, applets are also not very ideal for social application development, if a RIA is necessary Flash is the solution, not even Flex.

Anyway Turning a JavaFX application to a Facebook application Is really simple.
Deploy your JavaFX application for web, in order for it to launch in browser you have to use only WEB components, if you add Desktop components, Java classes etc. You can deploy it but It will not be really a Web application. It can only run in Web when the user download and confirm. It will seem like a Web application but its not.

The method I am going to explain applies for everything, not just JavaFX.

Create an application on Facebook, go to Canvas and point the application to http://yourdomain.com/javafxdeploy.htm
And from Canvas Tab choose “IFRAME”!!!!

I emphasized this point because Iframe application can show anything as a Facebook application.

You can alternatively Develop a “FBML”!!! application and use “fb:iframe” tag and point it to http://yourdomain.com/javafxdeploy.htm

This way you can include fancy stuff like SHARING POINTS with Feed forms etc.

The thing is that you cannot use Facebook API library in JavaFX, so you have to write your own Web services (Php files) to get and set data, interact with Facebook etc. (This part can be a life saver for you if you are determined to use JavaFX)

So to sum up, this is possible but don’t do it.

I personally mastered PHP and I am very happy with it, If I must use RIA in future I will definitely master Flash etc.

Don’t get me wrong, I like JavaFX, it’s great, language properties are really really charming, but it’s not really good for social applications

Lenovo Bluetooth Problem

Simply:
Press Fn+F5, if you see bluetooth there enable it.
else if you see a bluetooth device on Control Panel>Hardware on Network Devices tab, then play around with the driver etc, your problem is minor

else
This was my problem and it took me a lot of time to fix, on windows 7 with my current bios version blutooth device wasn’t recognized, so I made a Bios update and it fixed the problem, now I have bluetooth enabled, here is the link:
http://www-307.ibm.com/pc/support/site.wss/document.do?lndocid=BMOE-3VAM8Y

Netbeans ruins up the day, Windows 7 saves it

I have been using Netbeans PHP because it has auto-completion and it really speeds you up when you write PHP code,

Other than that you can’t believe how awful Netbeans PHP is, it sucks so hard because the FTP support is highly flawed

Suppose you work on a Project with another developer, he made a change, you made a change, Netbeans overwrites the previous change, there is no version control

Suppose other developer created a new php file, in order to download it you have to download all the folder, if the folder doesnt exist you have to download all the Project!!

Additional to these, today (an hour ago) I deleted a folder in one of my projects, not realizing another folder was also selected in an other project
This other folder is the Main Project Folder of a Facebook Application with 400k Monthly active users!!

Guess what? When i delete that other folder, my main application folder also got deleted and at the same time they are deleted from the FTP!! (Yes, i use On Save on Netbeans)

I immediately called my partner, asking him to restore the files if he had them, he uses Zend Studio so i was also afraid he didn’t have the files because Zend, unlike Netbeans works perfectly from FTP, so i wasn’t sure if Zend had the files, fortunately my partner had the files, but not the images

While we were talking, I right-clicked the mouse on My Project Folder, and I saw an option named “Restore Previous Versions”, I didn’t even told Windows 7 to save back-ups, fortunately it did.

I restored files to 26 hours before the delete, thats the time when i last edited the files and thats it Netbeans fucked up the day and Windows 7 saved it.

It’s not the first time Windows helped me like this, there are occasions one of my External hard disks fails, Linux etc can’t do anything to open them, when i plug the hard disk to a windows, and on boot wait >6 hours, windows fixes the hard disk

Time after time, I love Windows.
What about Linux? Well I hate linux because it consumes a high percentage of your time, because it needs to be tweaked and debugged a lot, so I have a Fedora 7 VM on VirtualBox, which I use for Linux specific stuff like C/C++ programming, other than that Windows is ideal

What to do when you get “This file is not SDC file or the format is not supported” from Unpacksdc

Assume you are downloading Windows 7:


en_windows_7_professional_x86_dvd_x15-65804.01.sdc
en_windows_7_professional_x86_dvd_x15-65804.02.sdc

The unpacksdc can’t handle it, so just copy paste them to the C:\Temp\ (or wherever you download the Windows 7)

And resume the download from exe, it will continue from %90, and it will be less painful

SPOJ MEOWIST

The Problem
This problem should be a practise problem

It took me 20mins to solve it =) , I am too rusted lately but hopefully I will post a new problem everyday from now on


#include<stdio.h>
#include<stdlib.h>
#include<algorithm>
#include<string>
#include<iostream>
#include<set>

using namespace std;

class person{
        public:
        int age;
        string name;
        person(int a,string b){age=a; name=b;}
};

bool operator< (person a,person b)
{
        if(a.age>b.age) return true;
        else if(a.age==b.age && a.name<b.name) return true;
       return false;
}

int main()
{

        string a;
        int b;
        multiset< person > people;
        while(cin>>a>>b)
        {
                person n(b,a);
                people.insert(n);
        }
        while(people.size())
        {
                cout<<people.begin()->name<<endl;
                people.erase(people.begin());
        }
        return 0;
}

How to put flash behind HTML

This was a big issue for me because on my new game arcade Goober when i try to pop up a feed dialog, it was going behind the swf.

I found this post searching about how to keep the flash in the background, I may extract only the hiding part and post it here later.

EDIT:

It turns out its a matter of flash embed properties, one should add


wmode='transparent'

or adding this to object tag:


<param name="wmode" value="transparent" />

SPOJ Twinsnow solution

Started to code with a challenge, this problem turned out to be really simple

My friend tried out hashing and it timed out

My approach was to sort the 6 lengths, then sort all the snowflakes, and if the sorted parts match, it compares actual snowflakes

If snowflakes are equal, then when you sort their lengths the sorted listes are also equal.
If sorted lists are equal, then there is a possibility that snowflakes are equal.
If sorted lists are not equal, snowflakes can’t be equal.

Here is the code:
Passed in 11s


#include<stdio.h>
#include<stdlib.h>
#define DEBUG 0

int N;
struct node{
	int a[6],id;
};
node sorted[100100],unsorted[100100];

void escape()
{
	printf("Twin snowflakes found.\n");
	exit(0);
}

void issame(int aa,int b)
{
	if(DEBUG) printf("Comparing %d %d\n",aa,b);
	int i,k,ok;
	for(k=0;k<6;k++)
	{
		ok=1;
		for(i=0;i<6;i++)
			if(unsorted[aa].a[i]!=unsorted[b].a[(i+k)%6]) {ok=0; break;}
		if(ok) escape();
	}
	for(k=0;k<6;k++)
	{
		ok=1;
		for(i=0;i<6;i++)
			if(unsorted[aa].a[i]!=unsorted[b].a[(6-i+k)%6]) {ok=0; break;}
		if(ok) escape();
	}
}

int intsort(const void *pa,const void *pb)
{
	int *aa=(int *)pa;
	int *bb=(int *)pb;
	if((*aa)>(*bb)) return -1;
	return 1;
}

int sort6(const void *pa,const void *pb)
{
	node *aa=(node *)pa;
	node *bb=(node *)pb;
	int i;
	for(i=0;i<6;i++)
	{
		if((*aa).a[i]>(*bb).a[i]) return 1;
		if((*aa).a[i]<(*bb).a[i]) return -1;
	}
	return 0;
}

int equal(int aa,int b)
{
	for(int i=0;i<6;i++)
		if(sorted[aa].a[i]!=sorted[b].a[i]) return 0;
	return 1;
}

void read(void)
{
	int i,j;
	scanf(" %d",&N);
	for(i=0;i<N;i++)
	{
		for(j=0;j<6;j++)
			scanf(" %d",&unsorted[i].a[j]),sorted[i].a[j]=unsorted[i].a[j],sorted[i].id=i;
		qsort(sorted[i].a,6,sizeof(int),intsort);
	}
	qsort(sorted,N,sizeof(node),sort6);
}

void find(void)
{
	int i=0,j,k,l;
	while(i<N-1)
	{
		j=i+1;
		while(equal(i,j) && j<N) j++;
		for(k=i;k<j-1;k++)
			for(l=k+1;l<j;l++)
			{
				issame(unsorted[k].id,unsorted[l].id);
			}
		i=j;
	}
	printf("No two snowflakes are alike.\n");
}

int main()
{
	read();
	find();
	return 0;
}

Solution of * doesnt contain ObjectFactory.class or jaxb.index

For some reason while unmarshalling something you get this error
Solution is:
Instead of


        javax.xml.bind.JAXBContext jaxbCtx = javax.xml.bind.JAXBContext.newInstance("oasis.names.specification.ubl.schema.xsd.invoice_2");
or
        JAXBContext context = JAXBContext.newInstance(inv.getClass().getPackage().getName());

Use a notation like this


        javax.xml.bind.JAXBContext jaxbCtx = javax.xml.bind.JAXBContext.newInstance(oasis.names.specification.ubl.schema.xsd.invoice_2.InvoiceType.class);

Where InvoiceType will be the thing you want to unmarshall into

How to validate XML with XSD in Java

After initializing xsd with JAXB Binding on Netbeans, you can use a method like this.
Both JAXB binding and schema are same but as far as i see, JAXB unmarshalling doesn’t validate XML, it just transforms it.


package unmarshallertest;

import java.io.*;
import javax.xml.bind.*;
import javax.xml.validation.*;
import oasis.names.specification.ubl.schema.xsd.invoice_2.*;

public class Main {
    public static void main(String[] args) {
        String result;
        InvoiceType inv = new InvoiceType();
        try {
            javax.xml.bind.JAXBContext jaxbCtx = javax.xml.bind.JAXBContext.newInstance("oasis.names.specification.ubl.schema.xsd.invoice_2");
            javax.xml.bind.Unmarshaller unmarshaller = jaxbCtx.createUnmarshaller();

            SchemaFactory sf = SchemaFactory.newInstance(javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI);
            Schema schema = sf.newSchema(new File("C:\\Users\\Kaan\\Desktop\\BELGELER\\UBL-TR files\\UBLTR\\UBL-TR\\xsd\\maindoc\\UBLTR-Invoice-2.0.xsd"));

            unmarshaller.setSchema(schema);

            JAXBElement element=(JAXBElement) unmarshaller.unmarshal(new FileInputStream("fatura.xml")); //NOI18N
            inv=(InvoiceType) element.getValue();
        } catch (Exception ex) {
            // XXXTODO Handle exception
            ex.printStackTrace();
        }
        System.out.println("Validation complete");

    }
}

for oasis.names.specification.ubl.schema.xsd.invoice_2.InvoiceType code is as seen
you can fill it for your own xml and package

Netbeans jaxbu(tab) shortcode doesnt work as intended (At least not now)

Flex: How to add enter event for RichTextEditor

I did this for RichTextEditor but it is applicable to any object.

Many of them have enter event, but RichTextEditor uses enter keys for new line so if you want enter to submit you should do it manually.


<mx:Script>
    	<![CDATA[
        private function enterHandler(event:KeyboardEvent):void
        {
        	if(event.keyCode==Keyboard.ENTER) sendMessage();
        }
        private function init():void
        {
        	textInput.addEventListener(KeyboardEvent.KEY_DOWN,enterHandler);
        }
))>
</mx:Script>
<mx:RichTextEditor id="textInput" change="write('W')" width="550" height="150" fontFamily="Verdana" fontSize="14" color="#150E56"/>

sendMessage, write are my custom functions, of course