Skip to content

Instantly share code, notes, and snippets.

View AlexRogalskiy's full-sized avatar
🛰️
Work on stuff that matters

Alexander AlexRogalskiy

🛰️
Work on stuff that matters
View GitHub Profile
@AlexRogalskiy
AlexRogalskiy / sequence.scala
Created December 19, 2020 20:30
Scala sequence
import scala.reflect.ClassTag
import scala.collection.mutable.WrappedArray
import scala.collection.mutable.ArrayLike
def ASeq[T](elt: T*)(implicit ct: ClassTag[T]): IndexedSeq[T] = {
val a = elt.toArray.clone
a.deep.asInstanceOf[IndexedSeq[T]]
}
val a = Array(1,2,3) //> a : Array[Int] = Array(1, 2, 3)
@AlexRogalskiy
AlexRogalskiy / akka_converter.scala
Created December 19, 2020 20:31
Scala akka converter
import scala.concurrent.duration.{Duration => ScalaDuration}
import scala.concurrent.{ExecutionContext => ScalaExecutionContext, Future => ScalaFuture, Promise => ScalaPromise}
import scala.util.{Success, Failure}
import akka.dispatch.{ExecutionContext => AkkaExecutionContext, Future => AkkaFuture, Promise => AkkaPromise}
import akka.util.{Duration => AkkaDuration}
/**
* Some compatibility implicit conversions to deal with akka as if it might already be a newer version
* (using scala interfaces instead of akka).
@AlexRogalskiy
AlexRogalskiy / docker_init.sh
Created December 19, 2020 20:45
Docket download with initialization
curl -sSL https://get.docker.com/ | sh
sudo usermod -aG docker $USER && exec sg docker newgrp `id -gn`
sudo systemctl start docker
sudo curl -sSL https://github.com/docker/compose/releases/download/1.16.1/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
@AlexRogalskiy
AlexRogalskiy / tmuxinator_config.sh
Created December 19, 2020 20:54
Tmuxinator terminal configuration
sudo apt-get install ruby
gem install tmuxinator
export EDITOR='vim
tmuxinator new system-monitor
export TERM=xterm-256color
name: system-monitor
root: ~/
windows:
@AlexRogalskiy
AlexRogalskiy / FileReaderThread.kt
Created December 19, 2020 22:33
Thread file reader
import java.io.File
import java.util.concurrent.LinkedBlockingQueue
class FileReaderThread(val queue : LinkedBlockingQueue<ByteArray>, val filename : String) : Thread() {
override fun run() {
File(filename).readLines()
}
}
@AlexRogalskiy
AlexRogalskiy / UserDaoImpl.java
Created December 20, 2020 08:03
Java SpringBoot repository
@Repository
public class UserDaoImpl implements UserDao {
@Autowired
private JdbcTemplate jdbcTemplate;
private final String INSERT_USER_QUERY = "INSERT INTO USER(id,first_name,last_name,gender,age) VALUES(?,?,?,?,?)";
private final String UPDATE_USER_QUERY = "UPDATE user SET first_name=?,last_name=?,gender=?,age=? WHERE id=?";
private final String DELETE_USER_QUERY = "DELETE FROM user WHERE id=?";
private final String GET_USER_BY_ID_QUERY = "SELECT * FROM user where id = ?";
@AlexRogalskiy
AlexRogalskiy / scoold.Dockerfile
Last active December 20, 2020 10:22
Docker scoold example
FROM openjdk:8-jdk-alpine
RUN apk --update add git openssh maven && \
rm -rf /var/lib/apt/lists/* && \
rm /var/cache/apk/*
ENV BOOT_SLEEP=0 \
JAVA_OPTS=""
RUN addgroup -S scoold && adduser -S -G scoold scoold && \
@AlexRogalskiy
AlexRogalskiy / random.kt
Last active December 20, 2020 10:22
Kotlin random text
fun genRandomString(): String {
val chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
var passWord = ""
for (i in 0..Random.nextInt(3, 35)) {
passWord += chars[Math.floor(Math.random() * chars.length).toInt()]
}
return passWord
}
fun genRandomText() : String {
@AlexRogalskiy
AlexRogalskiy / scalastyle-config.xml
Last active December 20, 2020 10:22
Scala style configuration
<!--
~ Licensed to the Apache Software Foundation (ASF) under one or more
~ contributor license agreements. See the NOTICE file distributed with
~ this work for additional information regarding copyright ownership.
~ The ASF licenses this file to You under the Apache License, Version 2.0
~ (the "License"); you may not use this file except in compliance with
~ the License. You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
@AlexRogalskiy
AlexRogalskiy / Base64Coder.java
Last active December 20, 2020 10:22
Base64 encoder/decoder utility
import java.nio.charset.Charset;
//Copyright 2003-2010 Christian d'Heureuse, Inventec Informatik AG, Zurich, Switzerland
//www.source-code.biz, www.inventec.ch/chdh
//
//This module is multi-licensed and may be used under the terms
//of any of the following licenses:
//
//EPL, Eclipse Public License, http://www.eclipse.org/legal
//LGPL, GNU Lesser General Public License, http://www.gnu.org/licenses/lgpl.html