Skip to content

Instantly share code, notes, and snippets.

@kastoestoramadus
kastoestoramadus / hocon.py
Last active February 27, 2025 11:19
python script
import sys
import ddpyhocon
def format_hocon(input_file, output_file):
with open(input_file, 'r') as infile:
# Parse the HOCON file into a Python dictionary
config = ddpyhocon.ConfigFactory.parse_file(infile)
with open(output_file, 'w') as outfile:
# Write the formatted HOCON file
package com.nordea
import java.io.File
import java.nio.file.{Path, Paths}
import org.ekrich.config.{Config, ConfigFactory, ConfigParseOptions, ConfigRenderOptions}
object HoconFormatter {
def main(args: Array[String]): Unit = {
println(s"Running HOCON formatter. pwd: ${ new File(".").getAbsolutePath}")
@kastoestoramadus
kastoestoramadus / second
Last active April 25, 2025 14:25
second
package org.ekrich.config
import java.io.File
import java.nio.file.{Path, Paths}
import java.nio.file.{Files, Paths}
import java.nio.charset.StandardCharsets
object Formatter {
def main(args: Array[String]): Unit = {
println(s"Running HOCON formatter. pwd: ${new File(".").getAbsolutePath}")
@kastoestoramadus
kastoestoramadus / TakeWhileByFoldRight.scala
Last active June 28, 2017 07:54
WhyFoldRight works here
def takeWhileR[A](s: Stream[A], f: A => Boolean): Stream[A] =
s.foldRight(Stream[A]())((h, t) =>
if (f(h)) Stream(h) #::: t
else Stream.apply())
def takeWhileL[A](s: Stream[A], f: A => Boolean): Stream[A] =
s.foldLeft(Stream[A]())((t, h) =>
if (f(h)) Stream(h) #::: t
else Stream.apply())
@kastoestoramadus
kastoestoramadus / ImplicitTest.scala
Last active June 28, 2017 07:46
Scala implicitly. Where to override it?
package snippet
/**
* Created by walidus on 27/06/17. How to override the implicit val with c?
*/
object ImplicitTest extends App{
implicit val overrider = MyClass.c // works
Util.print()
}
object Util {
byobu new -d -s $$ && tmux send -t $$ 'sbt -mem 1600 run' ENTER
Replace all numbers with that number of '?':
java like:
import java.util.regex.Pattern
val NKasString = "?"
val p = Pattern.compile("[0-9]+")
val m = p.matcher("\"a2a12a2\"")
val sb = new StringBuffer()
while (m.find()) {
@kastoestoramadus
kastoestoramadus / notesSendMail
Last active June 28, 2017 07:58
batch sendmail scala and bash
import sys.process._
import java.time.LocalDateTime
object SendMailMain {
def main(args: Array[String]) {
val start = LocalDateTime.now()
(1 to 1000).par.foreach { i =>
print(s"$i ")
val out = s"echo anything $i" #| s"sendmail 123456789@[192.168.2.118]" !;
@kastoestoramadus
kastoestoramadus / codiDemo.scala
Created October 28, 2015 05:53
few version of solutions with one stuff to discuiss
import scala.annotation.tailrec
import scala.collection.JavaConversions._
object Solution {
def solutionShortest(A: Array[Int]): Int = {
// fake from https://github.com/khatwaniNikhil/codility-scala/blob/master/src/com/codility/lesson1/TapeEquilibrium.scala
val sumAccum = A.scanLeft(0L)(_ + _).tail
(1 to A.size - 1).map(p =>
scala.math.abs(
// generate cyclic sending mail wiht rotation on chosen data
private def generateMailsSending(sentmails: Meter): Cancellable = {
import sys.process._
val getNextHeaderSet: () => ClientHeaders = {
def b(): Stream[ClientHeaders] = headers.toStream #::: b
var cyclicIterator: Stream[ClientHeaders] = b()
() => {
val tail = cyclicIterator.tail