Intermediate

10 Object Oriented Design Principles

OO LogoEvery now and then when I review code, I see developers write code that does not conform to the basis OO design principles and this eventually make it difficult to understand, maintain, extend blah blah..... Basically its just keeps on adding a layer of un-necessary complexity that you have to deal with. So what do you do? I guess you end-up refactoring the code( Did I said, I love refactoring?

How to get the Temp Directory Path in Java?

Java LogoThe path to the temp directory in Java can be retreived via the sytem property as mentioned below:

System.getProperty("java.io.tmpdir");

Find the Calling Class

Here is a simple snippet to find out the calling Java Class.

Class.forName(new Throwable().getStackTrace()[2].getClassName()));

Compute size of Mysql database with it's tables

Basically a database is a collection of tables.
So the size of the database is sum total of size of its individual tables.
Size of the table = Size of its Data + Size of its Indexes.
Size of database = Sum of {Individual Table Size}
The following snippet uses that above logic to compute the overall size of the database by computing the size of its individual tables.

How to do view all the triggers in a schema?

Yes, you can view triggers using the INFORMATION_SCHEMA.TRIGGERS table. The following sql list all the triggers in a given schema.

select

SEQUENCE_NAME,MIN_VALUE,MAX_value,LAST_NUMBER,length(LAST_NUMBER)

from dba_sequences

where SEQUENCE_OWNER='schema owner'

order by length(LAST_NUMBER) desc

How to view all Stored Procedures in a schema?

The following sql list the name of all the routines in a given database.

SELECT ROUTINE_NAME

FROM INFORMATION_SCHEMA.ROUTINES

WHERE ROUTINE_TYPE="PROCEDURE" AND ROUTINE_SCHEMA="dbname";

How to convert ISAM table to MYISAM?

The table types have changed from ISAM to MYISAM from Mysql version 4.x to 5.x.

In order to convert a table from ISAM to MyISAM, simply issue a statement like

ALTER TABLE tblname ENGINE=MYISAM.

How do I import a MySQL dumpfile into my database?

Data can be dumped into the database using the following command. mysql -p -h DBSERVER dbname < dbname.sql

 

Recursively Convert Gif Images To Jpg

Converting images from gif to jpg for web or other reason can be done easily using the ImageIO package. The following snippet convert all the gif images in directory rootDir to jpg images.Compile this class and execute using java command line. This utility class is also available as part of the Livrona Tools Project.The following is the code for the Image Converter.

 

Clean up Rail Sessions

By default rails does not clear out stale sessions from the session store. Depending on the configuration session can be stored in the local file system or the database.

Syndicate content

Back to top