Skip to content

Instantly share code, notes, and snippets.

View shelajev's full-sized avatar

Oleg Šelajev shelajev

View GitHub Profile
@shelajev
shelajev / NgrokContainer.java
Created February 22, 2024 17:18
NgrokContainer
package org.testcontainers.repro;
import com.github.dockerjava.api.command.InspectContainerResponse;
import org.testcontainers.Testcontainers;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.wait.strategy.LogMessageWaitStrategy;
import org.testcontainers.containers.wait.strategy.Wait;
import org.testcontainers.images.builder.Transferable;
import org.testcontainers.shaded.org.bouncycastle.util.Strings;
package main
import (
"context"
"fmt"
"os"
"dagger.io/dagger"
)
@shelajev
shelajev / test-containers.py
Created March 25, 2019 18:16
Using test-containers-java from Python (GraalVM)
import java
generic = java.type('org.testcontainers.containers.GenericContainer')
container = generic('nginx')
container.setExposedPorts([80])
container.start();
print('%s:%s' % (container.getContainerIpAddress(), container.getMappedPort(80)));
// Here's the network where both containers will join
static final Network NET = Network.newNetwork();
// The database container will join the network under the 'mysql' alias
@Container
static MySQLContainer dbContainer =
new MySQLContainer<>(DockerImageName.parse("mysql:8.0"))
.withNetwork(NET)
.withNetworkAliases("mysql");
@shelajev
shelajev / Debuggable.java
Last active February 23, 2022 05:26
Java 8 cheat sheet code
public interface Debuggable {
default String debug() {
StringBuilder sb = new StringBuilder(this.getClass().getName());
sb.append(" [ ");
Field[] fields = this.getClass().getDeclaredFields();
for(Field f: fields) {
f.setAccessible(true);
try {
sb.append(f.getName() + " = " + f.get(this));
sb.append(", ");
package com.example;
import io.micronaut.http.MediaType;
import io.micronaut.http.annotation.Controller;
import io.micronaut.http.annotation.Get;
import java.util.HashMap;
import java.util.Map;
@Controller("/")
public class FibonacciController {
package com.example;
import io.micronaut.http.MediaType;
import io.micronaut.http.annotation.Controller;
import io.micronaut.http.annotation.Get;
@Controller("/")
public class FibonacciController {
private static final StringBuilder LOG = new StringBuilder();
public static double correlate(double[] a, double[] b) {
if (a.length != b.length) {
return Double.NaN;
}
double <w,x,y,z> = <0,0,0,0>;
int i = 0;
for ( ; i + 3 < a.length; i += 4) {
<w,x,y,z> += a[<i,i+1,i+2,i+3>] * b[<i,i+1,i+2,i+3>];
}
double correlation = w + x + y + z;
public static double correlate(double[] a, double[] b) {
if (a.length != b.length) {
return Double.NaN;
}
double partial[] = new double[4];
int i = 0;
for ( ; i + 3 < a.length; i += 4) {
partial[0] += a[i+0] * b[i+0];
partial[1] += a[i+1] * b[i+1];
partial[2] += a[i+2] * b[i+2];
class SignalCorrelation {
/** Approximate {@code sin(i / 1000)}. */
public static double sin(int i) {
double x = i / 1000.0;
double term3 = (x*x*x) / (3 * 2 * 1);
double term5 = (x*x*x*x*x) / (5 * 4 * 3 * 2 * 1);
return x - term3 + term5;
}