Skip to content

Instantly share code, notes, and snippets.

@regis-leray
regis-leray / change_scala_version.sh
Created December 29, 2021 20:52 — forked from zxh/change_scala_version.sh
change scala version via brew
# show all scala versions
brew search scala
# install specific version, maybe scala 2.11
brew install scala@2.11
# unlink current scala version
brew unlink scala
# link new scala version

Problem

I have two Github accounts: oanhnn (personal) and superman (for work). I want to use both accounts on same computer (without typing password everytime, when doing git push or pull).

Solution

Use ssh keys and define host aliases in ssh config file (each alias for an account).

How to?

  1. Generate ssh key pairs for accounts and add them to GitHub accounts.
@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
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 / 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)
@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)
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 / 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] {
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 {
<plugin>
<groupId>org.codehaus.groovy.maven</groupId>
<artifactId>gmaven-plugin</artifactId>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>execute</goal>
</goals>