Skip to content

Instantly share code, notes, and snippets.

@aliteralmind
aliteralmind / AppendWebPageSource.java
Created January 30, 2014 16:05
Append the source-code from a web-page into a {@code java.lang.Appendable}. It has runtime and non-runtime versions, and also provides for verifying the tail end of the retrieved source.
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.io.EOFException;
import java.net.URL;
/**
<P>Append the source-code from a web-page into a <CODE>java.lang.Appendable</CODE>.</P>
@aliteralmind
aliteralmind / ATPropFromRplc.java
Last active January 4, 2016 16:39
Ant task: Within a string, replace all instances of a 'what' string with a 'with' string, placing the result into a property. This only does a single pass through.
/*
XBN-Java is released under the LGPL 2.1
XBN-Java is a collection of generically-useful non-GUI programming utilities, featuring shareable self-returning method chains, "Listify"-ers, regular expression convenience classes, ValidateValue and AlterValue, highly-configurable output for strings and lists, and unit-testing example code.
Copyright (C) 2013 Jeff Epstein
This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
@aliteralmind
aliteralmind / Fraction.java
Last active January 4, 2016 15:39
Represents a fraction in reduced and mixed-number form, with some mathematical functionality.
//package EDU.oswego.cs.dl.util.concurrent.misc;
package xbn.number;
import java.io.Serializable;
import java.util.regex.Pattern;
import java.util.regex.Matcher;
/**
<P>Represents a fraction in reduced and mixed-number form, with some mathematical functionality.</P>
<P>Originally {@code EDU.oswego.cs.dl.util.concurrent.misc.Fraction.java}, with some minor edits, and the addition of mixed numbers, testing function, and string-constructor, by Jeff Epstein.</P>
@aliteralmind
aliteralmind / InitializedObjectUtil.java
Last active January 4, 2016 00:49
Get an object containing an initialized value for a specific type.
/*
XBN-Java is released under the LGPL 2.1
XBN-Java is a collection of generically-useful non-GUI programming utilities, featuring shareable self-returning method chains, "Listify"-ers, regular expression convenience classes, ValidateValue and AlterValue, highly-configurable output for strings and lists, and unit-testing example code.
Copyright (C) 2013 Jeff Epstein
This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
@aliteralmind
aliteralmind / NewWriterForAppendable.java
Last active January 3, 2016 17:19
Creates a new java.io.Writer that wraps around a java.lang.Appendable. It properly flushes and closes appendables that happened to also be java.io.Flushables and/or java.io.Closeables. This uses instanceof only in the constructor, and a (Java 1.5) delta in flush() and close(), which avoids having to use any logic or reflection after object const…
/*
XBN-Java is released under the LGPL 2.1
XBN-Java is a collection of generically-useful non-GUI programming utilities, featuring shareable self-returning method chains, "Listify"-ers, regular expression convenience classes, ValidateValue and AlterValue, highly-configurable output for strings and lists, and unit-testing example code.
Copyright (C) 2013 Jeff Epstein
This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
@aliteralmind
aliteralmind / NewPrintWriterForFile.java
Last active January 3, 2016 05:59
Builder for creating a java.io.PrintWriter that writes to a file.
/*
XBN-Java is a large set of generically-useful utilities, with an emphasis on (single-threaded, non-GUI) text-processing, capturing common errors, and unit testing example code.
Copyright (C) 2013 Jeff Epstein
This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA*)
@aliteralmind
aliteralmind / PrimitiveArrayUtil.java
Last active December 30, 2015 09:59
Utility functions for arrays of primitive types, and java.lang.Objects which are known to be primitive arrays
/*
XBN-Java is released under the LGPL 2.1
XBN-Java is a large set of generically-useful utilities, with an emphasis on (single-threaded, non-GUI) text-processing, capturing common errors, and unit testing example code.
Copyright (C) 2013 Jeff Epstein
This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.