Skip to content

Instantly share code, notes, and snippets.

View sarxos's full-sized avatar

Bartosz Firyn sarxos

  • Lionbridge
  • Poland
View GitHub Profile
@sarxos
sarxos / HibernateOrmProcessor.java
Created March 19, 2020 14:49
A @ BuildStep to register files as hot deployment resources
@BuildStep
List<HotDeploymentWatchedFileBuildItem> hotDeploymentWatchedFiles(LaunchModeBuildItem launchMode) {
List<HotDeploymentWatchedFileBuildItem> watchedFiles = new ArrayList<>();
watchedFiles.add(new HotDeploymentWatchedFileBuildItem("META-INF/persistence.xml"));
watchedFiles.add(new HotDeploymentWatchedFileBuildItem(INTEGRATOR_SERVICE_FILE));
watchedFiles.add(new HotDeploymentWatchedFileBuildItem(SERVICE_CONTRIBUTOR_SERVICE_FILE));
getSqlLoadScript(launchMode.getLaunchMode()).ifPresent(script -> {
watchedFiles.add(new HotDeploymentWatchedFileBuildItem(script));
});
@sarxos
sarxos / ConcurrentStack.java
Created May 8, 2019 15:45
Concurrent, lock free stack, a Treiber's Stack implementation
import java.util.concurrent.atomic.*;
import net.jcip.annotations.*;
/**
* ConcurrentStack
*
* Nonblocking stack using Treiber's algorithm
*
* @author Brian Goetz and Tim Peierls
@sarxos
sarxos / GreedyResolver.java
Last active March 14, 2019 12:00
JustInTimeInjectionResolver will try resolve injectee when other injection attempts failed
// You should take care when using the above resolver as it'll add things into
// your ServiceLocator that you might not have been expecting. It will also
// probably not do well with injecting things like Strings or other types like
// that. Still, might work for your use case.
// Will not work if your injection point is injecting an interface!
@Singleton
@Visibility(DescriptorVisibility.LOCAL)
public class GreedyResolver implements JustInTimeInjectionResolver {
@sarxos
sarxos / pom.xml
Last active April 24, 2025 04:29
CheckerFramework with Lombok and Maven
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.plan.bofime</groupId>
<artifactId>swim-common-parent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
void actionPerformed(..) {
Thread t = new Thread(new Runnable() {
public void run() {
// capture qr, this will not block because it's in thread,
// do all long running/blocking operations here, in this
// thread
final String qr = captureQrCode();
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.TimerTask;
@sarxos
sarxos / TypeReference.java
Created August 28, 2015 17:39
Pass type reference from generic argument
package com.fasterxml.jackson.core.type;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
/**
* This generic abstract class is used for obtaining full generics type information
* by sub-classing; it must be converted to {@link ResolvedType} implementation
* (implemented by <code>JavaType</code> from "databind" bundle) to be used.
* Class is based on ideas from
@sarxos
sarxos / gist:d173cf554edebdb5ba42
Created August 14, 2015 09:54
Eclipse slf4j log template
${imp:import(org.slf4j.Logger,org.slf4j.LoggerFactory)}
/**
* I'm the logger.
*/
private static final Logger LOG = LoggerFactory.getLogger(${enclosing_type}.class);${cursor}
@sarxos
sarxos / gist:1c0b697aa04429e1460b
Created June 26, 2015 07:46
Pure JRE (no HK2, no Spring, no Guice) Java service registration by Maven plugin
<plugins>
<plugin>
<groupId>eu.somatik.serviceloader-maven-plugin</groupId>
<artifactId>serviceloader-maven-plugin</artifactId>
<version>1.0.2</version>
<configuration>
<services>
<service>foo.bar.service.ServiceInterface</service>
</services>
</configuration>
@sarxos
sarxos / XugglerVideoTest.java
Last active January 17, 2020 08:19
Xuggler RTSP Source Code
import com.xuggle.mediatool.IMediaListener;
import com.xuggle.mediatool.IMediaReader;
import com.xuggle.mediatool.IMediaWriter;
import com.xuggle.mediatool.MediaListenerAdapter;
import com.xuggle.mediatool.ToolFactory;
import com.xuggle.mediatool.event.IVideoPictureEvent;
import com.xuggle.xuggler.IError;
import com.xuggle.xuggler.demos.VideoImage;
import java.awt.image.BufferedImage;