Skip to content

Instantly share code, notes, and snippets.

View banterCZ's full-sized avatar

Luboš Račanský banterCZ

View GitHub Profile
@banterCZ
banterCZ / Employee.java
Last active August 29, 2015 14:17
JPA association class
import javax.persistence.*;
import java.util.Map;
@Entity
public class Employee {
@GeneratedValue(strategy = GenerationType.AUTO)
@Id
@Column(name = "EMP_ID")
private Integer id;
@banterCZ
banterCZ / build.gradle
Last active August 29, 2015 14:20
A version conflict results in a build failure. This strategy requires all version conflicts to be resolved explicitly in the build script. https://gradle.org/docs/current/userguide/dependency_management.html#sub:version_conflicts
apply plugin: 'java'
repositories {
mavenLocal()
}
configurations.all {
//TODO comment out to result in a build failure
//resolutionStrategy.failOnVersionConflict()
}
@banterCZ
banterCZ / pom.xml
Last active August 29, 2015 14:20
Dependency mediation - this determines what version of a dependency will be used when multiple versions of an artifact are encountered. http://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>cz.zvestov.mvn</groupId>
<artifactId>transitive-dependencies</artifactId>
<version>1.0.0-SNAPSHOT</version>
var binding = new BasicHttpBinding {AllowCookies = true};
using (var svc = new ServiceReference1.MyWSClient(binding, new EndpointAddress("http://localhost:8080/myApp/myWS")));
import javax.enterprise.context.SessionScoped;
import java.io.Serializable;
import java.util.concurrent.atomic.AtomicInteger;
@SessionScoped
public class Counter implements Serializable {
private AtomicInteger count = new AtomicInteger(0);
public void increase() {
@banterCZ
banterCZ / pom.xml
Last active August 29, 2015 14:23
How to keep war clean
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<id>enforce-banned-dependencies</id>
<goals>
<goal>enforce</goal>
</goals>
@banterCZ
banterCZ / script.groovy
Last active April 28, 2016 14:11
Soap UI WS mock script
def request = mockRequest.requestContent
log.info "CA Request: $request"
def payload = new XmlSlurper().parseText(request)
def csr = "${payload.Body.issueCertificate.paramIn.pkcs10}"
def temp = File.createTempFile('temp', '.csr')
temp.deleteOnExit()
temp.write(csr)
@banterCZ
banterCZ / feature_branches.py
Created September 15, 2015 08:23
A Mercurial extension used to with features branches
"""commands for working with feature branches
feature_branches is a Mercurial extension used to with features branches."""
from mercurial import util, commands, merge
def close_feature(ui, repo, node, **opts):
"""Close a feature branch (e.g. fb-123) and merge it to default."""
branch = "fb-" + node
close_branch(branch, ui, repo, node, **opts)
########################################################
#
# Check certificates inside a java keystore
#
########################################################
[CmdletBinding()]
Param(
[Parameter(Mandatory=$True)]
[string]$keystore,
@banterCZ
banterCZ / Dispatcher.groovy
Last active January 29, 2016 10:28
"Because Groovy dispatches by the runtime type, the specialized implementation of oracle(String) is used in the second case." "Wherever there’s a Java API that uses the static type Object, this code effectively loses the strength of static typing. ... This is why the Java type concept is called weak static typing" Source: Groovy in Action Second…
def oracle(Object o) { return 'object' }
def oracle(String o) { return 'string' }
Object x = 1
Object y = 'foo'
assert 'object' == oracle(x)
assert 'string' == oracle(y)