Skip to content

Instantly share code, notes, and snippets.

View omnisis's full-sized avatar

Clifford James omnisis

View GitHub Profile
@omnisis
omnisis / groovy_xml.groovy
Created October 19, 2010 00:41
XML examples in Groovy
class XmlExamples {
static def CAR_RECORDS = '''
<records>
<car name='HSV Maloo' make='Holden' year='2006'>
<country>Australia</country>
<record type='speed'>Production Pickup Truck with speed of 271kph</record>
</car>
<car name='P50' make='Peel' year='1962'>
<country>Isle of Man</country>
<record type='size'>Smallest Street-Legal Car at 99cm wide and 59 kg in weight</record>
@omnisis
omnisis / gist:1233705
Created September 22, 2011 00:14
TYCHO POM.xml with aspects copied deps
<?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 -->
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
@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 -->
@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: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 / 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
(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 / 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"
@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 / 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;