Skip to content

Instantly share code, notes, and snippets.

View kafecho's full-sized avatar

Guillaume Belrose kafecho

View GitHub Profile
@kafecho
kafecho / Ansible playbook for corosync
Created March 6, 2013 13:48
Reworked my Ansible playbook to install, configure and start Corosync and Pacemaker. Only tested it on CentOS 6.2 64 bit. The playbook now makes use of the built-it Ansible modules to enable services at boot time and to configure SELinux.
# This playbook installs and configure corosync and pacemaker on a set of nodes part of a given group.
---
# See the file /etc/ansible/hosts where the group is actually defined. There might be a way to define groups in a file 'closer' to this playbook.
- hosts: clusternodes
vars:
mcastport : 5405
tasks:
# It would be better to use Ansible to change the IP tables config to allow corosync/pacemaker on the nodes part of the cluster.
@kafecho
kafecho / enable-epel.yml
Created March 20, 2013 08:46
Ansible task file to enabled EPEL on CentOS.
---
- name: Downloading and enable the EPEL repository definitions.
action: command rpm -Uvh --replacepkgs http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
@kafecho
kafecho / gist:5232545
Created March 24, 2013 16:27
Using timeThis
val n = 40
// Measure in milliseconds how long it takes to compute a Fibonacci sequence.
timeThis(msecs){
println ("Naive recursion fib of " + n + ": " + fib(n))
}
// Measure in nanoseconds how long it takes to compute a Fibonacci sequence.
timeThis(nanosecs){
println ("Tail recursion fib of " + n + ": " + fib2(n))
}
@kafecho
kafecho / gist:5232548
Created March 24, 2013 16:28
timeThis output
Naive recursion fib of 40: 102334155
It took 9911 msecs to execute the operation.
Tail recursion fib of 40: 102334155
It took 151000 nanosecs to execute the operation.
I am going to sleep...
Nice to wake up
It took 1000 msecs to execute the operation.
@kafecho
kafecho / gist:5232557
Created March 24, 2013 16:30
timeThis implementation
trait TimeUnit
case object msecs extends TimeUnit
case object nanosecs extends TimeUnit
object Watch{
/* A hashmap to map a time unit to a tuple containing:
* - a description of the time unit in english.
* - a function invoked to measure the time in the given unit
*/
val timeUnits = Map[TimeUnit,Tuple2[String,() => Long]] (
msecs -> ("msecs",System.currentTimeMillis _),
@kafecho
kafecho / gist:5353393
Created April 10, 2013 10:09
Example of how to handle UDP connection with Akka 2.2-M2
package org.kafecho.learning.akka
import java.net.InetSocketAddress
import akka.actor.Actor
import akka.actor.ActorLogging
import akka.actor.ActorSystem
import akka.actor.Props
import akka.actor.actorRef2Scala
import akka.io.IO
import akka.io.UdpFF
@kafecho
kafecho / gist:5362350
Created April 11, 2013 10:31
Bit wrangling in Scala...
package org.kafecho.learning.akka
import akka.util.ByteString
import org.slf4j.LoggerFactory
object Timer{
def timeThis[T](fn : => T) : T = {
val start = System.currentTimeMillis()
val t = fn
val stop = System.currentTimeMillis()
@kafecho
kafecho / gist:6248352
Created August 16, 2013 08:57
Random MIDI tune with Scala and the Java MIDI API.
package org.kafecho.learning.midi
import javax.sound.midi.MidiSystem
import javax.sound.midi.ShortMessage
import scala.util.Random
object MidiTest extends App {
val rcvr = MidiSystem.getReceiver
while (true) {
val myMsg = new ShortMessage
myMsg.setMessage(ShortMessage.NOTE_ON, 8, Random.nextInt.abs % 127, 93)
@kafecho
kafecho / Reader.scala
Created May 8, 2014 08:20
Example of using the Reader Monad.
package org.kafecho.learning.monad
import java.util.UUID
/** My attempt at implementing the Reader Monad concept.
* The Reader Monad encapsulates a computation which:
* - requires a dependency of type D
* - produces values of type A.
*/
case class Reader[D, A](computation: D => A) {
@kafecho
kafecho / gist:2ba793c53f1c0cb15eca
Created July 8, 2014 17:50
Ansible playbook to install CouchDB from source on CentOS 6.5
---
- hosts: cd-servers
gather_facts: no
sudo: true
user: deploy
tasks:
- name: Install Couchdb dependencies
yum: name={{ item }} state=installed
with_items:
- autoconf