Skip to content

Instantly share code, notes, and snippets.

Avatar

Benedykt Jaworski silmeth

  • Poznań, Poland
View GitHub Profile
@silmeth
silmeth / VertxCompletableFutureJupiterTest.java
Created May 27, 2019
How to test some logic depending on Vertx context, returning a VertxCompletableFuture, using Junit Jupiter API
View VertxCompletableFutureJupiterTest.java
import java.util.concurrent.CompletableFuture;
import java.util.function.Supplier;
import io.vertx.core.Vertx;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import pl.omnilogy.utils.vertx.VertxCompletableFuture;
import static org.junit.jupiter.api.Assertions.assertTrue;
@silmeth
silmeth / rust_serde_base64_bytes.rs
Created May 16, 2019
Serialization and deserialization byte array (Vec<u8>) to/from json in Rust as Base64 string using Serde
View rust_serde_base64_bytes.rs
use serde::{Deserialize, Deserializer, Serialize, Serializer};
#[derive(Serialize, Deserialize, Debug)]
pub struct Foo {
#[serde(serialize_with = "as_base64", deserialize_with = "from_base64")]
bytes: Vec<u8>,
}
fn as_base64<T: AsRef<[u8]>, S: Serializer>(val: &T, serializer: S) -> Result<S::Ok, S::Error> {
serializer.serialize_str(&base64::encode(val))
@silmeth
silmeth / JacksonTest1.java
Created Jan 25, 2018
test if [jackson-module-kotlin @JsonIgnore issue](https://github.com/FasterXML/jackson-module-kotlin/issues/124) is also triggered in Java
View JacksonTest1.java
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
class JacksonTest1 {
@Test
View TypeReferenceTest.java
import java.util.List;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.Test;
import static java.util.Arrays.asList;
import static org.junit.jupiter.api.Assertions.assertEquals;
@silmeth
silmeth / Main.kt
Last active Oct 13, 2017
Example of parsing (subset of) JSON using Kotlin better-parse (https://github.com/h0tk3y/better-parse) parser combinators
View Main.kt
import com.github.h0tk3y.betterParse.grammar.parseToEnd
object Main {
@JvmStatic
fun main(args: Array<String>) {
val json = """
{
"Image": {
"Width": 800,
"Height": 600,
View FixedRateTask.java
import java.time.Instant;
import com.github.kagkarlsson.scheduler.Scheduler;
import com.github.kagkarlsson.scheduler.task.DeadExecutionHandler;
import com.github.kagkarlsson.scheduler.task.OnStartup;
import com.github.kagkarlsson.scheduler.task.Schedule;
import com.github.kagkarlsson.scheduler.task.Task;
public abstract class FixedRateTask extends Task implements OnStartup {
public static final String INSTANCE = "fixedRate";
View OnCompleteRescheduleByPreviousExecution.java
import java.time.Instant;
import com.github.kagkarlsson.scheduler.task.CompletionHandler;
import com.github.kagkarlsson.scheduler.task.ExecutionComplete;
import com.github.kagkarlsson.scheduler.task.ExecutionOperations;
import com.github.kagkarlsson.scheduler.task.Schedule;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public final class OnCompleteRescheduleByPreviousExecution implements CompletionHandler {
View VertxHttpClientTimeoutTest.java
import java.time.Duration;
import java.util.concurrent.TimeoutException;
import io.vertx.core.Handler;
import io.vertx.core.Vertx;
import io.vertx.core.http.HttpClient;
import io.vertx.core.http.HttpClientOptions;
import io.vertx.core.http.HttpServer;
import io.vertx.core.http.HttpServerRequest;
import io.vertx.ext.unit.Async;
View VertxHttpClientTimeoutTest.java
import java.time.Duration;
import java.util.concurrent.TimeoutException;
import io.vertx.core.Handler;
import io.vertx.core.Vertx;
import io.vertx.core.http.HttpClient;
import io.vertx.core.http.HttpClientOptions;
import io.vertx.core.http.HttpServer;
import io.vertx.core.http.HttpServerRequest;
import io.vertx.ext.unit.Async;
View early_drop.rs
// In Rust Playground: https://is.gd/hyO195
struct Foo;
impl Drop for Foo {
fn drop(&mut self) {
println!("Dropping!");
}
}
You can’t perform that action at this time.