Tuesday, December 30, 2008

Seam ve Sayfa Navigasyonu

Seam sayesinde EJB ve xhtml sayfa kavramlari birbirine iyice yaklasti. Sayfa icinden EJB ismini kullanarak button, link tiklamalari direk metot cagrilarina eslemek mumkun. Peki bu tiklama sonrasi hangi sayfaya gidecegimizi nasil soyleyecegiz?

Aksiyon metotlarindan String tipi dondurmek ve bu parametreye "falanca.xhtml" gibi bir deger koymak bir cozumdur. Seam burada gordugu degeri sayfa ismi olarak kabul eder ve oraya yonlendirme yapar.

Daha iyi bir cozum, aksiyon metotlarinin hicbir sey dondurmemesi (yani void) ve navigasyonun tamamen disarida bir ayar dosyasinda yapilmasidir. Bu dosya pages.xml dosyasidir.

Navigasyonu bu sekilde yapinca, ayni aksiyonun (metotun) degisik sayfalarda degisik yerlere yonlendirilmesi mumkun olur. Yani bu teknik daha gucludur ve daha temizdir. Bu dosya, WEB-INF altinda web.xml ile ayni seviyede olmali.

<pages xmlns="http://jboss.com/products/seam/pages" xsi="http://www.w3.org/2001/XMLSchema-instance" schemalocation="http://jboss.com/products/seam/pages http://jboss.com/products/seam/pages-2.1.xsd" id="/main.xhtml">

<page id="/burada.xhtml" required="false">
<navigation action="#{obj1.doIt}">
<redirect id="/suraya.xhtml">
</redirect>
</navigation>

</navigation>

</page></pages>

JBoss Seam ve Tarih Gostermek

Seam/JSF ile programlarken tarihleri basmak icin h:outputText ekrana bir seyler basacaktir. Fakat goruntude saat kismi da gozukecek (12:34:00 EST vs seklinde) ki bu istedigimiz bir goruntu olmayabilir. Bu goruntuyu istedigimiz gibi cevirttirmek icin Seam/JSF bir Converter tanimlamamiza izin veriyor.

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.ConverterException;

import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.intercept.BypassInterceptors;
import org.jboss.seam.annotations.faces.Converter;
import java.util.Date;

@Name("dateConverter")
@BypassInterceptors
@Converter
public class DateConverter implements javax.faces.convert.Converter
{

public Object getAsObject(javax.faces.context.FacesContext context,
javax.faces.component.UIComponent component,
java.lang.String str) {

return DateUtil.stringToDate(str);
}

public String getAsString(javax.faces.context.FacesContext context,
javax.faces.component.UIComponent component,
java.lang.Object object)
{
final Date date = (Date) object;

return DateUtil.dateToString(date);
}

}

DateUtil.dateToString cagrisi formatlamayi istedigimiz gibi yapmamizi saglayan yardimci metottur. Bu kadar, bu class @Convertor annotation'i kullandigi icin XML karin agrilarina girmeye gerek yok. Kullanmak icin herhangi bir xhtml sayfasinda alttaki kullanim yeterli.

<h:outputText value="#{obj.someDateColumn}"><f:converter converterId="dateConverter"/></h:outputText>

Hibernate ve Tarih Kolonlari

Eger icinde tarih olan tablolari okurken Hibernate (ve JDBC) soyle bir hata veriyorsa,

java.sql.SQLException: Value '0000-00-00' can not be represented as java.sql.Date

Bunun basit bir cozumu persistence.xml deki JDBC URL'e zeroDateTimeBehavior=convertToNull ibaresini eklemektir.

<property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/DB?zeroDateTimeBehavior=convertToNull">

Bunun sonucunda eger Hibernate'in map ettigi kolonda 0000-00-00 gibi bir deger var ise, bu otomatik olarak NULL'a cevirilecektir. Bu degerin oraya konulmasinin sebebi MySQL seviyesinde sema yaratilirken olagan degerin 0000-00-00 birakilmis olmasi cogunlukla, boylece tarih tanimlanmayan INSERT otomatik olarak bu garip degeri atiyor. Cozum DB seviyesinde de yapilabilir muhakkak, ama orada kontrolunuz yok ise, ustteki cozum ise yarar.

Monday, December 22, 2008

Hatali Tarih Saptamak

Eger SimpleDateFormat'i tarih bilgisini String tipinden Date tipine gecmek icin kullaniyorsaniz dikkat: Bu class, eger ozellikle belirtilmezse, herhangi bir gun ve ay bilgisini mutlu bir sekilde (kafasina gore) bir Date'e cevirebiliyor. Hicbir kontrol yapmiyor. Mesela 40-2-2008 tarihi 10 Mart 2008'e donusebiliyor!

Bu hatadan kacinmak icin setLenient(false) cagrisi yapmaniz gerekli. Bizim bu isi yapan DateUtil class'imizdaki metot suna benziyor.

