Skip to content

Instantly share code, notes, and snippets.

View andresilva's full-sized avatar
🌴
Off

André Silva andresilva

🌴
Off
  • Porto, Portugal
View GitHub Profile
require 'riak'
def fill_customers(n=50000)
n_threads = 4
ops_thread = n / n_threads
threads = []
n_threads.times do |i|
threads << Thread.new do
client = Riak::Client.new(:host => "10.112.29.130", :port => 8098,
@andresilva
andresilva / gist:2967278
Created June 21, 2012 17:39
Alternator bug scenario
import com.michelboudreau.alternator.*;
import com.amazonaws.AmazonClientException;
import com.amazonaws.AmazonServiceException;
import com.amazonaws.services.dynamodb.AmazonDynamoDB;
import com.amazonaws.services.dynamodb.model.*;
import java.util.*;
public class Main {
static private AlternatorDBClient client;
@andresilva
andresilva / gist:6012113
Last active December 19, 2015 20:18
HList type sizeOf
import shapeless._
trait Size[A] {
def apply(): Int
}
implicit val shortSize = new Size[Short] {
def apply() = 2
}
@andresilva
andresilva / gist:6084682
Created July 25, 2013 23:17
Low priority implicits issue
def test(m: Magnet): Int = m.i
class Magnet(val i: Int)
object Magnet extends LowerPriorityMagnet {
implicit def fromUnitWithInt(u: Unit)(implicit i: Int) = new Magnet(i)
}
abstract class LowerPriorityMagnet {
implicit def fromUnitWithString(u: Unit)(implicit s: String) = new Magnet(s.toInt)
trait Bar[In <: HList, Out <: HList]
class Foo[T](implicit gen: Generic[T]) {
def apply[L <: HList](implicit bar: Bar[L, gen.Repr]) = null
}
// error: type arguments [L,Foo.this.gen.Repr] do not conform to trait Bar's type parameter bounds [In <: shapeless.HList,Out <: shapeless.HList]
@andresilva
andresilva / gist:6509656
Created September 10, 2013 13:48
HListDeserializer
import shapeless._
import shapeless.poly._
import shapeless.ops.hlist._
import scala.util.Try
trait Deserializer[A, B] {
def apply(t: A): Either[String, B]
}
object Deserializer {
@andresilva
andresilva / PKGBUILD
Last active December 25, 2015 12:49
Shairport pkg
pkgname=shairport
pkgver=1.0
pkgrel=1
pkgdesc="An AirPlay-compatible audio receiver"
arch=('i686' 'x86_64' 'armv6h')
url="https://github.com/abrasive/shairport"
license=('public-domain')
depends=('avahi' 'glibc' 'pkgconfig' 'libao' 'openssl')
makedepends=('git' 'libao' 'openssl')
provides=(shairport)
@andresilva
andresilva / gist:7009914
Created October 16, 2013 15:42
Better C-a
(defun smarter-move-beginning-of-line (arg)
"Move point back to indentation of beginning of line.
Move point to the first non-whitespace character on this line.
If point is already there, move to the beginning of the line.
Effectively toggle between the first non-whitespace character and
the beginning of the line.
If ARG is not nil or 1, move forward ARG - 1 lines first. If
point reaches the beginning or end of the buffer, stop there."
function invert(move) {
switch (move) {
case 'up': return 'down';
case 'down': return 'up';
case 'left': return 'right';
case 'right': return 'left';
default: return move;
}
}
@andresilva
andresilva / montyhall.scala
Last active January 1, 2016 20:39
Monty Hall Problem using PFP
import scalaz.syntax.monad._
import spire.math._
import spire.implicits._
import pfp.Distribution._
// data Outcome = Win | Lose
sealed trait Outcome
case object Win extends Outcome
case object Lose extends Outcome