Skip to content

Instantly share code, notes, and snippets.

@virgium03
virgium03 / FixSubtitles.java
Last active November 18, 2015 21:24
Replace non ASCII characters from Romanian subtitle files with their counterparts
package org.vigi;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
@virgium03
virgium03 / IterableHasItemWithPropertyAndValue
Created October 11, 2012 09:48
Check if an {@link Iterable} has one item with a given property name and property value.
import static org.hamcrest.CoreMatchers.hasItem;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.Matchers.hasProperty;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeDiagnosingMatcher;
/**
* Matcher that checks if an {@link Iterable} has one item with a given property
@virgium03
virgium03 / IsIterableInSameOrder
Created October 11, 2012 12:05
Matcher that tells us if a given iterable has the elements in the same order as the one it is compared to.
import static org.hamcrest.CoreMatchers.equalTo;
import java.util.List;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeDiagnosingMatcher;
import org.hamcrest.collection.IsIterableContainingInOrder;
import com.google.common.collect.Lists;
@virgium03
virgium03 / applicationContext.xml
Created April 10, 2013 11:43
How to enable JPA 2.0 on Weblogic 10.3 - add the following in the Spring applicationContext.xml configuration file - create a Maven EAR module with the pom.xml below - create an weblogic-application.xml file that allows us to load the JPA 2.0 and Hibernate classes from our app and not from Weblogic - put the weblogic-application.xml inside src/m…
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<tx:annotation-driven mode="aspectj"
transaction-manager="transactionManager" />
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceUnitName" value="persistenceUnit" />
<property name="dataSource" ref="dataSource" />
@virgium03
virgium03 / tomcat7 integration tests
Created September 12, 2013 09:53
Run integration tests with Tomcat7 using the Maven plug in. Including JNDI data source and context root.
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.1</version>
<configuration>
<fork>true</fork>
<port>8080</port>
<path>...path>
<contextFile>src/test/resources/context.xml</contextFile>
</configuration>
@virgium03
virgium03 / applicationContext-security.xml
Last active December 24, 2015 02:09
Spring security configuration with pre authentication filter for ECAS
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:security="http://www.springframework.org/schema/security"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.1.xsd">
<bean id="filterChainProxy" class="org.springframework.security.web.FilterChainProxy">
@virgium03
virgium03 / maven command
Last active August 29, 2015 13:56
Deploy webapps with Weblogic Maven plugin
mvn com.oracle.weblogic:weblogic-maven-plugin:undeploy com.oracle.weblogic:weblogic-maven-plugin:deploy -pdev -Dweblogic.server.target=ms1
@virgium03
virgium03 / gist:ed0c01d6c5862d557a57
Last active August 29, 2015 14:15
Pagination for JSPs using Spring Data
<c:set var="page" scope="request" value="${it.number + 1}"/>
<c:set var="size" scope="request" value="${it.size}"/>
<c:set var="maxPages" scope="request" value="${it.totalPages}"/>
<c:if test="${it.number lt 0 or it.totalElements le 0 or it.totalPages le 0}">
<c:set var="page" value="0"/>
<c:set var="size" value="0"/>
<c:set var="maxPages" value="0"/>
</c:if>
<c:if test="${empty size || size lt 1}">
<c:set var="size" value="25"/>
@virgium03
virgium03 / gist:adf2850b806d63a51cdd
Created May 9, 2015 07:11
Word find and replace patterns
([âa-df-zA-Z])î([a-zA-Z]) with \1â\2. [âî]([a-z])î with â\1â
^013 - paragraph
Shift+F3 as many times as necessary to get the capitalization the way you want it for the selected words.
@virgium03
virgium03 / SecurityConfig.java
Last active December 16, 2017 18:26
Spring Security Java configuration for Pre-authenticated scenario
import org.springframework.boot.context.embedded.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.access.AccessDecisionVoter;
import org.springframework.security.access.vote.AffirmativeBased;
import org.springframework.security.access.vote.RoleVoter;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.AuthenticationProvider;
import org.springframework.security.authentication.ProviderManager;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;