Skip to content

Instantly share code, notes, and snippets.

@regis-leray
regis-leray / gist:6a296f9511b54930725e
Last active August 29, 2015 14:11
wicket dynamic panel
public class TestWicket {
WicketTester tester = new WicketTester();
@BeforeMethod
public void setUp() throws Exception {
tester = new WicketTester();
}
@AfterMethod
@regis-leray
regis-leray / gist:51682de444ff4027825d
Created February 17, 2015 15:36
Mock Bean Factory
import org.mockito.internal.util.MockUtil;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessorAdapter;
/**
* Do not process wiring for mock which contains @Autowired / @inject annotations
*/
public class MockBeanFactory extends InstantiationAwareBeanPostProcessorAdapter {
private static final MockUtil mockUtil = new MockUtil();
<plugin>
<groupId>org.codehaus.groovy.maven</groupId>
<artifactId>gmaven-plugin</artifactId>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>execute</goal>
</goals>
public class MockPostProcessorAdapter extends InstantiationAwareBeanPostProcessorAdapter {
private static final MockUtil mockUtil = new MockUtil();
public MockPostProcessorAdapter() {
super();
}
@Override
public boolean postProcessAfterInstantiation(Object bean, String beanName) throws BeansException {
@regis-leray
regis-leray / Valve.scala
Last active October 14, 2016 13:54
Valve for Akka stream
import akka.stream.stage.{GraphStageLogic, GraphStageWithMaterializedValue, InHandler, OutHandler}
import akka.stream.{Attributes, FlowShape, Inlet, Outlet}
trait ValveSwitch {
def open: Unit
def close: Unit
}
class Valve[A](mode: ValveMode = ValveMode.Open) extends GraphStageWithMaterializedValue[FlowShape[A, A], ValveSwitch] {
https://github.com/juretta/git-pastiche
https://askubuntu.com/questions/31216/setting-up-aliases-in-zsh
https://www.cyberciti.biz/tips/bash-aliases-mac-centos-linux-unix.html
postman
@regis-leray
regis-leray / WriteChannelSink.scala
Created November 17, 2017 18:46
WriteChannelSink
private class WriteChannelSource(channel: WriteChannel) extends GraphStage[SinkShape[ByteString]] {
val in: Inlet[ByteString] = Inlet.create[ByteString]("WriteChannelSource.in")
val shape: SinkShape[ByteString] = SinkShape.of(in)
override def createLogic(inheritedAttributes: Attributes): GraphStageLogic = new WriteChannelStageLogic()
private class WriteChannelStageLogic extends GraphStageLogic(shape) with InHandler {
override def onPush(): Unit = {
val data = grab(in)
@regis-leray
regis-leray / WriteChannelSink.scala
Last active November 17, 2017 18:49
WriteChannelSink
// with graph
private object WriteChannelSource {
def apply(channel: WriteChannel): WriteChannelSource = new WriteChannelSource(channel)
}
private class WriteChannelSource(channel: WriteChannel) extends GraphStage[SinkShape[ByteString]] {
val in: Inlet[ByteString] = Inlet.create[ByteString]("WriteChannelSource.in")
val shape: SinkShape[ByteString] = SinkShape.of(in)
def shortId(id: UUID, length: Int = 10): String = {
(id.toString.reverse.take(Math.floor(length/2).toInt) + "-" + UUID.randomUUID().toString.reverse.take(Math.ceil(length/2).toInt)).toUpperCase
}
@regis-leray
regis-leray / nas.java
Created January 8, 2020 15:57
NAs decoding
import com.oss.nas1570.Nas1570
import com.oss.nas1570.NASCoder;
import com.oss.nas1570.Nas1570;
import java.nio.ByteBuffer;
public class Test {
public static void main(String[] args) throws Throwable {
// NAS 2.0.0 - nasjava-r15.7.0