Skip to content

Instantly share code, notes, and snippets.

View hugoferreira's full-sized avatar

Hugo Sereno Ferreira hugoferreira

View GitHub Profile
@hugoferreira
hugoferreira / bot.rb
Created April 18, 2011 22:26
FEUP Bot
#!/usr/bin/env ruby
require 'socket'
class SimpleIrcBot
def initialize(server, port, channel)
@channel = channel
@socket = TCPSocket.open(server, port)
say "NICK BytterBot"
import collection.immutable.{TreeMap, SortedMap}
import collection.SortedMapLike
import org.specs2.mutable._
import org.specs2.ScalaCheck
import scalaz._
import Scalaz._
object Timeline {
def apply[A, B](l: Traversable[(B, A)])(implicit m: Manifest[B]) = m.toString match {
case "Int" => new Timeline(l.map(x => x._1.asInstanceOf[Int].toLong -> x._2).toMap)
import akka.actor._
import akka.pattern.ask
import akka.util.Timeout
import akka.util.duration._
final case class Ping(msg: String)
final case class Pong(msg: String)
class Ponger extends Actor {
def receive = {
@hugoferreira
hugoferreira / gist:3309826
Created August 10, 2012 00:57
Gambozino Proof
(T1) = It is not true that if it always has been the case that a Gambozino-like being exists then a Gambozino-like being exists and it is always going to be the case that a Gambozino-like being exists in (n).
(T2) = It always has been the case that a Gambozino-like being existed in (n).
(T3) = It is not true that a Gambozino-like being exists and it is always going to exist in (n).
(T4) = A Gambozino-like being does not exist in (n)
(T4)' = It is not the case that a Gambozino-like being will always exist in (n).
(T5) = In sometime in the future it will be the case that a Gambozino-like being will not exist in (n).
(T6) = (n) occurred before (k).
(T7) = A Gambozino-like being does not exist in (k).
(T8) = (k) occurred before (n). (Reflexive Rule)
(T9) = A Gambozino-like being exists in (k).
@hugoferreira
hugoferreira / gist:3785369
Created September 26, 2012 00:58
Zeros in Scalaz
scala> mzero[Int]
res4: Int = 0
scala> mzero[List[Int]]
res5: List[Int] = List()
scala> mzero[Map[Int, Double]]
res6: Map[Int,Double] = Map()
scala> mzero[Map[Int, Boolean]]
@hugoferreira
hugoferreira / gist:3861363
Created October 9, 2012 20:55 — forked from jcazevedo/gist:3849885
Simple Polymorphic Stack Machine
import scala.util.Random
object PStack {
type Any = PStack[_, _]
}
sealed trait PStack[A, B <: PStack.Any] {
def ++[C, D <: PStack.Any](op: Op[A, B, C, D]): PStack[C, D] = op.execute(this)
}
@hugoferreira
hugoferreira / gist:4048818
Created November 9, 2012 22:45
Genetic Algorithms in Scala
import annotation.tailrec
import util.Random
object main extends App {
val target = "as armas e os baroes assinalados"
val genePool = Array('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',' ')
def fitness(src: String): Double = src.zip(target).count { case (s, t) => s == t }
val petri = new GeneticExploration[Char, String](0.01, 500, genePool, cs => new String(cs.toArray), fitness, _.exists(_ == target))
@hugoferreira
hugoferreira / UnixUtilities.scala
Last active April 11, 2016 23:47
Unix utilities in Scala
import java.io.{BufferedOutputStream, FileOutputStream, FileInputStream, BufferedInputStream}
import java.util.zip.{GZIPOutputStream, GZIPInputStream}
import scala.io.{Source, Codec}
import scala.language.{reflectiveCalls, implicitConversions}
object main extends App {
import utils._
val inFile = "/Users/bytter/Documents/Development/shiftforward/spitz/coopeventsfiltered.log.gz"
@hugoferreira
hugoferreira / SierpinskiTriangle.scala
Created June 14, 2014 15:38
Artistic Sierpinski Triangle (Playing with Scala.JS)
import org.scalajs.dom
final case class Pt(x: Double, y: Double)
@JSExport
object SierpinskiTriangle {
val corners = Seq(
Pt(canvas.width/2, 0),
Pt(0, canvas.height),
Pt(canvas.width, canvas.height)
@hugoferreira
hugoferreira / CoreWar.scala
Last active November 13, 2020 20:16
Scala.js implementation of the MARS simulator (Core War)
/**
* Created by Hugo Sereno Ferreira on 15/06/14.
*/
import org.scalajs.dom
import scala.collection._
sealed trait Opcode
object Mov extends Opcode { override def toString = "MOV" }
object Add extends Opcode { override def toString = "ADD" }