Skip to content

Instantly share code, notes, and snippets.

View hugoferreira's full-sized avatar

Hugo Sereno Ferreira hugoferreira

View GitHub Profile
@hugoferreira
hugoferreira / asyncqueue-test.ts
Last active April 2, 2019 01:33
Tests the behaviour of an AsyncQueue by doing a random permutation of Enqueues and Dequeues
const isArraySorted = require('is-array-sorted')
async function testAsyncQueueBehavior(nOps: number): Promise<Boolean> {
const result = new Array<number>()
const q = new AsyncQueue<number>()
const enqueue = (m: number) => q.enqueue(m)
const dequeue = () => q.dequeue()
const promises = Array<Promise<void>>()
<?php print "Hello worldfçskdljflksdjfskfjdkfsjdfkl" ?>

Keybase proof

I hereby claim:

  • I am hugoferreira on github.
  • I am bytter (https://keybase.io/bytter) on keybase.
  • I have a public key ASAMmL1U1qmV9_HFtZ39FPzJnyWqYE2MUaog1jaexvYTjAo

To claim this, I am signing this object:

@hugoferreira
hugoferreira / asyncqueue-no-debug.ts
Last active May 17, 2018 23:31
Asynchronous Bounded Queue
class AsyncQueue<T> {
waitingEnqueue = new Array<() => void>()
waitingDequeue = new Array<() => void>()
enqueuePointer = 0
dequeuePointer = 0
queue = Array<T>()
maxSize = 1
async enqueue(x: T) {
if ((this.queue.length + 1) > this.maxSize || this.waitingDequeue.length > 0) {
{
"$schema": "https://vega.github.io/schema/vega-lite/v2.json",
"width": 500,
"height": 200,
"data": {"values":
[{"len":1,"p":0.631794},{"len":2,"p":0.392676},{"len":3,"p":0.282918},{"len":4,"p":0.220844},{"len":5,"p":0.181388},{"len":6,"p":0.153984},{"len":7,"p":0.133594},{"len":8,"p":0.117008},{"len":9,"p":0.10526},{"len":10,"p":0.0956},{"len":11,"p":0.086998},{"len":12,"p":0.080214},{"len":13,"p":0.073956},{"len":14,"p":0.068358},{"len":15,"p":0.064648},{"len":16,"p":0.060674},{"len":17,"p":0.05737},{"len":18,"p":0.053954},{"len":19,"p":0.051156},{"len":20,"p":0.048514},{"len":21,"p":0.046264},{"len":22,"p":0.04475},{"len":23,"p":0.042574},{"len":24,"p":0.041066},{"len":25,"p":0.038984},{"len":26,"p":0.037722},{"len":27,"p":0.036452},{"len":28,"p":0.035224},{"len":29,"p":0.03402},{"len":30,"p":0.032624},{"len":31,"p":0.031542},{"len":32,"p":0.030778},{"len":33,"p":0.029628},{"len":34,"p":0.028944},{"len":35,"p":0.028144},{"len":36,"p":0.02771},{"len":37,"p":0.026144},{"len":38,"p":0.02585},{"l
@hugoferreira
hugoferreira / origami.js
Last active April 30, 2018 01:41
Origami Programming Exercises
/*
* 'Origami Programming' by Hugo Sereno Ferreira
*
* IEEE Talk @ FEUP (2018)
*
* Exercise sheet (http://goo.gl/Dd4p7b)
*
* Note: Make sure you have node.js, and then install the dependencies using:
*
* npm install -g lodash

Keybase proof

I hereby claim:

  • I am hugoferreira on github.
  • I am bytter (https://keybase.io/bytter) on keybase.
  • I have a public key ASBalgfEuZoOCJiY2VxfYcKZGBr5PjTdUe8ltaEnYdsLJwo

To claim this, I am signing this object:

package eu.shiftforward.macroInterpreter
import scala.annotation.tailrec
import scala.reflect.runtime.universe._
import scala.collection._
sealed trait Expression[-ST, +A]
abstract class Atom[-ST, A](implicit val ev: Liftable[A]) extends Expression[ST, A] { val value: A }
@hugoferreira
hugoferreira / gist:5e14eaac93c9b37bfe68
Last active August 29, 2015 14:07
Bridging Scala and Javascript in Java 8
import javax.script.{Compilable, Invocable, ScriptEngineManager}
import scala.beans.BeanProperty
case class Pessoa(@BeanProperty var name: String,
@BeanProperty var age: Double)
trait CenasExtractor {
def processRow(row: String, age: Double): Pessoa
}
@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" }