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.cr
Created July 20, 2016 09:47 — forked from costajob/fact.cr
Factorial implementation using Big numbers in Ruby, GO and Crystal
require "big_int"
def fact(n)
return 1 if n == 0
n * fact(n - 1)
end
n = BigInt.new(ARGV[0])
puts fact(n)
@chemacortes
chemacortes / reducebykey.py
Last active May 30, 2021 21:22 — forked from astrojuanlu/reducebykey.py
Python implementation of Spark reduceByKey()
from functools import reduce
from itertools import groupby
from operator import (itemgetter,add)
def reduceByKey(func, iterable):
"""Reduce by key.
Equivalent to the Spark counterpart
Inspired by http://stackoverflow.com/q/33648581/554319
@chemacortes
chemacortes / Pi.scala
Last active August 29, 2015 14:14 — forked from tuxdna/Pi.scala
import akka.actor._
import akka.routing.RoundRobinRouter
import akka.util.Duration
import akka.util.duration._
sealed trait PiMessage
case object Calculate extends PiMessage
case class Work(start: Int, nrOfElements: Int) extends PiMessage
case class Result(value: Double) extends PiMessage
case class PiApproximation(pi: Double, duration: Double) extends PiMessage
package week6
import scala.io.Source
object collections {
/* read a file of words */
val in = Source.fromURL("http://lamp.epfl.ch/files/content/sites/lamp/files/teaching/progfun/linuxwords.txt")
/* create a list and filter all words where *all* their characters are not letters (like dashes) */
val words = in.getLines.toList filter (word => word forall (chr => chr.isLetter))
""""Create "The Matrix" of binary numbers scrolling vertically in your terminal.
original code adapted from juancarlospaco:
- http://ubuntuforums.org/showpost.php?p=10306676
Inspired by the movie: The Matrix
- Corey Goldberg (2013)
Requires: