Skip to content

Instantly share code, notes, and snippets.

@xfyre
xfyre / wsdc_allstar.scala
Created September 5, 2018 17:03
WSDC All Star qualification criteria explained
val isAllStarQualified = {
// 45 Advanced points accumulated within last 36 months
// OR
// has 3 All Star points within last 36 months
// OR
// has any All Star points AND 10 Advanced points within last 12 months
if (thisDivision == WsdcDivision.ALL_STAR) {
val maybeAdvPointsInPast3Years = maybePrevDivisionInfo.map {
advDivInfo => divisionInfoPlacements2(advDivInfo)
.filter(_.points > 0)
@xfyre
xfyre / ajax-error-reporting.js
Created January 26, 2015 06:16
Custom AJAX error reporting for Tapestry 5
define(["jquery", "t5/core/events", "t5/core/zone", "t5/core/ajax", "underscore"], function($, events, zone, ajax, _) {
return function(messages) {
var dialogTemplate = '<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">' +
'<div class="modal-dialog">' +
'<div class="modal-content">' +
'<div class="modal-header">' +
'<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>' +
'<h3 class="modal-title" id="exampleModalLabel">' + messages.title + '</h3>' +
'</div>' +
'<div class="modal-body"><p class="lead">' + messages.text + '</p><p class="text-danger">{{errorMessage}}</p>' +
package com.xdance.services
import spray.can.Http
import spray.http._
import spray.json.JsonFormat
import spray.json.DefaultJsonProtocol
import spray.httpx.SprayJsonSupport
import spray.client.pipelining._
import scala.concurrent._
import scala.collection.JavaConversions._
@xfyre
xfyre / RetrieveRankedList.java
Last active August 29, 2015 14:13
retrieveRankedList example
public List<ContestEntrance> retrieveRankedList ( Contest contest, ContestSignupRole role ) {
if ( !contest.isRandomPartnered () )
throw new IllegalArgumentException ( "only applicable for random-partnered contests" );
final List<ContestEntrance> list = new ArrayList<ContestEntrance> ();
final List<ContestRound> reverseRoundsList = new ArrayList<ContestRound> ( contest.getRounds () );
Collections.reverse ( reverseRoundsList );
for ( final ContestRound round : reverseRoundsList ) {
if ( !( round.isScored () || round.isFinished () ) )
package com.xdance.misc;
import java.io.*;
import java.util.List;
import org.apache.tapestry5.grid.GridDataSource;
import org.apache.tapestry5.grid.SortConstraint;
import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.criterion.*;
(ns com.myapp.tapestry.serviceregistry
(:import (org.apache.tapestry5.ioc ObjectLocator)))
(def ^:dynamic ^ObjectLocator *tapestry-registry-ref* (promise))
(defn init-registry [^ObjectLocator registry]
"Must be called during service initialization to set up Tapestry registry object"
(deliver *tapestry-registry-ref* registry))
(defmacro with-tapestry-services [service-bindings & body]
@xfyre
xfyre / AjaxUpload.java
Last active February 24, 2019 16:17
Tapestry 5.4 AJAX upload component
package my.app.components;
import org.apache.tapestry5.*;
import org.apache.tapestry5.annotations.*;
import org.apache.tapestry5.corelib.base.AbstractField;
import org.apache.tapestry5.internal.util.Holder;
import org.apache.tapestry5.ioc.Messages;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.apache.tapestry5.json.JSONArray;
import org.apache.tapestry5.json.JSONObject;
@xfyre
xfyre / Example.java
Last active August 29, 2015 14:02
Tapestry 5.4 Autocomplete mixin replacement
/**
* Example of mixin usage
*/
public class Example {
/**
* provide suggestions list
*/
List<?> onCompletionsRequestedFromAccountLookupField ( String partial ) {
List<?> list = hibernateSession.createCriteria ( MyAccountType.class )
@xfyre
xfyre / tapestry-https-frontend.java
Last active April 22, 2018 20:57
handling X-Forwarded-Proto in Tapestry 5
/**
* Pre-requisites:
* - add <Set name="forwarded">true</Set> to jetty.xml connector configuration section
* - set RequestHeader set X-Forwarded-Proto "https" env=HTTPS in apache configuration
*/
/* extend BaseURLSourceImpl */
public class ForwardedBaseURLSourceImpl extends BaseURLSourceImpl {
private final Request request;
@xfyre
xfyre / HashChange.java
Last active December 27, 2015 18:19
Tapestry HashChange mixin
package my.package.mixins;
import org.apache.commons.lang3.StringUtils;
import org.apache.tapestry5.*;
import org.apache.tapestry5.annotations.Environmental;
import org.apache.tapestry5.annotations.Import;
import org.apache.tapestry5.annotations.InjectContainer;
import org.apache.tapestry5.annotations.Parameter;
import org.apache.tapestry5.corelib.base.AbstractComponentEventLink;
import org.apache.tapestry5.corelib.components.ActionLink;