Skip to content

Instantly share code, notes, and snippets.

Derek Eskens snekse

Block or report user

Report or block snekse

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View CollectionStreamUtil.java
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 Dec 18, 2018
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
View convertDataAttributes.js
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 Oct 23, 2018
Testing for a String to just be defined in Yup
View README.md
// 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 Oct 23, 2018
Testing for a String to just be defined in Yup
View yup-is-string-defined.js
// 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 Oct 2, 2018
Nightwatch tips and tricks
View section-commands.js
/* 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 Apr 11, 2018
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.
View SingleColumnDatabaseMapping.java
//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 / Hibernate + Spring ignoring @Column name.md
Last active May 25, 2018
Hibernate + Spring Boot ignoring @column(name="camelCase")
View Hibernate + Spring ignoring @Column name.md
@snekse
snekse / IntegrationTestMockingConfig.groovy
Created Apr 11, 2017
spring-spock-integration-testing blog post samples
View IntegrationTestMockingConfig.groovy
@TestConfiguration
class IntegrationTestMockingConfig {
private DetachedMockFactory factory = new DetachedMockFactory()
@Bean
ExternalRankingService externalRankingService() {
factory.Mock(ExternalRankingService)
}
}
@snekse
snekse / Greetings.java
Created Apr 21, 2016
An example of creating custom method implementations on a per enum value basis.
View Greetings.java
public enum Greetings implements CustomGreeting {
FORMAL("Hello. Pleasure to see you.") {
@Override
public String customGreeting() {
return Babelfish.get("i18n.dothraki.greeting.formal");
}
}, CASUAL("Hey, what's up.") {
@Override
public String customGreeting() {
return Babelfish.get("i18n.dothraki.greeting.casual");
View NEJustSoccer.js
dragSpeed = 12 //9
team = ''
me = ''
myCircle = ''
ball = initBall().hide()
stampSize = 100
ballSpeed = 1000
playerSpeed = 1000
meter = 100
You can’t perform that action at this time.