Author Archive

Android tip #1 ContentProvider , Accessing local file system from WebView / showing image in webview using content://

ok, this was a tough one.
First be informed that this is something Google (Android people) are trying to prevent i.e. letting browser (WebView) have access to the local file system. In earlier releases of SDK you could access local files using ‘file://’ but it is stopped now. Then there was an option where you can provide a WebViewClient and implement shouldOverrideUrlLoading to make it work. This was also removed.
The way to make it work now is by implementing your own ContentProvider, there is lot of discussion and documentation on implementing ContentProvider but all that is completely redundant (not needed). The solution is very simple, create your own ContentProvider and only override

public android.os.ParcelFileDescriptor openFile(android.net.Uri uri, java.lang.String mode) throws java.io.FileNotFoundException

Rest of the code in ContentProvder is not needed for this problem.

Step 1:
Declare your Content Provider in AndroidManifest.xml

<provider android:name="MyDataContentProvider"  android:authorities="com.techjini" />

Step 2:
Create your ContentProvider and implement openFile
All you have to do is get real path from uri, open it and return the descriptor

URI uri = URI.create("file:///data/data/com.techjini/files/myImage.jpeg");
File file = new File(uri);
ParcelFileDescriptor parcel = ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY);
return parcel;

Step 3:
(You need this step only if file is not already present on the device/sdcard)
Save your content to the file. Following is an example to store a Bitmap

FileOutputStream fos = openFileOutput("myImage.jpeg", Activity.MODE_WORLD_WRITEABLE);
imageView.getBitmap().compress(Bitmap.CompressFormat.JPEG, 100, fos);

fos.flush();
fos.close();

You can find out where your image is stored using

System.out.println(getFilesDir().getAbsolutePath());

Step 4:
Access the file in WebView

myWebView.loadUrl("content://com.techjini/myImage.jpeg");
//com.techjini is what you mentioned in 'android:authorities' in your AndroidManifest.xml

Looks simple :)


MySql tip #2 Taking backup ensuring multi byte characters does not become garbage

If you have multi byte data in your tables its important to take backup in utf8 which can be done using the command below:

mysqldump -u root --default-character-set=utf8 DB_NAME | gzip > DB_NAME-`date +%Y%m%d%H%M`.sql.gz

The date parameter simply appends date/time to the backup.

In order to restore the backup taken above use following command

gunzip < FILE_NAME.sql.gz | mysql --default-character-set=utf8 -u root DB_NAME

This will ensure that db is back up without affecting multi byte data.


JBoss tip #5 Keeping the project in exploded .war file in some other location other than deploy folder

This is how you can increase your productivity while developing an app on Jboss, no need to package and deploy again and again, reduced development and testing time.

Open %JBOS_HOME%\server\default\conf\jboss-service.xml and add the new location

    <attribute name="URLs">
        deploy/, E:/ file:/var/opt/apps/
     </attribute>
1 Comment more...

JBoss tip #4 Increasing the jta time out from default 5 mins to more

Open %JBOSS-HOME%\server\default\conf\jboss-service.xml


name="jboss:service=TransactionManager">
3600
${jboss.server.data.dir}/tx-object-store

[/sourcecode language='css']

3600
[/sourcecode language='css'] by default it would be 300, here we changed it to 3600 which is 1 hr.


MySQL tip #1 How to find size of a mysql database

In order to find size of your mysql databases you can run following sql querry:

SELECT table_schema "Data Base Name", sum( data_length + index_length ) / 1024 / 1024 "Data Base Size in MB"
FROM information_schema.TABLES GROUP BY table_schema ;

Divide it by further 1024 to get it in GB.

For more information read about INFORMATION_SCHEMA

1 Comment more...

JBoss tip #3 Accessing the application out side the local machine

Open %JBOSS_HOME%\server\default\deploy\jboss-web.deployer\server.xml and change the address to “0.0.0.0″

     <Connector port="8081" address="0.0.0.0" maxThreads="250" maxHttpHeaderSize="8192"
        emptySessionPath="true" protocol="HTTP/1.1"
        enableLookups="false" redirectPort="8443" acceptCount="100"
        connectionTimeout="20000" disableUploadTimeout="true" />

Jboss tip #2 Changing the default port number 8080 to some other port

Open %JBOSS_HOME%\server\default\deploy\jboss-web.deployer\server.xml and change the port as per your requirement.

<Connector port="8081" address="0.0.0.0" maxThreads="250" maxHttpHeaderSize="8192"
        emptySessionPath="true" protocol="HTTP/1.1"
        enableLookups="false" redirectPort="8443" acceptCount="100"
        connectionTimeout="20000" disableUploadTimeout="true" />

Jboss tip #1 Connection Pooling And DataSource creation

Which ever data source you create (for instance lets say for oracle data source or mysql data source ) file name should end with “name-ds.xml” and the content should be

