Skip to content

Instantly share code, notes, and snippets.

Lutz Horn lutzhorn

Block or report user

Report or block lutzhorn

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
@lutzhorn
lutzhorn / RegisterRabbitMQMetrics.java
Created Apr 29, 2019
Register a RabbitMQ `ConnectionFactory` with Dropwizard Metrics.
View RegisterRabbitMQMetrics.java
import com.codahale.metrics.MetricRegistry;
import com.rabbitmq.client.ConnectionFactory;
import com.rabbitmq.client.impl.StandardMetricsCollector;
import io.dropwizard.setup.Environment;
// Register metrics for a ConnectionFactory.
MetricRegistry metricRegistry = environment.metrics();
StandardMetricsCollector metrics = new StandardMetricsCollector(metricRegistry);
connectionFactory.setMetricsCollector(metrics);
@lutzhorn
lutzhorn / Camel2Snake.java
Created Mar 26, 2019
Convert between camelCase and snake_case using Guava in Java
View Camel2Snake.java
CaseFormat camelCase = CaseFormat.LOWER_CAMEL;
CaseFormat snakeCase = CaseFormat.LOWER_UNDERSCORE;
Converter<String, String> camelToSnake = camelCase.converterTo(snakeCase);
Converter<String, String> snakeToCamel = snakeCase.converterTo(camelCase);
String s0 = "foo_bar_baz";
String c1 = snakeToCamel.convert(s0);
String s1 = camelToSnake.convert(c1);
System.out.println(String.format("%s => %s%n", s0, c1));
@lutzhorn
lutzhorn / FormatDate.java
Created Mar 8, 2019
format Date in Java 8
View FormatDate.java
Date value = new Date():
LocalDate localDate = value.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
String formatedDate = DateTimeFormatter.ISO_LOCAL_DATE.format(localDate);
LocalDateTime localDateTime = value.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
String formatedDateTime = DateTimeFormatter.ISO_LOCAL_DATE.format(localDateTime);
@lutzhorn
lutzhorn / InstantExplore.java
Last active Mar 7, 2019
Convert Instant to LocalDate in Java 11 or Java 8
View InstantExplore.java
package playground;
import java.time.Instant;
import java.time.LocalDate;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.Date;
public class InstantExplore {
public static void main(String[] args) {
@lutzhorn
lutzhorn / main.go
Last active Jan 31, 2019
Demonstrate the use of `Rows.NextResultSet`
View main.go
package main
import (
"context"
"database/sql"
"fmt"
"os"
_ "github.com/lib/pq"
)
@lutzhorn
lutzhorn / certbot-renew.sh
Created Jan 18, 2019
"Action required: Let's Encrypt certificate renewals"
View certbot-renew.sh
# Let's Encrypt sends emails like this:
# Subject: Action required: Let's Encrypt certificate renewals
#
# Hello,
#
# **Action is required to prevent your Let's Encrypt certificate renewals from breaking.**
#
# Your Let’s Encrypt client used ACME TLS-SNI-01 domain validation to issue a certificate in the past 60 days.
#
@lutzhorn
lutzhorn / interface-slice.go
Created Jan 17, 2019
An Interface Slice in Go: What is the use of `[]Fooer` in Go where `Fooer` is an interface?
View interface-slice.go
package main
import (
"fmt"
)
type Fooer interface {
Foo() string
}
@lutzhorn
lutzhorn / pom.xml
Created Jan 17, 2019
Maven Dependencies for JSON-P
View pom.xml
<dependency>
<groupId>javax.json</groupId>
<artifactId>javax.json-api</artifactId>
<version>1.1.2</version>
</dependency>
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.json</artifactId>
<version>1.1.2</version>
</dependency>
You can’t perform that action at this time.