Skip to content

Instantly share code, notes, and snippets.

View ayoub-benali's full-sized avatar

Ayoub Benali ayoub-benali

View GitHub Profile
@bwicklund
bwicklund / s3_file_combine.py
Last active March 12, 2023 08:27
S3 file Concatenation/Combination. S3 Spark file merge.
import argparse
import boto3
import os
import threading
from fnmatch import fnmatch
# S3 multi-part upload parts must be larger than 5mb
MIN_S3_SIZE = 6000000
LOG_LEVEL = 'INFO'
@tifletcher
tifletcher / FutureUtils.scala
Last active May 17, 2024 04:52
parallel and sequential futures
import scala.concurrent.Future
implicit val ec = scala.concurrent.ExecutionContext.global
def future(name: String): Future[String] = {
println(s"constructing $name")
Future {
Thread.sleep(1000)
println(s"resolved $name")
name

Applied Functional Programming with Scala - Notes

Copyright © 2016-2018 Fantasyland Institute of Learning. All rights reserved.

1. Mastering Functions

A function is a mapping from one set, called a domain, to another set, called the codomain. A function associates every element in the domain with exactly one element in the codomain. In Scala, both domain and codomain are types.

val square : Int => Int = x => x * x
@etorreborre
etorreborre / effForReal.scala
Last active September 7, 2016 03:22
Using Eff on a "real" use case
/**
* We need to create bidirectional maps for items having both a name an an id
* When we collect items, we need to check that there are no duplicated names or ids for a given item
*/
// first let's define bi-directional maps
case class BiMap[K, V](keys: Map[K, V], values: Map[V, K]) {
def add(entry: BiMapEntry[K, V]): BiMap[K, V] =
BiMap(keys + (entry.key -> entry.value), values + (entry.value -> entry.key))
@pauca
pauca / gz.scala
Last active April 30, 2022 06:14
scala read / write from compressed gz
import java.io._
import java.util.zip._
import scala.io.Source
var in = new GZIPInputStream(new FileInputStream("test.gz"))
// write setup in different objects to close later properly (important for big files )
var fos = new FileOutputStream("test2.gz")
var gzos = new GZIPOutputStream( fos )
var w = new PrintWriter(gzos)