Skip to content

Instantly share code, notes, and snippets.

import folium
import requests
# Load IPs from a file
with open('ips.txt', 'r') as file:
ip_list = [line.strip() for line in file if line.strip()]
# Create a world map centered at latitude 0, longitude 0
folium_map = folium.Map(location=[0, 0], zoom_start=2)
@ptaylor
ptaylor / curl-request.sh
Created November 1, 2024 11:23
Generic curl request script for JSON REST APIs
#!/bin/sh
#
# Usage: curl-request METHOD PATH [DATA]
#
if [ "${XXX_TOKEN}" == "" ]; then
echo "Set XXX_TOKEN"
exit 1
fi
@ptaylor
ptaylor / application.yml
Created January 9, 2019 11:52
Spring Boot log4j2 rolling log appender
logging:
level:
com.example: DEBUG
org.springframework: INFO
file: ${spring.application.name}.log
path: /var/app_log/myapp/
@ptaylor
ptaylor / AddOriginalUrlFilterFactory
Created October 18, 2018 14:02
Spring cloud gateway filter for adding the original gateway request URL
package org.example;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.gateway.filter.GatewayFilter;
import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory;
import org.springframework.cloud.gateway.support.ServerWebExchangeUtils;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.stereotype.Component;
@ptaylor
ptaylor / index.html
Last active October 15, 2018 10:56
Angular google maps with a list of markers
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>TITLE</title>
<base href="/">
<script src="https://maps.googleapis.com/maps/api/js?key=<YOUR-API-KEY>"></script>
</head>
<body>
@ptaylor
ptaylor / ParallelStreamTest.java
Created September 13, 2018 09:46
Java 8 parallelStream & ForkJoinPool
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ForkJoinPool;
import java.util.stream.Collectors;
import java.util.stream.LongStream;
public class ParallelStreamTest {
private static boolean verbose = false;
private static int size = 50;
@ptaylor
ptaylor / ServiceTest.java
Created June 27, 2018 16:52
Unit test with HTTP server
package org.example.service;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@ptaylor
ptaylor / ConfigurationServiceTest.java
Created June 26, 2018 15:54
Integration test of Spring Boot Configuration service to validate no errors in configuration served for services and profiles
package org.example.config;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.test.context.junit4.SpringRunner;
import java.util.List;
@ptaylor
ptaylor / build-docker.gradle
Created January 9, 2018 14:55
Gradle build docker image with multiple tags
// Using two docker builds as a workaround until multiple tags are
// supported (https://github.com/Transmode/gradle-docker/issues/50).
task createDockerTasks() {
buildDockerWithTag('latest')
buildDockerWithTag(version)
}
task buildDocker(dependsOn: [createDockerTasks, buildDocker_latest, "buildDocker_${version}"]) {
@ptaylor
ptaylor / RandomCodeGenerator.java
Created November 10, 2017 14:21
User friendly random code generator
import java.security.SecureRandom;
import java.util.Random;
public class RandomCodeGenerator {
static final SecureRandom RANDOM = new SecureRandom();
static final char[] LETTERS = "ABCEFGHJKMNPQRSTWXYZ".toCharArray();
static final char[] NUMBERS = "0123456789".toCharArray();
static final int DEFAULT_NUM_CODES = 20;