Skip to content

Instantly share code, notes, and snippets.

View chemacortes's full-sized avatar

Chema Cortés chemacortes

View GitHub Profile
@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
@chemacortes
chemacortes / exercise1.hs
Created September 4, 2018 22:38
Own definitions of scanr and scanl
-- 1.Write your own definition of scanr, first using recursion, and then using foldr.
-- Do the same for scanl first using recursion then foldl.
import Prelude hiding (scanl, scanr)
scanr :: (a -> b -> b) -> b -> [a] -> [b]
scanr _ acc [] = [acc]
scanr f acc (x:xs) = f x (head qs) : qs
where qs = scanr f acc xs
@chemacortes
chemacortes / TypePractice.hs
Created September 4, 2018 22:26
Natural implementation (Church)
module TypePractice where
data Nat = Zero
| Succ Nat
deriving Show
zero = Zero
one = Succ zero
two = Succ one
three = Succ two