Skip to content

Instantly share code, notes, and snippets.

View michail-nikolaev's full-sized avatar

Michail Nikolaev michail-nikolaev

View GitHub Profile
@michail-nikolaev
michail-nikolaev / PostgreSQL-crosstab
Created September 9, 2012 22:24
PostgreSQL - crosstab
/*CREATE EXTENSION tablefunc*/
INSERT INTO functions_header VALUES
('AM'),
('CM'),
('NM');
SELECT * FROM crosstab(
'
@michail-nikolaev
michail-nikolaev / spring.fat.gradle
Created September 9, 2012 22:27
Gradle - Spring - Fat Jar - Handlers
jar {
from {
configurations.compile.collect { it.isDirectory() ? it : zipTree(it).matching { exclude 'META-INF/spring.handlers' } }
}
from(file("src/main/resources/spring.handlers")) {
into "META-INF"
}
manifest {
attributes 'Implementation-Title': 'Bla-bla',
@michail-nikolaev
michail-nikolaev / neo4j.fat.gradle
Created September 9, 2012 22:29
Gradle - Neo4j - Fat Jar (to avoid problem with pom.xml unzipping)
compile('com.tinkerpop.blueprints:blueprints-neo4jbatch-graph:2.1.0') {
exclude group: "org.neo4j", module: "neo4j"
}
compile('com.tinkerpop.blueprints:blueprints-neo4j-graph:2.0.0') {
exclude group: "org.neo4j", module: "neo4j"
}
compile 'com.tinkerpop.gremlin:gremlin-java:2.1.0'
compile 'org.neo4j:neo4j-backup:1.8.M02'
compile 'org.neo4j:neo4j-com:1.8.M02'
@michail-nikolaev
michail-nikolaev / gist:3687706
Created September 9, 2012 22:31
SpringTestBase - workaround to support profiles
@Configuration
@ComponentScan("com.bla")
public class SpringConfig {
}
@ContextConfiguration(classes = SpringConfig.class)
@ActiveProfiles("test")
@RunWith(SpringJUnit4ClassRunner.class)
public class SpringTestBase {
@michail-nikolaev
michail-nikolaev / gist:3687728
Created September 9, 2012 22:35
Java - Lucene in RAM - withpit tokenizer
RAMDirectory ramDirectory = new RAMDirectory();
Analyzer analyzer = new SimpleAnalyzer(Version.LUCENE_36);
IndexWriterConfig config = new IndexWriterConfig(Version.LUCENE_36, analyzer);
int processed = 0;
try {
IndexWriter writer = new IndexWriter(ramDirectory, config);
writer.commit();
......
@michail-nikolaev
michail-nikolaev / gist:3687731
Created September 9, 2012 22:36
Lucene - JaroWinklerDistance
// compile 'org.apache.lucene:lucene-spellchecker:3.6.1'
private JaroWinklerDistance jaroWinklerDistance = new JaroWinklerDistance();
@michail-nikolaev
michail-nikolaev / gist:3687745
Created September 9, 2012 22:38
Spring - JPA using profiles
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/tx
@michail-nikolaev
michail-nikolaev / gist:3687748
Created September 9, 2012 22:40
Spring - property inject using Configuration (without any xml)
@Configuration
@PropertySource("classpath:/file.properties")
public class BeanProducer {
@Inject
private Environment env;
@Bean
public SomeClass someClass() {
String key = env.getProperty("key");
@michail-nikolaev
michail-nikolaev / gist:3687754
Created September 9, 2012 22:41
JPA - PostgreSQL - AbstractEntity with common ID sequence
@MappedSuperclass
public abstract class AbstractEntity<T extends AbstractEntity> {
private static final String SEQUENCE_NAME = "id_seq";
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = SEQUENCE_NAME)
@SequenceGenerator(name = SEQUENCE_NAME, sequenceName = SEQUENCE_NAME)
private Long id;
public Long getId() {
@michail-nikolaev
michail-nikolaev / gist:3687760
Created September 9, 2012 22:43
Hibernate - close after transaction commit
<property name="connection.release_mode" value="after_transaction" />