Skip to content

Instantly share code, notes, and snippets.

View chemacortes's full-sized avatar

Chema Cortés chemacortes

  • DGA
  • Zaragoza, Spain
View GitHub Profile
@chemacortes
chemacortes / futur.py
Created April 23, 2020 22:29
Simulación de uso de futures masivos
# -*- coding: utf-8 -*-
"""
Created on Fri Jun 12 18:29:33 2015
@author: chema
"""
from concurrent.futures import (
Future, ProcessPoolExecutor, ThreadPoolExecutor, TimeoutError, as_completed)
from itertools import islice
@chemacortes
chemacortes / birthday.scala
Last active February 27, 2020 00:26
Formula for calculating the birthday paradox
def birthday(n: Int) = {
1 - (0 until n).map(1 - BigDecimal(_) / 365).product
}
assert(birthday(23) == BigDecimal("0.5072972343239854072254172283370325"))
@chemacortes
chemacortes / fact_par.sc
Last active February 17, 2022 15:55
Scala parallel collections
#!/usr/bin/env -S scala-cli shebang
//> using scala "3.1.0"
//> using lib "org.scala-lang.modules::scala-parallel-collections:1.0.4"
import scala.collection.parallel.CollectionConverters._
def fact(n: BigInt) =
(n to 1 by -1).par.product
@chemacortes
chemacortes / rand17.py
Created July 6, 2019 15:30
Generate randint(1,7) using randint(1,5) as the only random function
from random import randint
from functools import partial
from collections import Counter
from itertools import cycle
from typing import Iterable
# única función random que se permite usar
rand5 = partial(randint, 1, 5)
# yapf: disable
@chemacortes
chemacortes / Default.txt
Last active April 3, 2019 13:17
Plantillas personalizadas de ZIM
======= [% page.basename %] =======
//Creado el [% strftime("%Y-%m-%d") %]//
TODO: @_revisar
@chemacortes
chemacortes / Default.txt
Created April 3, 2019 13:15
Plantillas personalizadas de ZIM
======= [% page.basename %] =======
//Creado el [% strftime("%Y-%m-%d") %]//
TODO: @_revisar
@chemacortes
chemacortes / new_project.sh
Created April 1, 2019 01:12
Create a Scala 3 (Dotty) project with SBT
# create a new Dotty project
sbt new lampepfl/dotty.g8
# create a dotty project that cross compiles with scala 2
sbt new lampepfl/dotty-cross.g8
# start a dotty reply from within your sbt project
$ sbt
> console
@chemacortes
chemacortes / fact-fiddle.html
Created March 12, 2019 14:25
fiddle example
<iframe height="400px" frameborder="0" style="width: 100%" src="https://embed.scalafiddle.io/embed?sfid=HiIQqkL/11&theme=dark&layout=v50"></iframe>
@chemacortes
chemacortes / zip-function.ts
Created February 20, 2019 14:37
Zip in typescript
function zipWith<T, R, S>(as: T[], bs: R[], conv: (a: T, b: R) => S): S[] {
return as.map((a, i) => conv(a, bs[i]));
}
function zip<T, R>(as: T[], bs: R[]) {
return zipWith(as, bs, (a, b) => [a, b]);
}
@chemacortes
chemacortes / TypeClass.scala
Created December 27, 2018 00:48
An example of typeclasses with scala
package types
object Math {
import annotation.implicitNotFound
@implicitNotFound("No member of type class NumberLike in scope for ${T}")
trait NumberLike[T] {
def plus(x: T, y: T): T