Skip to content

Instantly share code, notes, and snippets.

View rbonvall's full-sized avatar

Roberto Bonvallet rbonvall

View GitHub Profile
@rbonvall
rbonvall / redirect.py
Created April 4, 2014 20:36
Redirect both stdin and stdout of a process to a PyQt text edit.
from PyQt4 import QtGui, QtCore, uic
def p(x):
print x
class MainWindow(QtGui.QMainWindow):
def __init__(self):
QtGui.QWidget.__init__(self)
uic.loadUi('redirect.ui', self)
@rbonvall
rbonvall / rut.py
Created July 5, 2010 23:56
Dígito verificador del RUT en Python
# encoding=utf-8
# Obtener el dígito verificador del RUT en Python.
#
# La función recibe el RUT como un entero,
# y entrega el dígito verificador como un entero.
# Si el resultado es 10, el RUT es "raya k".
from itertools import cycle
@rbonvall
rbonvall / ejemplos.scala
Last active July 13, 2018 21:28
Ejemplos meetup de Scala, 12 de julio de 2018
case class Point(x: Double, y: Double) {
def +(p: Point) = Point(x + p.x, y + p.y)
def *(a: Double) = Point(a * x, a * y)
def distTo(that: Point) = {
val Point(dx, dy) = this + that * -1
math.sqrt(dx * dx + dy * dy)
}
}
@rbonvall
rbonvall / kolakoski.scala
Created January 12, 2018 21:15
Kolakoski prototype
val integers = Stream.from(0)
object E1 {
val evenIntegers = integers.filter(_ % 2 == 0)
}
object E2 {
val evenIntegers = integers.map(_ * 2)
}
object E3 {
@rbonvall
rbonvall / 16.scala
Created December 29, 2017 15:59
AoC day 16
sealed trait Move
case class Spin(x: Int) extends Move
case class Exchange(a: Int, b: Int) extends Move
case class Partner(a: Char, b: Char) extends Move
object Move {
val spin = """s(\d+)""".r
val exchange = """x(\d+)/(\d+)""".r
val partner = """p(\w)/(\w)""".r
val fromString: PartialFunction[String, Move] = {
case spin(x) ⇒ Spin(x.toInt)
#!/usr/bin/env python3.0
import sys, array, tempfile, heapq
assert array.array('i').itemsize == 4
def intsfromfile(f):
while True:
a = array.array('i')
a.fromstring(f.read(4000))
if not a:
#!/bin/bash
die () {
echo "$1"
exit 1
}
get-scala-version () {
curl http://www.scala-lang.org/ 2> /dev/null | grep scala-version | perl -pe 's/\D*([0-9.]+)\D*/$1/'
}
@rbonvall
rbonvall / rut.scala
Created August 1, 2016 19:05
Dígito verificador del rut en Scala
val rut1 = 15666777 // - 3
val rut2 = 23456789 // - 6
val rut3 = 22333444 // - k
// 1 5 6 6 6 7 7 7
// ...3 2 7 6 5 4 3 2
// 3 10 42 36 30 28 21 14 → (+) → 184
// -184 mod 11 = 3
//////////////////////////////////////////////////
// //
// El patrón del match //
// //
// Roberto Bonvallet //
// @rbonvall //
// //
// Martes 17 de mayo de 2016 //
// Santiago Scala Meetup //
// //
//////////////////////////////////////////////////
// //
// El patrón del match //
// //
// Roberto Bonvallet //
// @rbonvall //
// //
// Martes 17 de mayo de 2016 //
// Santiago Scala Meetup //
// //