Skip to content

Instantly share code, notes, and snippets.

View jvz's full-sized avatar

Matt Sicker jvz

View GitHub Profile
@jvz
jvz / SealedBox.java
Created April 19, 2021 21:56
Port of libsodium sealed boxes to Java using jnacl and jblake2
package io.jenkins.infra.sealedbox4j;
import org.kocakosm.jblake2.Blake2b;
import javax.crypto.AEADBadTagException;
import java.util.Arrays;
import static com.neilalexander.jnacl.crypto.curve25519.crypto_scalarmult_base;
import static com.neilalexander.jnacl.crypto.curve25519xsalsa20poly1305.*;
package io.jenkins.plugins.keystore;
import hudson.init.InitMilestone;
import hudson.init.Initializer;
import jenkins.model.Jenkins;
import jenkins.security.ConfidentialKey;
import jenkins.security.ConfidentialStore;
import org.apache.commons.io.IOUtils;
import javax.annotation.CheckForNull;
@jvz
jvz / DefaultInjectionManagerTest.java
Created February 23, 2020 20:10
Work in progress test suite showing off various ways dependency injection fits together
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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
*
@jvz
jvz / Jenkinsfile
Last active November 8, 2019 15:22
Example usage of credentials parameters in declarative pipelines
pipeline {
agent any
// user credentials as build parameters
/*
parameters {
credentials(credentialType: 'com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl',
defaultValue: '',
description: 'Production deployment key',
name: 'deployKey',
required: true)
@jvz
jvz / Jenkinsfile
Last active September 16, 2019 15:47
Example usage of credentials parameters for scripted pipelines
// build parameters can insert user credentials for the entire pipeline
/*
properties([
parameters([
credentials(credentialType: 'com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl',
defaultValue: '',
description: 'Production deployment key',
name: 'deployKey',
required: true)
])
@jvz
jvz / Graph.scala
Last active January 27, 2018 21:56
Minimal implementation of a covariant graph abstract data type using adjacency lists
package graph
trait Graph[+A] {
def isEmpty: Boolean
def size: Int
def contains[A0 >: A](vertex: A0): Boolean
def +[A0 >: A](vertex: A0): Graph[A0]
@jvz
jvz / FizzBuzz.scala
Last active September 24, 2023 21:11
Functional FizzBuzz
// adapted from this great paper:
// https://themonadreader.files.wordpress.com/2014/04/fizzbuzz.pdf
def fb(n: Int): String = {
def test(d: Int, s: String)(x: String ⇒ String)(v: String): String =
if (n % d == 0) s + x("") else x(v)
(test(3, "fizz") _ compose test(5, "buzz"))(identity)(n.toString)
}
import akka.NotUsed
import akka.actor.ActorRef
import akka.pattern.AskableActorRef
import akka.stream.scaladsl.Source
import akka.util.Timeout
import scala.reflect.ClassTag
/**
* Generic oracle that answers queries with streams.
@jvz
jvz / TcpStreamServer.scala
Created July 19, 2017 14:58
Trivial TCP server for Avro IPC
package avro.akka.ipc
import java.nio.ByteBuffer
import java.util.{ArrayList => AList, List => JList}
import akka.NotUsed
import akka.actor.{Actor, Props}
import akka.stream.Materializer
import akka.stream.scaladsl.Tcp.ServerBinding
import akka.stream.scaladsl.{BidiFlow, Flow, Framing, Tcp}
trait DefPwS {
def get(list: Boolean) = if (list) List(1, 2, 3) else (1, 2, 3) // warn
}
trait ValPwS {
val foo = if (true) List(1, 2) else (1, 2) // warn
}
trait ParamPwS {
def f[A](as: A*) = 42