Skip to content

Instantly share code, notes, and snippets.

View novoj's full-sized avatar
💻
Hacking on evitaDB

Jan Novotný novoj

💻
Hacking on evitaDB
View GitHub Profile
@novoj
novoj / ExperimentalPrePostAnnotationSecurityMetadataSource.java
Created March 18, 2012 21:12
Combining custom annotations for securing methods with Spring Security (http://blog.novoj.net)
package cz.novoj.spring.security.aop;
import cz.novoj.spring.security.annotation.RulesRelation;
import cz.novoj.spring.security.annotation.RulesRelation.BooleanOperation;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.security.access.ConfigAttribute;
import org.springframework.security.access.method.AbstractMethodSecurityMetadataSource;
import org.springframework.security.access.prepost.*;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
@novoj
novoj / MonteCarlo.java
Created December 10, 2012 09:13
Monte Carlo test for testing different strategies for guessing game. You have three doors and only one is winning one. You make your choice, and then moderator opens some other door showing you that this doors don't win. He then offers you to change your guess. Will you have bigger chance to win when you change your mind or not?
import java.util.Random;
public class MonteCarlo {
private enum Choice {
WINNING, LOSING
}
private static int ITERATIONS = 1000000;
private static final Random randomGenerator = new Random();
private static GuessStrategy stayStrategy = new StayStrategy();
@novoj
novoj / gui.xml
Created May 31, 2013 13:27
Mail module config
<?xml version="1.0" encoding="utf-8"?>
<gui>
<staticPage id="mail" storagePath="file:/www/p_java/cps/libs_java/prj_edeecms/prj_mail/lib_mail/src/main/resources/META-INF/lib_mail/templates/"> <!-- todo ${moduleName}, v MailModule uz je to pripravene -->
<dictionary>
<dataProviders>
<campaignRecordSource class="com.fg.mail.web.ramjet.campaign.datasource.CampaignRecordSource"/>
<campaignByTitleRecordSource class="com.fg.mail.web.ramjet.campaign.datasource.AggregatedCampaignRecordSource"/>
<recipientAutocompletionDataProvider class="com.fg.mail.web.ramjet.campaign.datasource.RecipientAutocompletionDataProvider"/>
<channelItemProvider class="com.fg.mail.web.ramjet.campaign.datasource.ChannelItemsProvider"/>
@novoj
novoj / EdeeUI
Last active December 18, 2015 12:29
V commandu:
@Autowired private EdeeUiAsyncConversationManager conversationMgr;
public Resolution perform(..) {
conversationMgr.addConversation(
new UiConversation() extends Conversation implements ApplicationListener {
public void onEvent(Application event) {
if (event instanceof BatchStoredEvent) {
@novoj
novoj / RecipientListManagerTest.java
Created June 25, 2013 11:45
Recipient subscription from external application.
@Test
public void shouldSubscribeAlreadyConfirmedRecipientByExternalApplication() throws Exception {
Recipient rcp = recipientListManager.createNewRecipient();
rcp.setName("Uďo");
rcp.setAddress(new EmailAddress("novotnaci+udo@gmail.com"));
recipientListManager.subscribeConfirmedRecipient(rcp);
Recipient createdRcpt = recipientListManager.getRecipientByAddress("novotnaci+udo@gmail.com");
assertNotNull(createdRcpt);
assertEquals(RecipientState.Confirmed, createdRcpt.getState());
public class RunAsSupportTestExecutionListener extends AbstractTestExecutionListener {
private static final ThreadLocal<User> savedAuthentication = new ThreadLocal<User>();
@Override
public void prepareTestInstance(TestContext testContext) throws Exception {
super.prepareTestInstance(testContext);
try {
testContext.getApplicationContext().getBean(CpsModuleSecuritySupport.class);
} catch (NoSuchBeanDefinitionException ignored) {
CpsModuleSupport moduleSupport = mock(CpsModuleSupport.class);
@novoj
novoj / ServletFreemarkerRenderer.java
Created August 28, 2013 12:13
ServletFreemarkerRenderer_part
public void render(RequestContext context, WidgetDefinition widgetDefinition, TemplateReference templateReference, ServletContext servletContext, HttpServletRequest request, HttpServletResponse response) throws TemplateNotFoundException, TemplateProcessingException {
try {
//we have to set encoding before writer is fetche
try {
response.setCharacterEncoding(configuration.getDefaultEncoding());
} catch (NoSuchMethodError e) {
// servlet spec 2.3
response.setContentType("text/html; encoding=" + configuration.getDefaultEncoding());
}
PageDefinition pageDefinition = (PageDefinition) context.getRequestable();
@novoj
novoj / bootstrapDictionary.xml
Created September 4, 2013 10:12
Bootstrap dictionary
<?xml version="1.0" encoding="utf-8"?>
<dictionary>
<widgets>
<rowFluid extends="widgetContainer" template="inherit">
<metadata>
<htmlClass>row-fluid</htmlClass>
</metadata>
</rowFluid>
<span1 extends="widgetContainer" template="inherit">
<metadata>
@novoj
novoj / HackedDynamicMappingFilter.java
Last active December 23, 2015 06:29
Patch for Stripes framework on WebSphere 8.x
package net.sourceforge.stripes.controller;
import net.sourceforge.stripes.action.ActionBean;
import net.sourceforge.stripes.exception.StripesServletException;
import net.sourceforge.stripes.util.HttpUtil;
import net.sourceforge.stripes.util.Log;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
package com.fg.doxx.gastro.web.user.validator;
import com.fg.doxx.gastro.business.GastroUserManager;
import com.fg.doxx.gastro.model.user.GastroUser;
import com.fg.form.core.context.RequestContext;
import com.fg.form.core.data.state.State;
import com.fg.form.core.lifecycle.validate.impl.AbstractSingleValueWidgetValidator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;