Skip to content

Instantly share code, notes, and snippets.

View biboudis's full-sized avatar

Aggelos Biboudis biboudis

View GitHub Profile
@biboudis
biboudis / Mandelbrot.java
Last active August 29, 2015 14:00
Test sequential and parallel mandelbrot in Java 8 with JMH. (http://openjdk.java.net/projects/code-tools/jmh/)
package benchmark;
import java.util.stream.*;
import org.openjdk.jmh.annotations.*;
import java.util.concurrent.TimeUnit;
import java.util.*;
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@BenchmarkMode(Mode.AverageTime)
public class MyBenchmark {
@biboudis
biboudis / GoldenRatio.java
Created December 15, 2011 16:17
A simple memoization with AspectJ, for golden ratio calculation.
package tests.recursive;
public class GoldenRation {
public static long fib(int n) {
if (n <= 1) return n;
else return fib(n-1) + fib(n-2);
}
public static double goldenratio(int n){
return fib(n+1)*Math.pow(fib(n),-1);
@biboudis
biboudis / Expressions.cpp
Created February 19, 2012 13:02
Just a Visitor pattern skeleton in C++. No gimmicks.
#include "Expressions.h"
void* SumExpression::Accept(Visitor& v)
{
return (void*) v.VisitSum(this);
}
void* ConstantExpression::Accept(Visitor& v)
{
return (void*) v.VisitConstant(this);
@biboudis
biboudis / gist:1869437
Created February 20, 2012 14:21
A random number, observable generator in Rx, without closing over a Random value.
IDisposable generator = Observable.Generate<Tuple<Random, int>, int>(
new Tuple<Random, int>(new Random(), 0),
value => value.Item2 < 100,
value => new Tuple<Random, int>(value.Item1, value.Item2 + 1),
value => value.Item1.Next(0, 100), scheduler).Subscribe(Console.WriteLine);
@biboudis
biboudis / gist:1931336
Created February 28, 2012 08:53
A quick bloom filter in Rx
public static IObservable<Tuple<TSource, bool>> Bloom<TSource>(this IObservable<TSource> source, int size)
{
BitArray bitmap = new BitArray(size);
return source.Select<TSource, Tuple<TSource, bool>>(value =>
{
var hashCode = value.GetHashCode();
var tuple = new Tuple<TSource, bool>(value, bitmap[hashCode] == true);
bitmap[hashCode] = true;
return tuple;
@biboudis
biboudis / playlistmanager.cpp
Last active December 28, 2015 19:29
Signals in QT (class taken from clementine's playlist manager header file).
class PlaylistManagerInterface : public QObject {
Q_OBJECT
public:
PlaylistManagerInterface(Application* app, QObject* parent)
: QObject(parent) {}
// methods
public slots:
virtual void Load(const QString& filename) = 0;
@biboudis
biboudis / Fluent.scala
Created April 18, 2017 16:59
Adding a fluent API to a tagless interpreter via implicit function types
object Fluent {
trait Foo[C[_]] {
def meth1[T]() : C[T]
}
trait ConcreteC[T]
class Lib[ElemT]{
@biboudis
biboudis / dbus.sh
Last active June 1, 2017 14:35
Playing with dbus.
# qdbus lists all service names of services that are running and you can manipulate at the moment.
qdbus
# control dbus
qdbus org.mpris.MediaPlayer2.clementine /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Next
qdbus org.mpris.MediaPlayer2.clementine /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Previous
# and use --literal if you need to print the reply in plain text
qdbus --literal org.mpris.MediaPlayer2.clementine /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Playlists.ActivatePlaylist /org/mpris/MediaPlayer2/Playlists/20
@biboudis
biboudis / FRP.scala
Created June 14, 2017 12:05
Martin's complete, FRP example from coursera.
object FRP {
class Signal[T](expr: => T) {
import Signal._
private var myExpr: () => T = _
private var myValue: T = _
private var observers: Set[Signal[_]] = Set()
update(expr)
protected def update(expr: => T): Unit = {
@biboudis
biboudis / Functional Unparsing.scala
Last active January 30, 2018 14:54
A simple type-safe formatter in Scala based on the "Functional Unparsing" paper by Olivier Danvy
// A simple type-safe formatter in Scala based on the "Functional Unparsing" paper by Olivier Danvy
// http://cs.au.dk/~danvy/DSc/16_danvy_jfp-1998.pdf
object Test {
def eol[A](k: String => A)(s: String): A = {
k(s + "\n")
}