Tuesday, December 16, 2014

Fetch mp3 from websites

Fetch mp3 from websites:

wget -r -l1 -H -t1 -nd -N -np -A.mp3 -erobots=off [url of website]
Options meaning:
-r            recursive
-l1           maximum recursion depth (1=use only this directory)
-H            span hosts (visit other hosts in the recursion)
-t1           Number of retries
-nd           Don't make new directories, put downloaded files in this one
-N            turn on timestamping
-A.mp3        download only mp3s
-erobots=off  execute "robots.off" as if it were a part of .wgetrc

Thursday, October 23, 2014

Friday, April 25, 2014

Thursday, October 17, 2013

Need to test email notification functionality in enterprise app 
without using QA or Prod mail server,Need to use email functionality without problems in SMTP configuration, we can use the below approach.

Please find the step by step guide to configure hmail server(http://www.hmailserver.com) in our local machines to test email functionalities whenever needed at the below link.


email.server.host=localhost
email.server.port=25


Thursday, April 26, 2012

My First VB Script to rename folder names

My First VB Script to rename folder names.

This script helped to rename and arrange movie files and movie folders in external hard disk.


Set objFS = CreateObject("Scripting.FileSystemObject")
strFolder = "i:\Movies"
Set objFolder = objFS.GetFolder(strFolder)
For Each Folder In objFolder.SubFolders
strFolderName = Folder.Name
if InStr(strFolderName,"[DVD~RIP]") <> 0 Then
WScript.StdOut.WriteLine "Inside if"
WScript.StdOut.WriteLine strFolderName
strFolderName = Replace(strFolderName, "[DVD~RIP]", "")
Folder.Name=strFolderName
End If
Next

Tuesday, March 29, 2011

Way to reverse a Queue in Java

Sample class to explain reversing a queue using recursion:

public class Demo {
public static void main(String[] args){
Queue queue = new LinkedList();
for(int i=0;i<10;i++){
if(queue.size()==4){
queue.poll();
queue.add(i);
}else{
queue.add(i);
}
}
System.out.println(queue);
Demo demo =new Demo();
demo.dequeue(queue);
System.out.println(queue);
}

private void dequeue(Queue queue){
if(queue.size()!=0){
int i=(Integer)queue.poll();
dequeue(queue);
queue.add(i);
}
}
}

Wednesday, January 6, 2010

Serialization Version issues and Best Practices

Do not implement Serializable lightly, since it restricts future flexibility, and publicly exposes class implementation details which are usually private. As well, implementing Serializable correctly is not trivial.

The serialVersionUID is a universal version identifier for a Serializable class. Deserialization uses this number to ensure that a loaded class corresponds exactly to a serialized object. If no match is found, then an InvalidClassException is thrown.

Guidelines for serialVersionUID :

  • always include it as a field, for example: "private static final long serialVersionUID = 7526472295622776147L; " include this field even in the first version of the class, as a reminder of its importance
  • do not change the value of this field in future versions, unless you are knowingly making changes to the class which will render it incompatible with old serialized objects
  • new versions of Serializable classes may or may not be able to read old serialized objects; it depends upon the nature of the change; provide a pointer to Sun's guidelines for what constitutes a compatible change, as a convenience to future maintainers
In Windows, generate serialVersionUID using the JDK's graphical tool like so :
  • use Control Panel | System | Environment to set the classpath to the correct directory
  • run serialver -show from the command line
  • point the tool to the class file including the package, for example, finance.stock.Account - without the .class
readObject and writeObject :
  • readObject implementations always start by calling default methods
  • deserialization must be treated as any constructor : validate the object state at the end of deserializing - this implies that readObject should almost always be implemented in Serializable classes, such that this validation is performed.
  • deserialization must be treated as any constructor : if constructors make defensive copies for mutable object fields, so must readObject
  • when serializing a Collection, store the number of objects in the Collection as well, and use this number to read them back in upon deserialization; avoid tricks using null
Other points :
  • use javadoc's @serial tag to denote Serializable fields
  • the .ser extension is conventionally used for files representing serialized objects
  • no static or transient fields undergo default serialization
  • extendable classes should not be Serializable, unless necessary
  • inner classes should rarely, if ever, implement Serializable
  • container classes should usually follow the style of Hashtable, which implements Serializable by storing keys and values, as opposed to a large hash table data structure
Example in code:
  * Maintainers must change this value if and only if the new version
* of this class is not compatible with old versions. See Sun docs
* for * /serialization/spec/version.doc.html> details.
*
* Not necessary to include in first version of the class, but
* included here as a reminder of its importance.
*/

private static final long serialVersionUID = 7526471155622776147L;

Followers