Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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;
}, {});
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 / .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
@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"