15 Eylül 2011 Perşembe

bibsonomy

BibSonomy (http://www.bibsonomy.org/) is a successful bookmarking and publication sharing system.. In fact, i use the site to gather bibtex format reference entries..

13 Eylül 2011 Salı

logging the stacktrace

logging the stacktrace with log4j:


import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;

// ......
static Logger logger = Logger.getLogger(MyClass.class);

// ......
public static void debugException(Exception ex) {
    //ex.printStackTrace();
    logger.error("An error occurred in MyClass.", ex);
}

frames in Latex

in order to print text inside a frame:



 \centering
    \fbox{
    \begin{minipage}{1.0\linewidth}
    The text that will be printed in frame goes here..
    \end{minipage}
    }



a few tips here: http://www.personal.ceu.hu/tex/spacebox.htm
http://en.wikibooks.org/wiki/LaTeX/Advanced_Topics
http://chenfuture.wordpress.com/2007/06/22/frames/

proguard ant task

proguard (http://proguard.sourceforge.net/) promises for  the following:

  • Creating more compact code, for smaller code archives, faster transfer across networks, faster loading, and smaller memory footprints.
  • Making programs and libraries harder to reverse-engineer.
  • Listing dead code, so it can be removed from the source code.
  • Retargeting and preverifying existing class files for Java 6, to take full advantage of Java 6's faster class loading.

here is code sample:
<target name="proguard" depends="jar">
<taskdef resource="proguard/ant/task.properties" classpath="${lib}/proguard-4.4.jar" />
<proguard configuration="${config}/obfuscate.pro">
<injar file="${build.dir}/prod.jar" />
<outjar file="${build.dir}/prod_obf.jar" />
<libraryjar refid="externals" />
</proguard>
</target>

checkstyle ant task

checkstyle (http://checkstyle.sourceforge.net/) is a tool that hels java code to adhere to coding standards.

for checkstyle ant task: http://checkstyle.sourceforge.net/anttask.html



<property name="build.checkstyle.config" value="${config}/sun_checks.xml" />
<property name="build.checkstyle.output" value="${build.dir}/checkstyle_report.xml" />


<path id="checkstyle.classpath">
<pathelement location="${lib}/checkstyle-5.3.jar" />
<pathelement location="${lib}/google-collections-1.0.jar" />
<pathelement location="${lib}/commons-beanutils-core-1.8.3.jar" />
<pathelement location="${lib}/commons-logging-1.1.1.jar" />
<pathelement location="${lib}/antlr-2.7.7.jar" />
</path>


<target name="checkstyle" depends="init">
<taskdef resource="checkstyletask.properties" classpathref="checkstyle.classpath" />
<checkstyle failOnViolation="false" config="${build.checkstyle.config}">
<fileset dir="${src.dir}">
<include name="**/*.java" />
</fileset>
<formatter type="xml" tofile="${build.checkstyle.output}" />
</checkstyle>
</target>



about sun-checks.xml configuration file: http://checkstyle.sourceforge.net/config.html
here is a sample config file: http://code.google.com/p/checkstyle-idea/source/browse/trunk/src/main/resources/sun_checks.xml?r=120

cobertura ant task

cobertura (http://cobertura.sourceforge.net/) is a coverage analysis tool which reports what percentage of source code is covered by unit tests.

for cobertura ant task: http://cobertura.sourceforge.net/anttaskreference.html

and here is code sample:


<property name="build.coverage.datafile" value="${build.coverage}/cobertura.ser" />


<path id="instrument.classpath">
<pathelement location="${build.classes}" />
</path>


<path id="cobertura.classpath">
<pathelement location="cobertura-1.9.4.1.jar" />
<pathelement location="log4j-1.2.4.jar" />
<pathelement location="oro-2.0.8.jar" />
<pathelement location="asm-3.0.jar" />
<pathelement location="asm-tree-3.0.jar" />
</path>


<target name="instrument" depends="compile-test">
<taskdef classpathref="cobertura.classpath" resource="tasks.properties" />
<cobertura-instrument todir="${build.instrumented}" datafile="${build.coverage.datafile}">
<includeClasses regex=".*" />
<instrumentationClasspath>
<path refid="instrument.classpath" />
</instrumentationClasspath>
</cobertura-instrument>
</target>



<target name="test" depends="compile-test, instrument">
<junit ..;>
...
<sysproperty key="net.sourceforge.cobertura.datafile" file="${build.coverage.datafile}" />
..
</junit>
</target>

<target name="coverage" depends="test">
<taskdef classpathref="cobertura.classpath" resource="tasks.properties" />
<cobertura-report format="xml" destdir="${build.coverage}" srcdir="${src.dir}" datafile="${build.coverage.datafile}" />
<cobertura-check haltonfailure="false" datafile="${build.coverage.datafile}" />
</target>

12 Eylül 2011 Pazartesi

findbugs ant task

Findbugs is a static analysis tool that finds existing bugs in java code. Here is a link on how to use it from ant script: http://findbugs.sourceforge.net/manual/anttask.html

and code sample is as follows:



<property name="findbugs.home" value="/home/hilal.tarakci/Desktop/htarakci/environment/other/findbugs-1.3.9"/>
<target name="findbugs-define">
<taskdef name="findbugs" classname="edu.umd.cs.findbugs.anttask.FindBugsTask">
<classpath path="${findbugs.home}/lib/findbugs.jar" />
</taskdef>
<!-- ensure that findbugs taskdef is only run once, otw ant will error -->
<property name="findbugs.initialized" value="true" />
</target>
<target name="findbugs" if="findbugs.present" depends="findbugs-define, jar" description="Run findbugs">
<findbugs output="xml:withMessages" home="${findbugs.home}" effort="max" outputFile="${build.dir}/findbugs.report.xml">
<auxClasspath>
<fileset dir="${ivy.lib}">
<include name="**/*.jar" />
<exclude name="**/ivy-*.jar" />
</fileset>
</auxClasspath>
<sourcePath path="${src.dir}" />
<class location="${build.dir}/${final.name}.jar" />
</findbugs>
<xslt style="${findbugs.home}/src/xsl/fancy-hist.xsl" in="${build.dir}/findbugs.report.xml" out="${build.dir}/findbugs.report.html" />
</target>


commenting multiple lines in Latex

In order to comment multiple lines in Latex:

\usepackage{verbatim} 


\begin{comment}
this line is commented out.
this one too..
\end{comment}


to comment out just one single line:

% only this line is commented out.


11 Eylül 2011 Pazar

printing special characters in Latex

In order to print the following special characters in Latex output, simply put a \ in front of the char..


 # $ % & ~ _ ^ \ { }


more on http://www.tug.org/tutorials/latex2e/Special_Characters.html

9 Eylül 2011 Cuma

URL in Latex

I can be considered as a Latex newbie, so i try to write a post on every new piece of information about how to use Latex.
Here is sample code for using URLs in Latex:
.tex file


\documentclass{article}
\usepackage[pdftex]{graphicx}
\usepackage{url}
\usepackage{hyperref}


\begin{document}


\title{Some Notes}
\author{Author's Name}


\maketitle


\begin{abstract}
\end{abstract}


\section{Some Notes}


\subsection{Blog}
\href{http://hilaltarakci.blogspot.com}{Hilal Tarakci Blog Page}


\cite{Tarakci2011}


\bibliographystyle{unsrt}
\bibliography{blogreferences}
\end{document} 



blogreferences.bib file


@misc{
    Tarakci2011,
    author = "Hilal Tarakci",
    title = "Hilal Tarakci Technical Page",
    howpublished = "Website",
    year = {2011},
    note = {\url{http://hilaltarakci.blogspot.com/}}
}



and the output is as follows:

7 Eylül 2011 Çarşamba

mockito


Mockito is a mocking framework that can be downloaded from http://code.google.com/p/mockito/

An article about mockito:
http://gojko.net/2009/10/23/mockito-in-six-easy-examples/
quote from that article

To create a stub (or a mock), use mock(class). Then use when(mock).thenReturn(value) to specify the stub value for a method. If you specify more than one value, they will be returned in sequence until the last one is used, after which point the last specified value gets returned. (So to have a method return the same value always, just specify it once).

Code samples on that blog are adequate, so i will not reinvent the wheel with more examples..