Skip to content

Instantly share code, notes, and snippets.

View adrobisch's full-sized avatar

Andreas Drobisch adrobisch

View GitHub Profile
@adrobisch
adrobisch / Cargo.toml
Last active February 27, 2023 12:40
Custom JSON Format for Rust tracing
tracing-log = "0.1"
tracing-subscriber = { version = "0.3", features = ["env-filter", "json"] }
tracing-serde = "0.1"
chrono = { version = "0.4", default-features = false, features = ["clock"] }
@adrobisch
adrobisch / StopOnSignal.scala
Created September 29, 2021 06:50
handle pending work after a stop signal with fs2 and cats-effect
package stop
import cats.effect.std.Queue
import cats.effect.{ExitCode, IO, IOApp}
import fs2._
import fs2.concurrent.SignallingRef
import sun.misc.{Signal, SignalHandler}
import java.time.LocalDateTime
import scala.concurrent.duration.DurationInt
@adrobisch
adrobisch / aws-mfa.sc
Created January 17, 2019 15:20
Scala Ammonite Script to update AWS session token in awscli profile via 2FA
import $ivy.`io.circe::circe-core:0.10.0`;import $ivy.`io.circe::circe-generic:0.10.0`;import $ivy.`io.circe::circe-parser:0.10.0`
import sys.process._
import io.circe._
@doc("This script updates the awscli profile with the keys and the session token from AWS")
@main def authenticate(mfaArn: String @doc("// you can find the mfa arn in https://console.aws.amazon.com/iam/home#/users/<your aws console login username>?section=security_credentials"),
token: String @doc("the token code from you authenticator app e.g. Google Authenticator or Authy"),
@doc("the profile to use to get the session token, you can configure it with `aws configure --profile <profile name>`") stsProfile: String = "mfa",
@doc("the profile to store the session keys and session token") sessionProfile: String = "mfa-session") = {
assert(!stsProfile.equals(sessionProfile), "sts profile and session profile must not be the same")
@adrobisch
adrobisch / keybase.md
Created September 18, 2017 17:20
keybase.md

Keybase proof

I hereby claim:

  • I am adrobisch on github.
  • I am adrobisch (https://keybase.io/adrobisch) on keybase.
  • I have a public key ASDZGgRPX0TFWyhUI6YPnJvNMcftYipQjZcYB_DqSbEUaQo

To claim this, I am signing this object:

@adrobisch
adrobisch / hateoas.raml
Created May 17, 2016 13:33
HATEOAS with RAML 1.0
#%RAML 1.0
title: HATEOAS example
types:
Link:
type: object
properties:
rel: string
href?:
type: string
@adrobisch
adrobisch / AutenticationInterceptor.js
Created October 15, 2015 13:03
Spring Boot security example configuration for AngularJS applications including XSRF
var AutenticationInterceptor = ['$q', '$window', function($q, window) {
return {
response: function(response) {
return response || $q.when(response);
},
responseError: function(rejection) {
if (rejection.status === 401) {
window.location.href = "login.html";
}
return $q.reject(rejection);
@adrobisch
adrobisch / XmlBuilder.java
Created August 25, 2015 14:25
XML Builder for Java 8
/**
Usage
=====
XmlBuilder xml = new XmlBuilder(outputStream);
xml.start()
.tag("version", versionTag -> versionTag.content(pojo.getVersion()))
.tag("time", timeTag -> timeTag.content(pojo.getTime()))
.tag("data", dataTag -> {
@adrobisch
adrobisch / build.sbt
Last active August 29, 2015 14:13
sbt central publish for Java projects
import com.typesafe.sbt.SbtNativePackager._
import NativePackagerKeys._
net.virtualvoid.sbt.graph.Plugin.graphSettings
packageArchetype.java_application
organization := "com.example"
name := "example"
#%RAML 0.8
title: World Music API
baseUri: http://example.api.com/{version}
version: v1
schemas:
- halLink: |
{ "$schema": "http://json-schema.org/schema",
"type": "object",
"description": "a Hypertext Application Language link",