Skip to content

Instantly share code, notes, and snippets.

View gekomad's full-sized avatar

Giuseppe Cannella gekomad

View GitHub Profile
@gekomad
gekomad / ftp.scala
Created November 5, 2024 14:34
FTP scala and cats
import cats.effect.IO
import cats.effect.Resource.fromAutoCloseable
import org.apache.commons.net.ftp.{FTP, FTPClient}
import org.slf4j.{Logger, LoggerFactory}
import cats.implicits._
import java.io._
import scala.util.Try
/* use:
@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 {