Skip to content

Instantly share code, notes, and snippets.

bcalmac / FilmsOfTatooine.js
Last active May 14, 2021
Axios with concurrent requests
View FilmsOfTatooine.js
// What films does planet Tatooine shows up in?
// Functional-style friendly functions
function get(url) {
return axios.get(url).then(r =>
function getAll(urls) {
return Promise.all(
bcalmac / sleep.js
Created Sep 4, 2020
sleep function that can be used as "await sleep(1000)"
View sleep.js
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
bcalmac /
Created Feb 10, 2020
Load resource to string
package io.github.bcalmac.overtime.server.utils;
import java.nio.file.Files;
import java.nio.file.Paths;
public class OvertimeTestUtils {
bcalmac /
Created Jan 13, 2020
Test LocalDate JSON serialization / deserialization with Jackson
package io.github.bcalmac.scratch;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import lombok.Data;
import org.junit.jupiter.api.Test;
bcalmac /
Created Jan 13, 2020
Cofigure Spring type conversion to use ISO-8601 format for dates
import org.springframework.format.FormatterRegistry;
import org.springframework.format.datetime.standard.DateTimeFormatterRegistrar;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
* Override date/time formatters with ones using ISO-8601.
public class DateTimeFormatConfigurer implements WebMvcConfigurer {
bcalmac / RemaindersOfPowers.hs
Created Dec 14, 2019
Determine the list of remainders of powers of a divided by b
View RemaindersOfPowers.hs
-- a^0 mod b is 1. Once we find the next power with a remainder of 1, the remainders will repeat.
-- Take from a list until the first element repeats
takeUntilFirstRepeats (x:xs) = x : takeWhile (/= x) xs
remaindersOfPowers a b = takeUntilFirstRepeats [a^i `mod` b | i <- [0..]]
-- Example
remaindersOfPowers 9 7
bcalmac /
Last active Aug 18, 2021
Jackson serialization for Interval
import java.time.Instant;
import org.threeten.extra.Interval;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
// Exclude JavaBean properties that are not part of the state
bcalmac /
Created Aug 2, 2017
Simple WireMock transformer that converts the content to upper case
import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
import static com.github.tomakehurst.wiremock.client.WireMock.anyUrl;
import static com.github.tomakehurst.wiremock.client.WireMock.get;
import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
import static org.junit.Assert.assertEquals;
bcalmac /
Last active Jul 28, 2017
What happens if stdout is redirected to the same file as a FileAppender?
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class DuplicateLogging {
private static final Logger logger = LoggerFactory.getLogger(DuplicateLogging.class);
public static void main(String[] args) throws IOException, InterruptedException {
bcalmac /
Last active Jul 11, 2017
Minimal Selenium example that performs a search on
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
public class StackOverflowSearchExample {