Skip to content

Instantly share code, notes, and snippets.

@schmmd
schmmd / Pipe.java
Created August 29, 2011 21:44
Pipe a Reader to a Writer or an InputStream to an OutputStream in java.
public class Pipe {
/***
* Writes all lines read from the reader.
* @param reader The source reader
* @param writer The destination writer
* @throws IOException
*/
public static void pipe(Reader reader, Writer writer) throws IOException {
pipe(reader, writer, 4092);
}
@schmmd
schmmd / Timing.scala
Created September 10, 2011 15:39
scala-timing-helpers
object Timing {
/** Return a tuple, where the first part is the milliseconds
* taken and the second part is the result of the block
* execution. */
def time[R](block: =>R): (Long, R) = {
val start = System.currentTimeMillis
val result = block
(System.currentTimeMillis - start, result)
}
@schmmd
schmmd / cdextras.sh
Created September 14, 2011 18:19
bash-cd-extras
#!/bin/bash
#
# cdextras.sh - contains functions to optimize traversals
# of the directory tree.
#
# Author: Michael Schmitz <schmmd@cs.washington.edu>
# Original Author of up and down: Steve Rowe <steve_rowe@users.sourceforge.net>
#
@schmmd
schmmd / binary.scala
Created October 8, 2011 04:57
scala binary tree
/* contravariance required so Empty can be used with Nodes ( Nothing <: T ) */
class Tree[+T]
case object Empty extends Tree[Nothing]
case class Node[T](val elem: T, val left: Tree[T], val right: Tree[T]) extends Tree[T]
def inOrder[T](t: Tree[T]): List[T] = t match {
case Empty => Nil
case Node(e, left, right) => inOrder(left) ::: List(e) ::: inOrder(right)
}
@schmmd
schmmd / ctags
Created October 11, 2011 05:05
ctags file
--langdef=scala
--langmap=scala:.scala
--regex-scala=/^[ \t]*((abstract|final|sealed|implicit|lazy)[ \t]*)*(private|protected)?[ \t]*class[ \t]+([a-zA-Z0-9_]+)/\4/c,classes/
--regex-scala=/^[ \t]*((abstract|final|sealed|implicit|lazy)[ \t]*)*(private|protected)?[ \t]*object[ \t]+([a-zA-Z0-9_]+)/\4/c,objects/
--regex-scala=/^[ \t]*((abstract|final|sealed|implicit|lazy)[ \t]*)*(private|protected)?[ \t]*case class[ \t]+([a-zA-Z0-9_]+)/\4/c,case classes/
--regex-scala=/^[ \t]*((abstract|final|sealed|implicit|lazy)[ \t]*)*(private|protected)?[ \t]*case object[ \t]+([a-zA-Z0-9_]+)/\4/c,case objects/
--regex-scala=/^[ \t]*((abstract|final|sealed|implicit|lazy)[ \t]*)*(private|protected)?[ \t]*trait[ \t]+([a-zA-Z0-9_]+)/\4/t,traits/
--regex-scala=/^[ \t]*type[ \t]+([a-zA-Z0-9_]+)/\1/T,types/
--regex-scala=/^[ \t]*((abstract|final|sealed|implicit|lazy)[ \t]*)*def[ \t]+([a-zA-Z0-9_]+)/\3/m,methods/
--regex-scala=/^[ \t]*((abstract|final|sealed|implicit|lazy)[ \t]*)*val[ \t]+([a-zA-Z0-9_]+)/\3/l,constants/
@schmmd
schmmd / bashrc.sh
Created October 21, 2011 03:04
bashrc.sh
# make a TAB variable globally accessible
export TAB=`echo -e "\t"`
# sort compares binary data
export LC_ALL=C
# search for a file and open it with vim
function vimfind() {
if [ "$1" == "-s" ]
then
@schmmd
schmmd / maven.vim
Created October 27, 2011 18:17
vim maven compiler file
" Compiler: maven
" Author: Michael Schmitz <michael@schmitztech.com>
" Last Change: 10/27/2011
if exists("current_compiler")
finish
endif
let current_compiler = "maven"
set makeprg=mvn\ clean\ compile
@schmmd
schmmd / Trie.scala
Created November 16, 2011 06:41
Trie
import collection.mutable.SetLike
class Trie[A] extends Set[List[A]] {
type S = List[A]
type This = Trie[A]
sealed abstract class AbstractLayer
case class Layer(val map: Map[A, Layer]) extends AbstractLayer
case class Entry(val seq: S) extends AbstractLayer
@schmmd
schmmd / gist:1713952
Created January 31, 2012 23:50
PDFBox
/***
* Bypass the Tika wrapper for PDFs and go directly to PDFBox since
* Apache Tika 0.8 has a bug when processing PDFs. This should be fixed
* when Apache Tika 0.9 is released.
* @param file
* @param fileType
* @param writer
* @throws IOException
* @throws ConversionException
*/
@schmmd
schmmd / dot2svg.scala
Created February 14, 2012 00:54
dot2svg
def svg2xml(svgString: String) = {
import org.apache.batik.dom.svg.SVGDOMImplementation;
import org.apache.batik.util.XMLResourceDescriptor
import org.apache.batik.dom.svg.SAXSVGDocumentFactory
val uri = SVGDOMImplementation.SVG_NAMESPACE_URI;
val doc = using(new java.io.StringReader(svgString)) { reader =>
val parser = XMLResourceDescriptor.getXMLParserClassName();
val f = new SAXSVGDocumentFactory(parser);