Skip to content

Instantly share code, notes, and snippets.

View p3t0r's full-sized avatar

Peter Maas p3t0r

  • Adevinta
  • Hilversum, the Netherlands
View GitHub Profile
import scala.collection.mutable.Map
val phonebook = Map("peter" -> "12345")
phonebook += ("henk" -> "12300") // adds, but doesn't re-assign
println(phonebook)
package com.finalist.eip.examples;
import java.util.Arrays;
import java.util.List;
import javax.jms.ConnectionFactory;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.camel.CamelContext;
import org.apache.camel.EndpointInject;
/**
* listen to topic queue
* -- on incoming message
* --- split message into program fragments using xpath
* ---- extract the id from the program
* ---- write a program document to the xml store
*/
from("activemq:topic:incomingVPROGuide")
.splitter(vpro.xpath("//vpro:program"))
declare namespace vpro="urn:vpro:guide:2009";
<results>
{
for $prg in //vpro:program[@isMovie='true']
let $scheduleEvents := //vpro:scheduleEvent[vpro:programRef&=$prg/@id]
return
<programWithSchedule>
{$prg}
<schedule>{for $s in $scheduleEvents return $s}</schedule>
declare namespace vpro="urn:vpro:guide:2009";
//vpro:program[@isMovie = 'true']
def priceCalculator(tax: Double=>Double, reduction: Double=>Double, price:Double, shipping:Double) = tax(reduction(price + shipping))
def reducationCalculator(price:Double) = if(price > 50) price - 10 else price
val withTax = priceCalculator(_*1.19,_: Double=>Double, _:Double, _:Double)
val withTaxAndReduction = withTax(reducationCalculator(_), _:Double, _:Double)
println(withTaxAndReduction(97.5, 2.5))
import groovyx.net.ws.WSClient
def wsdlUrl = "http://localhost:8080/Quickstart_helloworld/scheduleService?wsdl"
def proxy = new WSClient(wsdlUrl, this.class.classLoader)
proxy.create()
println proxy.findScheduleForUrn("my:test:urn")
@p3t0r
p3t0r / reformatTwitterDate.java
Created February 15, 2009 12:38
a piece of code to reformat a date which doesn't perform well on Android devices.
private static final String TW33T0R_DATE_PATTERN = "HH:mm:ss - MMM dd";
private static final String TWITTER_DATE_PATTERN = "EEE MMM dd HH:mm:ss Z yyyy";
/**
* @param d The datestring as received from the twitter api
* @return the date formatted in tw33t0r format
*/
private static String reformatTwitterDateToTw33t0rRepresentation(final String d) {
SimpleDateFormat formatter = new SimpleDateFormat(TWITTER_DATE_PATTERN);
try {
@p3t0r
p3t0r / unary oparator.scala
Created January 29, 2009 19:09
overloading a unary operator in scala
class MyString(string:String){
var value = string
def unary_- = new MyString(new StringBuilder(value).reverse.toString)
override def toString = value
}
val myString = new MyString("abcd")
println(myString) // prints "abcd"
println(-myString) // prints "dcba"
private function connectRTMP():Boolean
{
// setup timeout
connectionTimer.reset();
connectionTimer.start();
tryNC = [];
tryNCTimer = new Timer(DEFAULT_NC_TIMEOUT);
tryNCTimer.addEventListener(TimerEvent.TIMER, nextConnect);