public static Date DMYtoDate(int day, int mon, int year) {

SimpleDateFormat fmt = new SimpleDateFormat("dd-MM-yyyy");
String ds = day + "-" + mon + "-" + year ;
Date date = null;
try {
fmt.setLenient(false);
date = fmt.parse(ds);
} catch (java.text.ParseException e) {
log.error(e);
return null;
}

return date;
}

Bu metot, eger hatali bir tarih varsa, null dondurecektir.

Saturday, December 13, 2008

Ubuntu 8 on Toshiba Satellite u300

This post is in English hoping it can help out a wider audience on Linux compatibility issues. Also see Linux on Laptops page.

I have purchased a sweet little Toshiba Satellite u300 laptop and am running Ubuntu 8 on it; Sound, video worked out of the box.

Wireless caused problems, to get around it, you need to download and install compat-wireless package found here. Before installing this package, the network icon on the upper right corner will not detect any wireless networks, and don't fiddle with anything in the system to get wireless "working" - it won't. Until you install compat-wireless. Get the sources, then "make" "sudo make install" and "sudo make load". After this last step, driver will be loaded, and network icon in upper right corner will change, it will detect and connect to a wireless network. From now on, if you want to load the drivers, you need to run "sudo make load" (I am still looking for a way to make this part of startup without changing startup scripts).

There is a problem with the volume control on the left side of the machine. When you roll the wheel up or down, it gets stuck on changing the volume action and will not yield control to your keyboard. At this point you are screwed, the only thing you can do is rebooting the machine.

My solution is to disable the wheel volume up or down event. Go to System | Preferences | Keyboard Shortcuts and assign "any" key combination to Sound | Volume up and down events. Anything except the X86blabla event. Then you will be set. Make sure you have turned volume all the way up before you do this.

By the way; To shut off the annoying drum, tamtam sound when you login, go to System | Administration | Login Window and to Accesibility tab. There uncheck the sound option for question.wav.

Out of the box, you won't have external display capability. In order to enable TVOUT so you can watch movies, presentation on an external display, you need to enable TwinView.

From cmd prompt, sudo vi /etc/X11/xorg.conf then add the following two lines to your "Section" block in your xorg.conf.

Section "Screen"
...
Option "TwinView"
Option "TVOutFormat" "SVIDEO"
SubSection "Display"
Virtual 1280 800
EndSubSection
EndSection

You need to reboot for external display to take effect everytime you use your external display. When you reconnect, same way, reboot so you get back to your normal display. I am sure there are easier ways to do this, this was easiest way for me with least amount of trial and error.

I will update this post with any other u300 + Linux related problems and solutions.

Wednesday, December 10, 2008

Ubuntu ve Emacs

Ubuntu uzerinde Emacs kullanmak icin once en son paketi kurdurmak gerekiyor;

sudo apt-get install emacs22

Sonra bizim Java JDE ortaminda calismasi icin hazir ettigimiz ve pek cok diger ek araci iceren paketi indirip /usr/share/emacs/22.2/site-lisp/ altinda aciyoruz. Artik tek bir .emacs satiri ile bu dizin altindaki emacs-ubuntu.el dosyasini yuklettirebiliriz. Bu satir soyle olacak;

(load-file "/usr/share/emacs/22.2/site-lisp/emacs-ubuntu.el")

Tuesday, December 9, 2008

Ubuntu'da CAPS Tusunu Control Yapmak

Kabul edelim: Caps Lock tusu fazla bir halta yaramiyor. Bu tusu eger daha cok ise yarayan Control tusu ile degistirmek istiyorsak, alttaki tarif ise yarayabilir.

Once /etc/X11/xorg.conf dosyasina girelim. Bu dosyada degistirmemiz (yoksa eklememiz) gereken ibare soyle:

Section "InputDevice"
Identifier "Generic Keyboard"
Driver "kbd"
Option "CoreKeyboard"
Option "XkbRules" "xorg"
Option "XkbModel" "pc105"
Option "XkbLayout" "us"
Option "XkbOptions" "lv3:ralt_switch, ctrl:nocaps"
EndSection

Bilgisayari tekrar baslattiktan sonra CAPS tusunun artik Control olarak isledigini goreceksiniz.

Monday, November 24, 2008

Firefox Icin SSH Tunelleme

