Skip to content

Instantly share code, notes, and snippets.

View davetron5000's full-sized avatar

David Copeland davetron5000

View GitHub Profile
@davetron5000
davetron5000 / Checkstyle pre-commit hook
Created December 18, 2008 02:40
Pre Commit Hook for running checkstyle on changed files
#!/usr/bin/perl
#
# Pre-commit hook for running checkstyle on changed Java sources
#
# To use this you need:
# 1. checkstyle's jar file somewhere
# 2. a checkstyle XML check file somewhere
# 3. To configure git:
# * git config --add checkstyle.jar <location of jar>
# * git config --add checkstyle.checkfile <location of checkfile>
/** Immutable name */
public class DefensiveName {
private String first;
private String last;
public DefensiveName(String first, String last) {
if (first == null) throw new IllegalArgumentException("first may not be null");
if (last == null) throw new IllegalArgumentException("last may not be null");
this.first = first;
@davetron5000
davetron5000 / no_dry.rb
Created April 22, 2009 02:45
Why JavaBeans just tires me so
class ThanksJavaBeans
def initialize(hash)
@hash = hash
end
def method_missing(symbol,*args)
if args.length == 0
@hash[symbol]
else
super(symbol,args)
#include <stdio.h>
int doit(float f) {
printf("%f\n",f);
}
int doitDouble(double d) {
printf("%f\n",d);
}
int main(int argc, char** argv) {
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<properties>
<resteasy-version>1.1-RC2</resteasy-version>
</properties>
<groupId>com.example</groupId>
<artifactId>spring-resteasy</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<display-name>Archetype RestEasy Web Application</display-name>
<listener>
<listener-class>org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap</listener-class>
</listener>
<listener>
<listener-class>org.jboss.resteasy.plugins.spring.SpringContextLoaderListener</listener-class>
// define a class called "Circle"
// it has a 1-arg constructor that takes an Int
class Circle(r:Int) {
// define a read-only field
val radius = r;
// define a method to compute diameter
def diameter = radius * 2
// define a method to compute area
// we use braces since we need more than one line of code
def area = {
trait SuperComparable {
// extenders need only implement this method
// since it has no definition, it's abstract
// Also notice that the final colon and type indicate
// the return type of this method
def compareTo(x: Any): Int
// here we have a method that works in terms
// of the abstract one above, just as you
// would have in a Java abstract class
// Also note that we don't need to declare
public interface SuperComparable extends Comparable {
boolean lessThan(Object o);
boolean greaterThan(Object o);
boolean same(Object o);
}
class Cylinder(h: Int, r:Int) extends Circle(r) {
val height = h;
override def area = (super.area * 2) + (2 * 3.14 * r * height)
def volume = super.area * height
override def toString = "Cylinder with radius " + radius
}