Skip to content

Instantly share code, notes, and snippets.

import {Template} from '@hexlabs/kloudformation-ts';
import {join, joinWith, Value, Base64Fn} from '@hexlabs/kloudformation-ts/dist/kloudformation/Value';
import {AWS} from '@hexlabs/kloudformation-ts/dist/kloudformation/aws';
import {InternetGateway} from '@hexlabs/kloudformation-ts/dist/aws/ec2/InternetGateway';
import {VPC} from '@hexlabs/kloudformation-ts/dist/aws/ec2/VPC';
import {VPCGatewayAttachment} from '@hexlabs/kloudformation-ts/dist/aws/ec2/VPCGatewayAttachment';
import {RouteTable} from '@hexlabs/kloudformation-ts/dist/aws/ec2/RouteTable';
import {SecurityGroup} from '@hexlabs/kloudformation-ts/dist/aws/ec2/SecurityGroup';
import {NatGateway} from '@hexlabs/kloudformation-ts/dist/aws/ec2/NatGateway';
import {Subnet} from '@hexlabs/kloudformation-ts/dist/aws/ec2/Subnet';
@richard-gibson
richard-gibson / traceOps.scala
Last active February 2, 2021 12:59
Possible way to capture tracing for anonymous functions
def trace[U, V](
functionName: String
)(func: U => V)(implicit txnExecutionContext: TxnExecutionContext): U => V =
new Function1[U, V] {
// set functionName, call trace async here
def apply(u: U): V = {
txnExecutionContext.token.link()
func(u)
}
fun <T> queryUser(s: T?) =
Either.fromNullable(s).mapLeft { "unknown" }
data class Person(val name: String, val age: Int)
val ePerson: Either<String, Person> = Either.applicative<String>().mapN(
queryUser("name"),
queryUser(10)
) { (name, age) -> Person(name, age) }.fix()
@richard-gibson
richard-gibson / List.rs
Created January 7, 2021 21:18
Persistent List in rust
use std::{iter::FromIterator, rc::Rc};
#[derive(Eq, PartialEq, Debug, Ord, PartialOrd, Clone)]
struct Node<T> {
elem: T,
next: Link<T>,
}
#[derive(Eq, PartialEq, Debug, Ord, PartialOrd, Clone)]
pub struct List<T> {
function todoRoutes(todoService: TodoService): Handler {
return router([
bind("/{id}", router([
bind(HttpMethod.GET, async request => {
const id = requiredPathParam(request, "id");
const todoEntry = todoService.fetch(id);
return (todoEntry)
? { statusCode: 200, body: JSON.stringify(todoEntry) }
: { statusCode: 404, body: '' };
}),
data class Location(val location: String, val since: String, val till: String)
val searchDate = LocalDate.now()
locations.filter { location ->
searchDate.isAfter(LocalDate.parse(location.since, DateTimeFormatter.ISO_DATE)) &&
searchDate.isBefore(LocalDate.parse(location.since, DateTimeFormatter.ISO_DATE))
}.groupBy { it.location }
@richard-gibson
richard-gibson / multiProducerMultiConsumerQueue.kt
Created October 20, 2019 19:51
Example of multiple producers using a single Arrow Effects Queue
import arrow.Kind
import arrow.core.Either
import arrow.fx.IO
import arrow.fx.ForIO
import arrow.fx.Queue
import arrow.fx.Timer
import arrow.fx.fix
import arrow.fx.handleErrorWith
import arrow.fx.QueueShutdown
import arrow.fx.extensions.fx

I've been working with Kafka for over 7 years. I inevitably find myself doing the same set of activities while I'm developing or working with someone else's system. Here's a set of Kafka productivity hacks for doing a few things way faster than you're probably doing them now. 🔥

Get the tools

[error] /.../src/test/scala/admin/repository/ProductServiceSqlTest.scala:18:14: type mismatch;
[error] found : cats.effect.Resource[cats.effect.IO,doobie.hikari.HikariTransactor[cats.effect.IO]]
[error] (which expands to) cats.effect.Resource[cats.effect.IO,doobie.util.transactor.Transactor[cats.effect.IO]{type A = com.zaxxer.hikari.HikariDataSource}]
[error] required: cats.effect.Resource[F,doobie.hikari.HikariTransactor[F]]
[error] (which expands to) cats.effect.Resource[F,doobie.util.transactor.Transactor[F]{type A = com.zaxxer.hikari.HikariDataSource}]
[error] xa <- transactor(dbConf)
[error] ^
[info] cats.effect.Resource[cats.effect.IO,doobie.hikari.HikariTransactor[cats.effect.IO]] <: cats.effect.Resource[F,doobie.hikari.HikariTransactor[F]]?
[info] F[_] <: cats.effect.IO[_]?
[info] false
@richard-gibson
richard-gibson / gist:61596733a7cb65bd75139b5eabe4e36c
Created October 25, 2018 21:57
Arrow Either Validation examples
package co.brightcog.validation
import arrow.core.*
import arrow.data.*
import arrow.typeclasses.*
sealed class Failure {
data class EmptyString(val fieldName: String) : Failure()
data class InvalidCity(val fieldName: String) : Failure()