Skip to content

Instantly share code, notes, and snippets.

@snekse
snekse / Hibernate + Spring ignoring @Column name.md
Last active April 25, 2024 00:59
Hibernate + Spring Boot ignoring @column(name="camelCase")
@snekse
snekse / .gitconfig
Created April 28, 2022 17:03
git alias commands
[alias]
########################################
# Config commands
########################################
editConfig = "!code ~/.gitconfig"
# setAuthor "Firstname Lastname" "email@gmail.com"
setAuthor = "!f(){ git config user.name $1 && git config user.email $2; }; f"
@snekse
snekse / .gitignore
Created February 24, 2022 15:39
A global git ignore file that ignores all of the most common files we would want to exclude from saving in a VCS
# It's better to unpack these files and commit the raw source because
# git has its own built in compression methods.
*.7z
*.jar
*.rar
*.zip
*.gz
*.bzip
*.bz2
*.xz
package com.snekse.java.utils
import java.util.Collection;
import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;
public class CollectionStreamUtil {
public static <T, R> List<R> mapToList(Collection<T> i, Function<T, R> f) {
return i.stream().map(f).collect(Collectors.toList());
@snekse
snekse / convertDataAttributes.js
Created December 18, 2018 17:26
Simple function to take an object with a bunch of `data-` attributes and convert to a new object that has keys with the `data-` stripped
const convertDataAttributes = dataAttributes =>
Object.entries(dataAttributes)
.filter(([k, v]) => k.startsWith("data-"))
.reduce((acc, [k, v]) => {
const newKey = k.slice(5); //`data-` length
acc[newKey] = v;
return acc;
}, {});
@snekse
snekse / README.md
Last active October 23, 2018 18:21
Testing for a String to just be defined in Yup
// See https://runkit.com/snekse/yup-tests-string-defined/1.0.0
// and https://runkit.com/snekse/yup-tests-string-defined/2.0.0
yup.string().min(0).strict(true).nullable(true).notOneOf([undefined]);

// If we want to allow nulls, just add `.nullable(true)`
const schema = yup.string().min(0).strict(true).nullable(true).notOneOf([undefined]);

console.log(schema.isValidSync(""));
@snekse
snekse / yup-is-string-defined.js
Created October 23, 2018 16:42
Testing for a String to just be defined in Yup
// See https://runkit.com/snekse/yup-tests-string-defined
yup.string().min(0).strict(true).nullable(true).notOneOf([undefined]);
// If we want to allow nulls, just add `.nullable(true)`
const schema = yup.string().min(0).strict(true).nullable(true).notOneOf([undefined]);
console.log(schema.isValidSync(""));
@snekse
snekse / section-commands.js
Created October 2, 2018 17:08
Nightwatch tips and tricks
/* eslint-disable no-console */
const CHECK = "CHECK";
const WHEN = "WHEN";
const THEN = "THEN";
const DEFAULT_INDENT = " ";
const DEFAULT_STEP_PAUSE = 50;
const DEFAULT_LOG_VALUE_MSG_FORMATTER_FN = (selector, result) =>
`${DEFAULT_INDENT}${selector} value is "${result.value}"
@snekse
snekse / SingleColumnDatabaseMapping.java
Created April 11, 2018 21:45
When you have a "child" table that, for whatever reason, only has a single real column in it, then you can use `ElementCollection` for the mapping to avoid some of the hassle w/ creating a real entity and repo. This is especially useful when using Spring Data Rest and you want to be able to easily add/edit/delete the values in this association.
//All of the fancy annotations are mostly here if you want to generate the DDL via Hibernate
@Size(min = 10) // If you want to limit the max size of the array
@ElementCollection(fetch = FetchType.EAGER)
@CollectionTable(name = 'IssueRequestor', joinColumns = [@JoinColumn(name = 'IssueID')],
uniqueConstraints = [ @UniqueConstraint(name = 'IssueRequestor_uc_issueId_requestor',
columnNames = ['IssueID', 'requestor'])])
@Column(name = 'requestor', length = 150)
Set<String> requestors = []
@snekse
snekse / IntegrationTestMockingConfig.groovy
Created April 11, 2017 17:46
spring-spock-integration-testing blog post samples
@TestConfiguration
class IntegrationTestMockingConfig {
private DetachedMockFactory factory = new DetachedMockFactory()
@Bean
ExternalRankingService externalRankingService() {
factory.Mock(ExternalRankingService)
}
}