Skip to content

Instantly share code, notes, and snippets.

View gregturn's full-sized avatar

Greg L. Turnquist gregturn

View GitHub Profile
@gregturn
gregturn / ScalaCompilationUnit.java
Created August 24, 2011 17:55
Embedding scala compiler in java
try {
Settings settings = new Settings();
settings.usejavacp().tryToSetFromPropertyValue("true");
settings.stopAfter().tryToSetColon(Nil.$colon$colon("dce")); // same as "dce" :: Nil in scala
settings.debug().tryToSetFromPropertyValue("true");
System.out.println("About to compile " + new String(sourceUnit.getContents()));
PrintWriter out = new PrintWriter("output.txt");
IMain main = new IMain(settings, out);
@gregturn
gregturn / git-lg
Created December 5, 2011 15:40
Pretty git "railroad track" log report
git log --graph --pretty=\"format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr)%Creset'\" --abbrev-commit --date=relative
@gregturn
gregturn / closing.scala
Created April 6, 2012 00:41
Finance app with scala part 2
}
@gregturn
gregturn / EiulLimits.scala
Created April 6, 2012 00:54
Finance app with scala part 3
/** apply allows it to sort the right value into the middle, and then pick it
* For example, EiulLimits(0.0, 15.0)(4.0) would become List(0.0, 4.0, 15.0), with 4.0 being in the middle
* EiulLimits(0.0, 15.0)(-2.4 would become List(-2.4, 0.0, 15.0), with 0.0 being in the middle
* EiulLimits(0.0, 15.0)(22.5) would become List(0.0, 15.0, 22.5), with 15.0 being in the middle
*/
case class EiulLimits(lower:Double, upper:Double) {
def apply(x: Double) = List(x, lower, upper).sorted.apply(1)
}
@gregturn
gregturn / fix
Created July 19, 2013 13:52
This script will parse a markdown file and replace any lines that look like <@snippet path="pom.xml" prefix="complete"/> with <@snippet path="pom.xml" prefix="initial"/>. It writes the new files into <file>.new first, and then moves it to replace the existing file. See comments for more details
#!/usr/bin/env python
import os
import re
import sys
if len(sys.argv) < 2:
print "Usage: %s <file>" % sys.argv[0]
sys.exit(1)
Table of Contents

<#assign project_id="gs-rest-service"> <#assign spring_version="3.2.4.RELEASE"> <#assign spring_boot_version="0.5.0.M4"> This guide walks you through the process of creating a "hello world" [RESTful web service][u-rest] with Spring.

What you’ll build

You’ll build a service that will accept HTTP GET requests at:

@gregturn
gregturn / UriListHttpMessageConverter.java
Created January 17, 2014 15:55
replace Resources with ResourceSupport
package org.springframework.data.rest.webmvc.convert;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@gregturn
gregturn / gist:8956690
Created February 12, 2014 14:40
adding extra dump of environment and classloader info
public static void main(String[] args) {
System.getProperties().list(System.out);
for (String key : System.getenv().keySet()) {
System.out.println(key + " => " + System.getenv(key));
}
dumpClassPaths(ApplicationConfiguration.class.getClassLoader());
SpringApplication.run(ApplicationConfiguration.class, args);
}
private static void dumpClassPaths(ClassLoader classLoader) {
@gregturn
gregturn / crawler
Created April 23, 2014 15:40
Simple crawler to look for bad links on a site
#!/usr/bin/env python
import re
import socket
import sys
import urllib2
from urlparse import urlparse
socket.setdefaulttimeout(10)
#!/bin/bash
spring run `dirname $0`/bootconsole.groovy