Skip to content

Instantly share code, notes, and snippets.

View chemacortes's full-sized avatar

Chema Cortés chemacortes

View GitHub Profile
""""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:
@chemacortes
chemacortes / mutabilidad de listas.ipynb
Last active December 15, 2015 01:08
Mutabilidad de listas. Un artículo de ch3m4.org.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@chemacortes
chemacortes / Mutable o Inmutable.ipynb
Last active December 15, 2015 07:39
¿Tiene sentido tener "duplicados" algunos tipos en sus dos versiones, mutable e inmutable?
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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))
@chemacortes
chemacortes / calcFreqs.scala
Last active January 12, 2020 01:51
Char frequencies (*Recursive and non-recursive versions*) in scala
//Non-recursive version
def calcFreq(s:String):List[(Char,Int)] =
s.toLowerCase groupBy (identity) mapValues (_.length) toList
@chemacortes
chemacortes / calcFreq.py
Created May 2, 2013 11:16
Char frequencies in python
def calcFreq(s):
return [(c,s.count(k)) for c in set(s)]
@chemacortes
chemacortes / pouring.scala
Last active December 17, 2015 10:09
Solución del problema "Pouring Water".
class Pouring(capacity: Vector[Int]) {
// States
type State = Vector[Int]
val initialState = capacity map (x ⇒ 0)
// Moves
trait Move {
@chemacortes
chemacortes / gist:5713746
Created June 5, 2013 13:13
Forget about #Unicode problems on ANY Version of #Python !
# put this after the imports on your .py files
try: # py2
str, range, input = unicode, xrange, raw_input # lint:ok
except NameError: # py3
buffer, long = memoryview, int # lint:ok
@chemacortes
chemacortes / Readme.md
Last active September 19, 2022 09:14
Juego de la vida de Conway realizado en numpy y animado con matplotlib. Basado en el artículo de Juan Luis Cano (@Juanlu001) en http://pybonacci.wordpress.com/2012/11/30/juego-de-la-vida-de-conway-con-python-usando-numpy/

El juego de la vida de Conway

Aunque hay muchas variantes del juego de la vida, nos vamos a centrar en la que publicó originalmente Conway en 1970.

El juego de la vida es un juego de cero jugadores, lo que quiere decir que su evolución está determinada por el estado inicial y no necesita ninguna entrada de datos posterior (Wikipedia).

Las reglas son las siguientes:

  • El tablero es una rejilla de celdas cuadradas (n x m) que tienen dos posibles estados: viva y muerta.
@chemacortes
chemacortes / trait.py
Last active December 21, 2015 21:28
Pattern for traits in python3
from abc import ABCMeta, abstractmethod
class Trait(ABCMeta):
pass
class MyTrait(metaclass=Trait):
@abstractmethod
def __str__(self):
raise NotImplementedError("Calling an abstract method")