Mathematical constant e generator in Java

Java — Dillon @ 11:59 pm

A small class to generate the mathematical constant “e”. Complete with timer and digits per second clock. Unpolished. Here’s a quick benchmark and you can see that it doesn’t scale.

import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Date;

/**
* calculate mathmatical constant e
*/

public class ECalculator {
private static final int numberOfDigits = 1000;
public static void main(String[] args) {
ECalculator myEClass = new ECalculator();
System.out.println("Calculating e to " + numberOfDigits + " digits ...\n");
Date start = new Date();
BigDecimal e = myEClass.doCalculation();
Date stop = new Date();
long elapsedSeconds = (stop.getTime()-start.getTime()) / 1000;
System.out.println("e is: \n" + e);
if (elapsedSeconds

Made useful build.xml file for use with Ant

Java — Dillon @ 12:30 am

The following build.xml file has a few targets that make compiling a project much simplier. Read on for more details.

I have the following directory structure:

(chris@hobbes)-(BackupLink)$ ls -l
total 20
drwxrwxr-x    3 chris    chris        4096 Apr 21 00:07 bin
-rw-rw-r--    1 chris    chris        2776 Apr 21 00:15 Build.xml
drwxrwxr-x    2 chris    chris        4096 Apr 13 19:07 CVS
drwxrwxr-x    2 chris    chris        4096 Apr 20 14:32 include
drwxrwxr-x    4 chris    chris        4096 Apr 21 00:06 src

In Eclipse, I set the project preference to make [project root]/src the only folder on the source path. Lastly, I set bin to be the output folder. The ant script grabs any jars out of include (mostly useless to me).

When I want to create a jar, I just run the jar target. I removes the java source files before creating the jar archive. You can also increment the version number to create ‘releases’. This is the best I can come up with right now.

<?xml version='1.0'?>

<project name="BackupLink" default="jar" basedir=".">
	<!-- set global properties for this build -->
	<property name="version" value="0.1" />
	<property name="src" value="src"/>
	<property name="build" value="build"/>
	<property name="jarname" value="backUplink.${version}.jar"/>
	<property name="docs" value="docs"/>
	<property name="include" value="include"/>
	<property name="lib"  value="lib"/>
	<property name="runclass" value="com.squarism.backUplink.BackUplink"/>
	<property name="classpath"  value="classes"/>
	<target name="init">
	    <!-- Create the build directory structure used by compile -->
	    <mkdir dir="${build}" />
	    <mkdir dir="${build}/classes" />
		<!-- Create the directory for the jar file -->
	    <mkdir dir="${lib}" />
		<!-- Create the directory for the java docs -->
	    <mkdir dir="${docs}" />
	</target>
	<target name="compile" depends="init">
		<!-- copy all .java files from ${src} to ${build}  -->
		<copy todir="${build}/">
			<fileset dir="${src}" />
			<!-- apply a substitution @version@ with the value of ${version} -->
			<filterset>
				<filter token="version" value="${version}"/>
			</filterset>
		</copy>
		<!-- run javac to compile the source files -->
		<javac srcdir="${build}" destdir="${build}">
			<classpath>
				<!-- use the value of the ${classpath} property in the classpath -->
				<pathelement path="${classpath}"/>
				<!-- include all jar files  -->
				<fileset dir="${include}">
					<include name="**/*.jar"/>
				</fileset>
			</classpath>
		</javac>
	</target>
	<target name="jar" depends="compile">
		<delete>
			<fileset dir="${build}" includes="**/*.java"></fileset>
		</delete>
	    <!-- make a jar file -->
	    <jar jarfile="${lib}/${jarname}" basedir="${build}" manifest="${build}/manifest" />
	</target>
	<target name="run" depends="jar,docs">
		<!-- run the class -->
		<java classname="${runclass}">
			<!-- add a command line arg: <arg value="-h"/> -->
			<classpath>
				<!-- use the value of the ${classpath} property in the classpath -->
				<pathelement path="${classpath}"/>
				<!-- include all jar files  -->
				<fileset dir="${include}">
					<include name="**/*.jar"/>
				</fileset>
				<fileset dir="${lib}">
					<include name="**/*.jar"/>
				</fileset>
			</classpath>
       </java>
	</target>
	<target name="docs" depends="compile">
		<!-- create javadocs -->
		<javadoc packagenames="com.squarism.backUplink.*"
		sourcepath="${build}"
		defaultexcludes="yes"
		destdir="${docs}"
		author="true"
		version="true"
		use="true"
		windowtitle="BackUplink API Documentation Version: ${version}">
		</javadoc>
	</target>
	<target name="clean">
		<delete dir="${build}"/>
		<delete dir="${docs}"/>
		<delete dir="${lib}"/>
	</target>
</project>

A nice bash prompt

Unix — Dillon @ 3:14 pm

Throw this into your /etc/bashrc for all users to pick up this more interesting bash prompt. If you just want to test it out on a single user’s profile, add to ~/.bashrc (at the end is good).
(more…)

Misc Hackings

News — Dillon @ 3:35 am

Played around with Opera 7.1. Very nice rendering, but a little buggy. Horrible mail client. Uninstalled all older versions of Mozilla on my workstation and went with Mozilla 1.4a. Was an adventure.

Got rid of evolution. Love it, but it’s not GTK2 yet. The GTK2 beta is too unstable. It’s a shame because GTK2 rules.

Got some more functionality working on my side project “backUplink” which is a utility for Introversion’s hacking game “Uplink”. It backs up your character so you don’t lose your entire character. Very close to done.

Read on to see the Java source code to an Application Preferences storage class.

(more…)

10 Friggin Useful Linux Tips

Unix — Dillon @ 1:09 pm

A friggin run through 10 really friggin useful friggin Linux tips.
(more…)

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License.
(c) 2012 SQUARISM | powered by WordPress with Barecity