Skip to content

Instantly share code, notes, and snippets.

View dhinojosa's full-sized avatar

Daniel Hinojosa dhinojosa

View GitHub Profile
@dhinojosa
dhinojosa / MyProducer.java
Created June 4, 2020 16:53
MyProducer.java
package com.xyzcorp;
import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.ProducerConfig;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.apache.kafka.common.serialization.IntegerSerializer;
import org.apache.kafka.common.serialization.StringSerializer;
import java.util.Arrays;
import java.util.Properties;
@dhinojosa
dhinojosa / template_params.adoc
Created August 31, 2022 02:41
Sample of slide for question

Template Parameters

  • A template is like a function, so it needs parameters, which must be declared at the top of the template file

    @(customer: Customer, orders: List[Order])
  • Templates can also have default values in case one is not specified

package com.xyzcorp;
import java.util.HashSet;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
public class Person implements Comparable<Person>{
private String firstName;
private String middleName; //null by default
@dhinojosa
dhinojosa / ScriptTimeoutJupiterTest.java
Created November 5, 2021 05:12
Understanding the Callback
/*
* (C) Copyright 2021 Boni Garcia (https://bonigarcia.github.io/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
trait Functor[F[_]]:
def fmap[A, B](fa:F[A])(f: A => B):F[B]
trait Applicative[F[_]] extends Functor[F]:
def pure[A](a:A):F[A]
object Lists:
given Functor[List] with
def fmap[A,B](fa:List[A])(f:A=>B):List[B] = fa.map(f)
import scala.compiletime.ops.int.%
type HCF[A <: Int, B <: Int] <: Int = B match {
case 0 => A
case _ => HCF[B, A % B]
}
//A: 50, B: 10
//HCF[10, 0]
//10
@dhinojosa
dhinojosa / HigherKindedTypesScala3.scala
Created January 14, 2021 22:23
Higher Kinds and Functors in Scala 3
package com.xyzcorp.demo.higherkindedtypes
trait Functor[F[_]]:
def fmap[A,B](fa:F[A])(f: A => B):F[B]
object Functor:
def apply[F[_]](using fun:Functor[F]):Functor[F] = fun
object ListTypeClasses:
given Functor[List] =
package com.xyzcorp.challenges;
import org.junit.Test;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class WordChallenge1 {
static class Tuple2<A, B> {
private final A a;
private final B b;
public Tuple2(A a, B b) {
this.a = a;
this.b = b;
}
@dhinojosa
dhinojosa / service-account.yml
Created June 11, 2020 03:40
Service-Account YAML for Spinnaker
apiVersion: v1
kind: Namespace
metadata:
name: spinnaker
---
apiVersion: v1
kind: ServiceAccount
metadata: