Sunday, August 11, 2013

generic .htaccess

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

Friday, July 5, 2013

URI is not hierarchical - Java

There are some problems when running the build jar of your project compare to running it in an IDE, when resources such as images is called within the build jar, usually we just use getClass#getResource("path/of/the/image.jpg") in the IDE, and when you build the project and execute the jar the "URI is not hierarchical" is thrown. One way to fix this is retrieve it as a resource-stream like.

InputStream dx = this.getClass().getResourceAsStream("/com/sample/images/default_image.png");
Image sm = ImageIO.read(dx).getScaledInstance(width, height, Image.SCALE_SMOOTH);

You can then us the Image in any component.

Wednesday, May 8, 2013

Enable localhost phpmyadmin to login

Set the config.php under phpmyadmin folder to this


Catch ConstraintViolationException in Hibernate and get the Error message

I am developing a Java desktop app and I'm using Hibernate on it. In the documentation of Session#save() it only returns Serializable and I have to get a response object when it throws an exception during save call. Heres what I did.

I enclose it with a try catch, and when it receives an exception just get the ConstraintViolationException#getMessage(1) object of it. You can directly return the Object or encapsulate it with your custom object.


Tuesday, November 13, 2012

Options Menu won't show in ICS(Ice Cream Sandwich)

I am developing an application in android and decided to code at the options menu, to add some preferences/settings. As I want to see the output of my code, I notice that the options menu isn't showing, no matter how I override the onCreateOptionsMenu(..), and decided to hit google. This link gives the ANSWER.

You must change the targetSdkVersion to <= 10 in the manifest.xml, and run the code again, and successfully the options menu showed.

Friday, November 2, 2012

Access Denied for phpmyadmin in XAMPP 1.8.1 - Ubuntu

I installed the XAMPP 1.8.1 for linux in my ubuntu and ran http://localhost/phpmyadmin, and suddenly it gives an error Access Denied! Really in my localhost? yeah!

The Fix:

  1. Navigate to the file "httpd-xampp.conf" mine is "/opt/lampp/etc/extra/httpd-xampp.conf"
  2. Add "Require all granted" to this block of code
    #
    
        AllowOverride AuthConfig Limit
        Order allow,deny
        Allow from all
    
    #
    
  3. The result will be
    #
    
        AllowOverride AuthConfig Limit
        Order allow,deny
        Allow from all
        Require all granted
    
    #
    
  4. Then restart your lampp
    #
    sudo /opt/lampp/lampp restart
    #
    

Thursday, November 1, 2012

Manual Install Eclipse - Ubuntu

I'm tired of searching in the internet on how to manually install eclipse. I am not using the Ubuntu Software Center to download eclipse because I want the Eclipse Helios to be installed.


  1. Download the Eclipse Helios. You can download any package you want. I downloaded the eclipse-jee-helios-linux-gtk.tar.gz 
  2. Extract and copy it to the /opt directory
    
    sudo tar -vxzf eclipse-SDK-3.7-linux-gtk-x86_64.tar.gz -C /opt
    cd /opt
    sudo chown -R root:root eclipse
    sudo chmod -R +r eclipse
    
    
  3. You can also change the root:root to user:user
  4. Create an executable
    sudo touch /usr/bin/eclipse
    sudo chmod 755 /usr/bin/eclipse
    sudo gedit /usr/bin/eclipse
  5. Paste this to gedit and save
    #!/bin/sh
    #export MOZILLA_FIVE_HOME="/usr/lib/mozilla/"
    export ECLIPSE_HOME="/opt/eclipse"
    
    $ECLIPSE_HOME/eclipse $*
    
  6. Create a shortcut
    sudo gedit /usr/share/applications/eclipse.desktop
    
  7. Paste to gedit
    [Desktop Entry]
    Encoding=UTF-8
    Name=Eclipse
    Comment=Eclipse IDE
    Exec=eclipse
    Icon=/opt/eclipse/icon.xpm
    Terminal=false
    Type=Application
    Categories=GNOME;Application;Development;
    StartupNotify=true
    
  8. And launch Eclipse for the first time
    sudo eclipse/eclipse -clean