Altta bahsedecegim tunelleme tekniginin 2 yarari var: Birincisi hicbir Internet yasagina takilmadan, istediginiz siteyi gezebilmeniz. Ikincisi, eristiginiz adres ve network trafiginizin guvenli hale gelmesi; Mesela acik ve/ya size ait olmayan bir Internet baglantisindan (cafe'lerdeki WiFi noktalarindan mesela) disari cikiyorsaniz, bu teknik isinize yarayacak.

Teknigin tek dezavantaji, Internet yasagini delmek istiyorsaniz, ulke disinda bir Unix hesabi gerektirmesi. Ama sadece Internet'i guvenli gezmek istiyorsaniz, ulke icinde bir makina da olabilir.

SSH tunelleme teknigi icin once Unix makinaniza baglaniyorsunuz:

ssh -D 8080 -f -C -q -N kullanici@makina

Bunu islettikten sonra komut satiri hemen geri donecek, ama baglantiniz arka planda yapilmis olacak. Ustte lokal makinanin 8080 portunu tunelleme portu olarak tanimladik. Simdi Firefox'a girin ve tum Internet trafiginin bu port uzerinde disari cikmasi icin, gerekli ayarlari yapin. Bunun icin URL kutusuna about:config yazin, bu size gereken ayarlari getirecek. Burada olmasi gerekenler soyle:
  • network.proxy.no_proxies_on : localhost, 127.0.0.1
  • network.proxy.socks : 127.0.0.1
  • network.proxy.socks_port : 8080
  • network.proxy.socks.remote_dns : true
  • network.proxy.socks_version : 5
  • network.proxy.type : 1
Bu kadar. Artik Firefox'un tum istekleri SSH uzerinden Unix makinasina gidecek, ve Internet'te gezinmeyi aslinda bu makina yapacak, ve size sayfa iceriklerini yine SSH uzerinden geri dondurecek. Eger network'unuz "izleniyorsa" sadece sifrelenmis SSH trafigi gorecekler, gittiginiz URL bile belli olmayacak.

Kaynak

Tuesday, October 21, 2008

Ardabot4j

Ardabot4j is an open source autonomous vehicle controller written in Java created to work in the simulated environment USARSim. USARSim also aimed to provide robot developers with basic sensor, visualization, mapping features that sits on top of the popular game Unreal Tournament 2004 physical engine.
Ardabot4j project started as an assignment for Autonomous Robots class.

Ardabot4j is mainly written to work in DM-ARDA map which is a facsimile of the DARPA Urban Challange environment. We installed (soft-install, through a config file) a Tarantula 3D laser scanner which supplied us 3D range data. We then applied vertical scanline detection algorithm to define landmarks which in turn were used to map the environment. Then, using this map, the bot was able to navigate its environment.



Ardabot4j features include a Driver UI which also lets the user drive manually, and lets user observe vertical scanline algorithm at work, real-time. User can toggle scanline visualization on and off using the c key. For manual driving, the keys are e for forward, x for stop, f for right steering and a for left steering.




In Auto-Drive mode, Ardabot4j will take over control of the vehicle and start identifying navigatable locations. These targets will be shown in MapUI visually in green.

Configuration

In order to install Ardabot4j, you must have Unreal Tournament 2004, USARSim and DM-ARDA map installed. See this documentation for more details. Then, in UT2004\System\USARBot.ini file, you make following changes:
[USARBot.RangeScanner3D]
MaxRange=1000.000000
ScanInterval=0.4
VerticalFOV=0.4363
VerticalResolution=0.0145
HorizontalFOV=1.0472
HorizontalResolution=0.0209
...
...
[USARBot.P2AT]
...
Sensors=(ItemClass=class'USARBot.RangeScanner3D',ItemName="TarantulaRangeScanner3D",
Position=(X=0.14399984,Y=0.0,Z=-0.0919999),Direction=(Y=0.1,Z=0.0,X=0.0))
Then, through Ant, you can fire up the UI using ant gui that will automatically connect to localhost port 3000. It is recommended you develop with UT/USARSim in server mode as seen below because gaming mode with full blown view (even when minimized) would eat up too much of your CPU processing power.
ucc server DM-Arda_250?game=USARBot.USARDeathMatch?imeLimit=0?GameStats=False
-ini=USARSim.ini -log=usar_server.log

Downloads

Code Downloads

Ardabot4j
Ardabot4j is an open source autonomous vehicle controller written in Java to work in the simulated environment USARSim.













CmuCam4J

CmuCam4J aimed to create a bridge between AWT-independent image processing, JavaComm and J2ME. It's written to run on the JStamp board which carries a pure Java chip that is able to run Java bytecodes natively. The final code is able to interface to the CmuCam camera using JavaComm, convert the incoming data into a Java matrix which can then be processed by using image processing classes.

Monitor4jmx

Monitor4jmx lets administrators and users of J2EE systems to monitor and observe a JMX enabled system through a easy-to-use user interface. Monitor4jmx can dynamically discover and inspect all MBeans and attributes on these MBeans on a server dynamically at runtime and offer this list for threshold monitoring to the administrator. The attributes selected by the administrator can then be recorded along with a user specified threshold value, which can then be watched by Monitor4jmx continously at certain intervals. Current MBean values are polled continously to find out if any threshold conditions are violated.

Presentations Using LaTeX

The templates shared here are based on the Power4 project kindly shared by Technische Universitat Darmstadt. We made some macro/shortcut additions on this package based on our intensive use of it for educational material preparation.

libSVM Wrapper

Here is a nice little Java wrapper for the libSVM package. libSVM allows reading from file format, our interface allows you to take in array based values and pass them on to libSVM. You can call the code like this;
SVM svm = new SVM();

double [] labels = {1,1,-1,-1};
double [][] values = {{2,2},{4,4},{10,10},{15,15}};
svm.train(labels, values);

double [] test = {13,13};
System.out.println(svm.predict(test));

There is more on Github.