Skip to content

Instantly share code, notes, and snippets.

View omnisis's full-sized avatar

Clifford James omnisis

View GitHub Profile
@omnisis
omnisis / H2EmbeddedTest.java
Last active February 29, 2020 14:16
Configuring H2 database for unit tests w/ spring
package examples.database;
import com.google.common.collect.Lists;
import examples.database.dao.PeopleDAO;
import examples.database.model.PeopleInfo;
import org.apache.commons.lang.time.StopWatch;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.Test;
import org.junit.runner.RunWith;
@omnisis
omnisis / MySqlCli.java
Created January 10, 2013 05:50
Mysql CLI Invoker
package ehcache.examples;
import java.io.*;
public class MySqlCLI {
private String mysqlBinaryPath = "/usr/local/bin/mysql";
public String getMysqlBinaryPath() {
return mysqlBinaryPath;
@omnisis
omnisis / XMLNSFilter.java
Created December 12, 2012 06:13
DOM4J: configure sax reader to remove ns uris
package com.cliff.xmlns;
import org.dom4j.Document;
import org.dom4j.DocumentFactory;
import org.dom4j.Node;
import org.dom4j.XPath;
import org.dom4j.io.SAXReader;
import org.junit.Before;
import org.junit.Test;
import org.xml.sax.Attributes;
@omnisis
omnisis / protocol.rb
Created November 2, 2012 04:42
Ruby UDP Server/Client Pair with Custom Binary Protocol
require 'bindata'
class CustomProtocol < BinData::Record
endian :big
stringz :command_word
uint8 :op1
uint8 :op2
end
@omnisis
omnisis / maven.sh
Created September 7, 2012 01:50
Maven Bash Function to run archetype generate using "gradle/grails style" GAV descriptors
export MAVEN_OPTS="-Xmx512m -XX:MaxPermSize=256M"
function maven-new-proj() {
if [ ! $# -eq 2 ]; then
echo "Usage: maven-new-proj example.org:some-archetype:1.0 mygroupid.myartifact"
fi
OIFS=$IFS
IFS=':'
read -rA ARCH_GAV <<< "$1"
(require '[clojure.data.csv :as csv]
'[clojure.java.io :as io])
(defn read-hitting-stats
"Reads hitting stats from a CSV file."
[csv-file]
(with-open [rdr (io/reader csv-file)]
(doall
(map parse-hitter (csv/read-csv rdr)))))
@omnisis
omnisis / gist:1625035
Created January 17, 2012 05:43
Basic Binary Tree with test sample in Clojure
;; binary tree using defrecord (as oppossed to maps)
(defrecord TreeNode [val l r])
;; constructor method: creates a new tree
(defn make-tree [root]
(TreeNode. root nil nil))
;; creates a new binary tree by appending v to existing tree
(defn tree-append [t v]
(cond
@omnisis
omnisis / gist:1614265
Created January 15, 2012 04:13
Example of How to create a SQL DSL in clojure (from Joy of Clojure)
(ns joy.sql
"SQL DSL example from chapter 1."
(:require [clojure.string :as str]))
(defn expand-expr [expr]
(if (coll? expr)
(if (= (first expr) `unquote) ;;#: Handle unsafe literals
"?"
(let [[op & args] expr]
(str "(" (str/join (str " " op " ") (map expand-expr args)) ")")))
@omnisis
omnisis / StrategyRunner.groovy
Created January 13, 2012 03:06
An example of using interfaces with flexible closures
class StrategyRunner {
Map strategyMap = [:]
interface IStrategy {
boolean apply(arg)
};
def addStrategy(String name, Closure cl) {
@omnisis
omnisis / gist:1233759
Created September 22, 2011 00:49
TYCHO POM.xml with aspects failing compile
=================
pom.xml
=================
<?xml version="1.0" encoding="UTF-8"?>
<!-- Copyright (C) 2011, EclipseSource and others All rights reserved. This
program and the accompanying materials are made available under the terms
of the Eclipse Public License v1.0 which accompanies this distribution, and
is available at http://www.eclipse.org/legal/epl-v10.html -->