Skip to content

Instantly share code, notes, and snippets.

View sermojohn's full-sized avatar

Ioannis Sermetziadis sermojohn

  • ThousandEyes (part of Cisco)
  • Heraklion, Greece
  • X @sermojohn
View GitHub Profile
@sermojohn
sermojohn / go-custom-errors
Last active September 11, 2019 08:58
Use of custom error types and switch on error types
package main
import (
"fmt"
)
type ErrorType1 struct {
Message string
}
package main
import (
"fmt"
"runtime"
"time"
)
// GetWebResults test
func GetWebResults(cancel chan bool) {
public class UndertowResteasyServer {
public static void main(String[] args) {
ResteasyDeployment deployment = new ResteasyDeployment();
deployment.setApplicationClass(MyRestApplication.class.getName());
UndertowJaxrsServer server = new UndertowJaxrsServer();
DeploymentInfo deploymentInfo = server.undertowDeployment(deployment, "/")
.setClassLoader(UndertowResteasyServer.class.getClassLoader())
.setContextPath("/api").setDeploymentName("WS");
import static java.lang.System.out;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
public class SoAnswer {
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.Assert;
import org.junit.Test;
import java.io.IOException;
import java.util.Collections;
import java.util.Map;
@sermojohn
sermojohn / ItemProcessor.java
Created November 18, 2016 08:45
Java Streams for hierarchical object traversal
package concepts;
import java.util.Collection;
import java.util.LinkedList;
import java.util.UUID;
import java.util.stream.Stream;
public class ItemProcessor {
public static void main(String[] args) {
generateStreamOf(5)
import org.slf4j.Logger;
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.context.Initialized;
import javax.enterprise.event.Observes;
import javax.inject.Inject;
@javax.enterprise.context.ApplicationScoped
public class StartupCdiBean {
package gr.iserm.java.javaplayground.lambdas;
import java.util.Arrays;
import java.util.List;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import static java.lang.System.out;
@sermojohn
sermojohn / NestedClassesTest
Created June 9, 2015 08:17
NestedClassesTest
package ocp;
/** Static methods of hierarchy classes are called on the reference variable type. */
public class NestedClassTest {
/** Nested classes need to be static in order to define static methods (Nested class, not Inner) */
static class A {
public void parentMethod() {
System.out.println("parent method");
}
@sermojohn
sermojohn / gist:4632652
Created January 25, 2013 08:03
Utility method for generating an image with rounded corners from an image with proper corners.
public class ImageUtils {
public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, int radius, int bgcolor) {
Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888);
Canvas canvas = new Canvas(output);
final Paint paint = new Paint();
final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
final RectF rectF = new RectF(rect);
final float roundPx = radius;