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
package euler14
object Main {
def isCollatzSerie(n:BigInt, numElements:BigInt):(BigInt, BigInt) = {
if(n <= 1)
(n, numElements)
else if(n%2 == 0)
isCollatzSerie(n >> 1, numElements + 1)
else
package com.maasfrensch
import java.io._
/**
* Adds some useful methods to file, to be used implicitely:
* implicit def file2enhanced(file:File) = new EnhancedFile(file)
* @author peter@maas-frensch.com
*/
class EnhancedFile(val file:File) {
private function connectRTMP():Boolean
{
// setup timeout
connectionTimer.reset();
connectionTimer.start();
tryNC = [];
tryNCTimer = new Timer(DEFAULT_NC_TIMEOUT);
tryNCTimer.addEventListener(TimerEvent.TIMER, nextConnect);
@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 {
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")
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))
declare namespace vpro="urn:vpro:guide:2009";
//vpro:program[@isMovie = 'true']
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>
/**
* 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"))
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;