<?xml version="1.0" encoding="UTF-8"?>

   <datasources>
         <local-tx-datasource>
           <jndi-name>tjOracleDS</jndi-name>
            <use-java-context>false</use-java-context>
                   <connection-url>jdbc:oracle:thin:@localhost:1521:tjdb</connection-url>
                   <driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
                     <user-name>staging</user-name>
                   <password>staging</password>
                    <exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.OracleExceptionSorter</exception-sorter-class-name>
                        <min-pool-size>5</min-pool-size>
                   <max-pool-size>30</max-pool-size>
                   <blocking-timeout-millis>5000</blocking-timeout-millis>

                 <metadata>
                    <type-mapping>Oracle9i</type-mapping>
                 </metadata>
         </local-tx-datasource>

       </datasources>
<use-java-context>false</use-java-context>   

This help us to remove java:comp from jndi look up for data source


Linux applications to make life easier

  • bash-completion
    If you know what the command does but dont remember the options this will be really helpful. You wont have to open man everytime. Just put a’ ‘-’ or ‘–’ and press tab. for eg. javac – will list following:

    
    ~$ javac -
    -bootclasspath   -extdirs      -g:vars        -sourcepath
    -classpath         -g              -help           -target
    -d                     -g:lines      -nowarn       -verbose
    -deprecation      -g:none      -O
    -encoding          -g:source   -source
    
  • tomboy
    Tomboy is a desktop note-taking application for Linux and Unix. Simple and easy to use, but with potential to help you organize the ideas and information you deal with every day. – copied from site
  • Firefox
    Browser – duh!!
  • Thunderbird
    Email Client
  • ies4linux
    Run IE from linux…well we all need to test site for most widely used browser.
  • pidgin
    Muli protocol (What they call universal) chat (IM) client. Support yahoo, msn, gtalk, irc, xampp and lot more.
  • XChat
    XChat is an IRC chat program for both Linux and Windows. It allows you to join multiple IRC channels (chat rooms) at the same time, talk publicly, private one-on-one conversations etc. Even file transfers are possible. - copied from site
  • unison
    Unison is a file-synchronization tool for Unix and Windows. It allows two replicas of a collection of files and directories to be stored on different hosts (or different disks on the same host), modified separately, and then brought up to date by propagating the changes in each replica to the other. – copied from site
  • timer-applet
    Very useful to run simple timers. Very helpful if you are working against time and want to track how much time is left.
  • hamachi and gHamachi
    LogMeIn Hamachi is a VPN service that easily sets up in 10 minutes, and enables secure remote access to your business network, anywhere there’s an Internet connection. – copied from site. Not free, you need to pay for commercial use.
    gHamachi is GUI for hamachi. Although using hamachi from command line is also pretty simple but this tool makes it even more ‘user friendly’
  • skype
  • gFtp / filezilla
    For all your ftp needs
  • Transmission
    For all your piracy needs :) sorry bit toorents
  • nm-applet
    Not sure if I need to mention here, this has to be there by default. Network Manager, applet. Can’t do without it.
  • Revelation / keypassx
    Password managers. Both are very very good and it requires a separate article to compare them.
  • gimp / Inkscape
  • openoffice
  • regexxer
    regexxer is a nifty GUI search/replace tool featuring Perl-style regular expressions. If you need project-wide substitution and you’re tired of hacking sed command lines together, then you should definitely give it a try. – copied rom site
  • Meld
    Meld is a visual diff and merge tool. You can compare two or three files and edit them in place (diffs update dynamically). You can compare two or three folders and launch file comparisons. You can browse and view a working copy from popular version control systems such such as CVS, Subversion, Bazaar-ng and Mercurial. – copied from site
  • Mysql Administrator
  • Mysql query browser
  • Mysql Workbench
    Very nice tool for creating DB models
  • vlc / mplayer / rhythmbox
    Media (music / video) players
  • synaptic package manager / GDebi Package installer
  • CHM Viewer / chmsee / gnochm
  • Gmail Notifiers
    Given gmail’s popularity, you might want to know about these too gmail-notify, gmailfs, kcheckgmail, kgmailnotifier, cgmail, checkgmail
  • gscan2pdf
1 Comment more...

tip: Single symfony project serving multiple domains via separate apps

Problem: You have a symfony project with 2 applications ‘customers’ and ‘resellers’. You want www.myretail.com to use ‘customer’ application and www.myresellers.com to use ‘resellers’ application.

here customers app is your default ‘frontend’ app with index.php and resellers app has say ‘reseller.php’ and ‘reseller_dev.php’ controller files.

Solution:
Separate the web folder for each domain you want handle.

so customers content is in /project/web folder and resellers content is in /project/web-reseller/ folder. Move your reseller.php to web-reseller folder and rename it to index.php

You will need to create two virtual host for each domain with document root pointing to their respective folders.

Another solution is to have different .htaccess files. In case you do not want to create separate web folder you can create another .htaccess_reseller file in the web/ folder and redirect all request to reseller.php instead of index.php

1 Comment more...

© Copyright 2009 TechJini Solutions Private Limited. All Rights Reserved
iDream theme by Templates Next | Powered by WordPress