Skip to content

Instantly share code, notes, and snippets.

View michail-nikolaev's full-sized avatar

Michail Nikolaev michail-nikolaev

  • Belarus\Netherlands
View GitHub Profile
@michail-nikolaev
michail-nikolaev / OneToOne.java
Created December 28, 2012 13:53
JPA (Hibernate 4) - OneToOne with id from children (optional side)
@Entity
public class User extends AbstractEntity {
@OneToOne(optional = true, cascade = CascadeType.ALL, mappedBy = "owner", orphanRemoval = true)
private UserDog dog;
...
@Entity
public class UserDog extends AbstractEntity {
@OneToOne(optional = false)
@michail-nikolaev
michail-nikolaev / gist:4345069
Created December 20, 2012 12:37
Gradle - provided dependency + IDEA
apply plugin: 'java'
apply plugin: 'idea'
subprojects {
configurations { provided }
sourceSets {
main { compileClasspath += configurations.provided }
}
idea {
@michail-nikolaev
michail-nikolaev / gist:4194409
Created December 3, 2012 11:38
Gradle - IDEA export settings
apply plugin: 'java'
apply plugin: 'idea'
idea {
project {
jdkName = '1.7'
languageLevel = '1.7'
ipr {
withXml { provider ->
provider.node.component.find { it.@name == 'VcsDirectoryMappings' }.mapping.@vcs = 'Git'
@michail-nikolaev
michail-nikolaev / gist:4134618
Created November 23, 2012 08:54
Gradle - jar dependency
def repositoryPath = 'lib'
repositories {
maven {
url "http://mavenrepo.google-api-java-client.googlecode.com/hg"
}
maven {
url "http://boilerpipe.googlecode.com/svn/repo/"
}
@michail-nikolaev
michail-nikolaev / gist:4077880
Created November 15, 2012 10:29
Ubuntu - number of open files
vi /etc/security/limits.conf
#add:
user soft nofile 1000000
user hard nofile 1000000
root soft nofile 1000000
root hard nofile 1000000
vi /etc/pam.d/sudo
@michail-nikolaev
michail-nikolaev / gist:4065829
Created November 13, 2012 13:43
PostreSQL - performance setup
sysctl -w kernel.shmmax=536870912 #see shared_buffers
sysctl -w kernel.shmall=262144
vi /etc/sysctl.conf
kernel.shmmax=536870912
kernel.shmall=262144
postgres.sql:
fsync=on
synchronous_commit=off #may lead to lost transactions
@michail-nikolaev
michail-nikolaev / build.gradle
Last active April 18, 2022 01:48
Gradle - dependency to test classes of another module
// use test classes from spring-common as dependency to tests of current module
testCompile files(this.project(':spring-common').sourceSets.test.output)
// use testCompile dependencies from spring-common as dependency to tests of current module
testCompile files(this.project(':spring-common').sourceSets.test.runtimeClasspath)
def isClassesDependency(module) {
(module instanceof org.gradle.plugins.ide.idea.model.ModuleLibrary) && module.classes.iterator()[0].url.toString().contains(rootProject.name)
}
@michail-nikolaev
michail-nikolaev / gist:3933297
Created October 22, 2012 18:41
Run in screen in parallel
screen -S [name of screen] -d -m [command to run]
@michail-nikolaev
michail-nikolaev / iterations.xml
Created October 21, 2012 11:55
IDEA - live templates
<?xml version="1.0" encoding="UTF-8"?>
<!-- put to C:\Users\${USER}\.IdeaIC11\config\templates as iterations.xml -->
<templateSet group="iterations">
<!-- slf+ TAB to generate logger -->
<template name="slf" value="private static final org.slf4j.Logger LOGGER = org.slf4j.LoggerFactory.getLogger($CLASS_NAME$.class);" description="Creates sfl4j logger" toReformat="true" toShortenFQNames="true" useStaticImport="true">
<variable name="CLASS_NAME" expression="className()" defaultValue="" alwaysStopAt="true" />
<context>
<option name="HTML_TEXT" value="false" />
@michail-nikolaev
michail-nikolaev / gist:3858501
Created October 9, 2012 12:24
Javascript - quarter start and end
var now = new Date();
var quarter = Math.floor((now.getMonth() / 3));
var firstDate = new Date(now.getFullYear(), quarter * 3, 1);
var endDate = new Date(firstDate.getFullYear(), firstDate.getMonth() + 3, 0);