Skip to content

Instantly share code, notes, and snippets.

View hamnis's full-sized avatar

Erlend Hamnaberg hamnis

View GitHub Profile
@hamnis
hamnis / JettyBooter.java
Created August 7, 2013 07:15
Boot jax-ws inside jetty
package antifusion;
import mock.itsm.CreateIncident;
import mock.netcool.UpdateIncident;
import org.eclipse.jetty.http.spi.JettyHttpServerProvider;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.ContextHandlerCollection;
import org.eclipse.jetty.server.handler.HandlerCollection;
import org.eclipse.jetty.webapp.WebAppContext;
public static ConstrettoConfig create() {
ConstrettoConfiguration config = new ConstrettoBuilder().
createIniFileConfigurationStore().
addResource(Resource.create("classpath:config.ini")).
addResource(Resource.create("file:/etc/wholesale/config.ini"))
.done().createSystemPropertiesStore().getConfiguration();
return new ConstrettoConfig(config);
}
import org.apache.velocity.app.Velocity
import org.apache.velocity.VelocityContext
import java.io.StringWriter
public class VelocityRenderer {
public String render(Map<String, String> map, String resource) {
StringWriter stringWriter = new StringWriter();
VelocityContext context = new VelocityContext(map);
@hamnis
hamnis / jboss-web.xml
Created May 28, 2013 06:04
If you for any reason find yourself in need of using jboss; don't. But if you have to, and using basic auth.
<?xml version="1.0" encoding="UTF-8"?>
<jboss-web>
<context-root>/some-context-path</context-root>
<security-domain>ldap</security-domain>
<valve>
<class-name>org.apache.catalina.authenticator.BasicAuthenticator</class-name>
<param>
<param-name>disableProxyCaching</param-name>
<param-value>false</param-value>
</param>
class CalculateAndWrap[A, B](f: (A) => B) {
def unapply(input: A): Option[(A,B)] = Some(input -> f(input))
}
val StringAndLength = new CalculateAndWrap((s: String) => s.length)
"foo" match {
case StringAndLength((f,l)) => println(f + " length " + l)
}
@hamnis
hamnis / Example.java
Last active December 11, 2016 14:14
import net.hamnaberg.json.parser.CollectionParser;
import net.hamnaberg.funclite.Function;
import net.hamnaberg.funclite.FunctionalList;
import net.hamnaberg.funclite.Optional;
import org.apache.http.HttpResponse;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import java.io.IOException;
#!/bin/bash
sudo sh -c 'echo "deb http://repository.spotify.com stable non-free" > /etc/apt/sources.list.d/spotify.list'
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 94558F59
sudo apt-get update
sudo apt-get install spotify-client
libraryDependencies ++= {
val libVersion = "0.6.8"
Seq("net.databinder" % "unfiltered-filter" % libVersion, "net.databinder" % "unfiltered-directives" % libVersion)
}
package ems
import javax.servlet.http.HttpServletRequest
import org.joda.time.DateTime
import unfiltered.directives._
import Directives._
import unfiltered.request._
import unfiltered.response._
import unfilteredx._
POST /events/{id}/sessions/{sessionId}
Content-Type: application/x-www-form-urlencoded
tag=ja&tag=kommer&tag=speakers_dinner_2013
200 OK
Content-Type: application/vnd.collection+json
{