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 / gist:8744c54d116c437e8eef
Created August 8, 2014 12:53
Loooong lambda
SelectableItem matchingItem = getItems().stream()
.filter(selectableItem -> selectableItem.getTitle().equals(title))
.findFirst().orElseGet(() -> SelectableItem.EMPTY).getId();
private Map<Integer, ? extends Address> getAddressIndex(Optional<SubjectData> currentSubjectData) {
return currentSubjectData
.map(
subjectData -> subjectData.getAddresses()
.stream()
.filter(address -> address.getEsoId() != null)
.collect(toMap(Address::getEsoId, t -> t))
).orElse(
emptyMap()
);
public interface DateConversionHelper {
static LocalDateTime fromXmlDate(XMLGregorianCalendar calendar) {
if (calendar == null) {
return null;
}
final int year = calendar.getYear() > 0 ? calendar.getYear() : 0;
final int month = calendar.getMonth();
final int day = calendar.getDay();
final int hour = calendar.getHour() > 0 ? calendar.getHour() : 0;
{
"data": [
{
"x": 403,
"y": 907,
"count": 1,
"price": 0
},
{
"x": 801,
Quiz:
Try to replace request.getRequestURI() in #commence method with custom value retrieved from request attribute:
org.springframework.security.web.access.channel.RetryWithHttpsEntryPoint
org.springframework.security.web.access.channel.RetryWithHttpEntryPoint
Try to override org.springframework.security.web.DefaultRedirectStrategy, but reuse complex logic in org.springframework.security.web.DefaultRedirectStrategy#calculateRedirectUrl
package com.fg.newsfeed.dao;
import com.fg.metadata.business.SqlContainerQueryInterceptor;
import com.fg.metadata.business.SqlOneToManyBundleQueryInterceptor;
import com.fg.metadata.business.dto.ContainerId;
import com.fg.metadata.model.config.MetadataBundleDefinition;
import com.fg.metadata.model.config.MetadataContainerDefinition;
import com.fg.metadata.model.query.AdamQuery;
import com.fg.metadata.storage.model.Join;
import com.fg.metadata.storage.model.QueryDecomposition;
@Override
public boolean equals(Object o) {
if(this == o) return true;
if(o == null || getClass() != o.getClass()) return false;
Cell cell = (Cell)o;
if(x != cell.x) return false;
if(y != cell.y) return false;
@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) {