Skip to content

Instantly share code, notes, and snippets.

View gekomad's full-sized avatar

Giuseppe Cannella gekomad

View GitHub Profile
@gekomad
gekomad / getListOfFiles.scala
Last active February 4, 2020 12:23
Get a list of files that are in a directory and subdirectories
def recursiveListFiles(f: File): ArraySeq[File] = {
val these = f.listFiles
ArraySeq.from(these ++ these.filter(_.isDirectory).flatMap(recursiveListFiles))
}
///
import java.io.File
def getListOfFiles(dir: String): List[File] = {
def go(dir: File): List[File] = dir match {
@gekomad
gekomad / CirceDropNull.scala
Created October 16, 2019 11:13
Scala Circe DropNull
def _reduce(l: Seq[(String, Json)]): Json = l match {
case ::(x, xs) =>
if (x._2.isNull) {
dropNull(Json.fromFields(xs))
} else {
val jj = Json.fromJsonObject(JsonObject((x._1, dropNull(x._2))))
xs match {
case Nil => jj
case _ => dropNull(Json.fromFields(xs)).deepMerge(jj)
}
@gekomad
gekomad / Spinlock.h
Created January 30, 2019 22:28
A C++ shared Spinlock implementation
#pragma once
#include <atomic>
using namespace std;
#ifdef _WIN32
#include <intrin.h>
#pragma intrinsic(_InterlockedExchange)
#define LOCK_TEST_AND_SET(_lock) _InterlockedExchange(&_lock, 1)
@gekomad
gekomad / logger.h
Last active January 30, 2019 22:27
C++ Compile time logger
#pragma once
#include "../util/Singleton.h"
#include "../util/Time.h"
#include <iostream>
#include "../threadPool/Spinlock.h"
using namespace std;
namespace _logger {
@gekomad
gekomad / ZipHelper.scala
Last active January 25, 2019 11:08
Scala Zip with cats IO
package trackit.helper
import java.io.{File, FileInputStream, FileOutputStream}
import cats.effect.IO
import cats.effect.Resource.fromAutoCloseable
import org.apache.commons.compress.archivers.{ArchiveOutputStream, ArchiveStreamFactory}
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry
import org.apache.commons.compress.utils.IOUtils
object ZipHelper {
[ -f .bumpversion.cfg ] || echo "Error file .bumpversion.cfg does not exist"
cp .bumpversion.cfg /tmp/.bumpversion.cfg
printf "choice: minor|major|patch ";read version
bumpversion --config-file /tmp/.bumpversion.cfg $version
NEXT_VERSION=$(grep current_version /tmp/.bumpversion.cfg |awk -F "= " '{print $2}') && echo "next version: $NEXT_VERSION"
git flow release start $NEXT_VERSION
cp /tmp/.bumpversion.cfg .
#update build.sbt
sed -r -i 's/^version := "(\b[0-9]{1,3}\.){2}[0-9]{1,3}\b"'/"version := \"$NEXT_VERSION\""/ build.sbt
@gekomad
gekomad / Currying.hs
Created July 17, 2018 12:51
Currying Haskell / Scala
module Currying where
addF :: Integer -> Integer -> Integer
addF a b = a + b
res = addF 1 2
main :: IO ()
main = print res
@gekomad
gekomad / Mutex.h
Created March 6, 2016 19:21
C++ Mutex class
/*
Cinnamon UCI chess engine
Copyright (C) Giuseppe Cannella
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,