Skip to content

Instantly share code, notes, and snippets.

View armhold's full-sized avatar

George Armhold armhold

View GitHub Profile
@armhold
armhold / WicketUtils.java
Created August 17, 2011 17:18
render a wicket web page to a String
public static String renderPage(Class<? extends Page> pageClass, PageParameters pageParameters)
{
WebApplication application = WebApplication.get();
ServletContext context = application.getServletContext(); //fake a request/response cycle
MockHttpSession servletSession = new MockHttpSession(context);
servletSession.setTemporary(true);
MockHttpServletRequest servletRequest = new MockHttpServletRequest(application, servletSession, context);
MockHttpServletResponse servletResponse = new MockHttpServletResponse(servletRequest); //initialize request and response
servletRequest.initialize();
servletResponse.initialize();
@armhold
armhold / Start.java
Created December 30, 2011 10:58
Use a JNDI DataSource with Wicket 1.5 and Jetty 7.5.x
package com.example;
import org.apache.wicket.util.time.Duration;
import org.eclipse.jetty.http.ssl.SslContextFactory;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.bio.SocketConnector;
import org.eclipse.jetty.server.ssl.SslSocketConnector;
import org.eclipse.jetty.util.resource.Resource;
import org.eclipse.jetty.webapp.WebAppContext;
import org.eclipse.jetty.plus.webapp.EnvConfiguration;
@armhold
armhold / gist:1997767
Created March 8, 2012 01:12
wicket-cdi exception on bad cid
java.lang.IllegalStateException: Context is already active
at org.jboss.weld.context.AbstractConversationContext.activate(AbstractConversationContext.java:227)
at org.jboss.seam.conversation.plugins.weld.WeldHttpSeamConversationContext.doActivate(WeldHttpSeamConversationContext.java:52)
at org.jboss.seam.conversation.api.AbstractSeamConversationContext.activate(AbstractSeamConversationContext.java:51)
at net.ftlines.wicket.cdi.CdiContainer.activateConversationalContext(CdiContainer.java:99)
at net.ftlines.wicket.cdi.ConversationPropagator.activateConversationIfNeeded(ConversationPropagator.java:137)
at net.ftlines.wicket.cdi.ConversationPropagator.onException(ConversationPropagator.java:124)
at org.apache.wicket.request.cycle.RequestCycleListenerCollection$4.notify(RequestCycleListenerCollection.java:118)
at org.apache.wicket.request.cycle.RequestCycleListenerCollection$4.notify(RequestCycleListenerCollection.java:116)
at org.apache.wicket.util.listener.ListenerCollection.notify(ListenerCollection.ja
@armhold
armhold / gist:2198074
Created March 25, 2012 16:28
a Wicket Mapper that sets the locale based on the hostname of the request
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
@armhold
armhold / gist:2220564
Created March 27, 2012 21:37
Wicket NoVersionHomePageMapper - don't show page version/id on home page
public class NoVersionHomePageMapper extends AbstractComponentMapper
{
/**
* If this is the home page URL, return a bigger compatibility score than
* {@link org.apache.wicket.request.mapper.HomePageMapper#getCompatibilityScore(Request)}
*
* @see org.apache.wicket.request.mapper.HomePageMapper#getCompatibilityScore(org.apache.wicket.request.Request)
*/
public int getCompatibilityScore(Request request)
{
@armhold
armhold / spotlight.js
Created June 11, 2012 15:25
jQuery Spotlight modification: added a hide() hook
/**
* jQuery Spotlight
*
* Project Page: http://dev7studios.com/portfolio/jquery-spotlight/
* Copyright (c) 2009 Gilbert Pellegrom, http://www.gilbertpellegrom.co.uk
* Licensed under the GPL license (http://www.gnu.org/licenses/gpl-3.0.html)
* Version 1.0 (12/06/2009)
*
* modified slightly by George Armhold to add a hide() hook for removing the spotlight programmatically.
*/
@armhold
armhold / mem.rb
Created March 8, 2013 17:36
possible memory leak in Nokogiri 1.5.6
#!/usr/bin/env ruby
require 'nokogiri'
def get_memory_usage
`ps -o rss= -p #{Process.pid}`.to_i
end
HTML_CONTENT = "This is some html<br/>This is some more html<br/>" * 10
@armhold
armhold / rails4-emoji-bug
Last active December 19, 2015 03:48
demonstrates encoding bug in Rails4
#!/usr/bin/env ruby
# Activate the gem you are reporting the issue against.
gem 'activerecord', '4.0.0' # NB: works fine with 3.2.13
gem 'mysql2'
require 'active_record'
require 'minitest/autorun'
require 'logger'
# This connection will do for database-independent bug reports.
end of file reached
/Users/foo/.rvm/gems/ruby-1.9.3-p362/gems/rsolr-1.0.8/lib/rsolr/connection.rb:15:in `execute'
/Users/foo/.rvm/gems/ruby-1.9.3-p362/gems/sunspot_rails-2.0.0/lib/sunspot/rails/solr_instrumentation.rb:14:in `block in execute_with_as_instrumentation'
/Users/foo/.rvm/gems/ruby-1.9.3-p362/gems/activesupport-3.2.13/lib/active_support/notifications.rb:123:in `block in instrument'
/Users/foo/.rvm/gems/ruby-1.9.3-p362/gems/activesupport-3.2.13/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/Users/foo/.rvm/gems/ruby-1.9.3-p362/gems/activesupport-3.2.13/lib/active_support/notifications.rb:123:in `instrument'
/Users/foo/.rvm/gems/ruby-1.9.3-p362/gems/sunspot_rails-2.0.0/lib/sunspot/rails/solr_instrumentation.rb:12:in `execute_with_as_instrumentation'
/Users/foo/.rvm/gems/ruby-1.9.3-p362/gems/rsolr-1.0.8/lib/rsolr/client.rb:166:in `execute'
/Users/foo/.rvm/gems/ruby-1.9.3-p362/gems/rsolr-1.0.8/lib/rsolr/client.rb:161:in `send_and_receive'
(eval):2:in `post'
#
# RVM profile
#
# /etc/profile.d/rvm.sh # sh extension required for loading.
#
if
[ -n "${BASH_VERSION:-}" -o -n "${ZSH_VERSION:-}" ] &&
test "`ps -p $$ -o comm=`" != dash &&
test "`ps -p $$ -o comm=`" != sh