Debian - Display the total memory (RAM) on the Linux system

#cat /proc/meminfo
MemTotal:      2076452 kB
MemFree:         87404 kB
Buffers:          7844 kB
Cached:        1899844 kB
SwapCached:          0 kB
Active:         102824 kB
Inactive:      1864888 kB
HighTotal:     1179584 kB
HighFree:        36952 kB
LowTotal:       896868 kB
LowFree:         50452 kB
SwapTotal:     5245180 kB
SwapFree:      5245060 kB
Dirty:             224 kB
Writeback:           0 kB
AnonPages:       60024 kB
Mapped:          37012 kB
Slab:            11408 kB
SReclaimable:     7776 kB
SUnreclaim:       3632 kB

Java - List files from a directory

/**
 * List files from a directory.
 * @author Xuan Ngo
 */
import java.io.File;
 
public class ListFilesFromDirectory
{
  public static void main(String[] args)
  {
    String sDirectoryPath = "mydirectorypath";
    File oDirectory = new File(sDirectoryPath);
    if(oDirectory.isDirectory())
    {
      File[] aFiles = oDirectory.listFiles();
      for(int i=0; i<aFiles.length; i++)
      {
        System.out.println(aFiles[i].getPath());
      }
    }
    else
    {
      System.out.println(sDirectoryPath+" is not a directory.");
    }
  }
 
}

Java - Write text to file

/**
 * Show how to write text to file.
 * @author Xuan Ngo
 */
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
 
public class WriteToFile
{
  public static void main(String[] args)
  {
    try
    {
      FileWriter oFileWriter = new FileWriter("filename.txt");
      BufferedWriter oBufferedWriter = new BufferedWriter(oFileWriter);
      oBufferedWriter.write("Java");
      oBufferedWriter.close();
    }
    catch(IOException ex)
    {
      System.out.println(ex.getMessage());
    } 
  }
 
}

Drupal - Memory limit

If you are getting "Allowed memory size of 134217728 bytes exhausted (tried to allocate 35 bytes)", then increase memory_limit variable in php.ini.

XSLT - xmllint

# Validate xml using XSD file.
xmllint --noout --schema yourSchema.xsd yourXmlFile.xml >> results.log 2>&1

Bash - Redirection

#Redirect stdout and stderr to a file
yourCommandName &> toFile.log
 
# Redirect and append both stdout and stderr to a file.
yourCommandName >> toFile.log 2>&1

Debian - Tar

#Compress to *.tar.gz
tar -zcvf archive_name.tar.gz directory_to_compress

Ant - Built-in Properties

basedir             the absolute path of the project's basedir (as set
                    with the basedir attribute of <project>).
ant.file            the absolute path of the buildfile.
ant.version         the version of Ant
ant.project.name    the name of the project that is currently executing;
                    it is set in the name attribute of <project>.
ant.java.version    the JVM version Ant detected; currently it can hold
                    the values "1.2", "1.3", "1.4" and "1.5".

Ant - Send email

If you are adding attachments to your email and you are getting the error message "Failed to initialise MIME mail: javax/mail/MessagingException", then download JavaMail API(mail.jar) and JavaBeans Activation Framework(activation.jar) and copy them in the lib/ folder of Ant.

<target name="run_testng" >
  <testng failureProperty="test.failed">
    <!-- ... -->
  </testng>
</target>
<!-- test.failed value come from <testng>. The target sendMail will be executed only if test.failed is true. Therefore, email will be sent only if the test failed. -->

Varia - Mantisbt Administrator's password

The default Administrator password is root.

Syndicate content