Skip to content

Instantly share code, notes, and snippets.

View francois's full-sized avatar

François Beausoleil francois

  • Sherbrooke, QC, Canada
View GitHub Profile
@francois
francois / check_rabbitmq.rb
Created November 12, 2013 20:17
A quick Nagios script to monitor a RabbitMQ queue. This uses the RabbitMQ HTTP API. This code also depends on the rest-client gem.
#!/usr/bin/env ruby
require "rest-client"
require "ostruct"
require "json"
require "yaml"
require "cgi"
begin
require "ruby-debug"
rescue LoadError
private def normalize(name: String) = Normalizer.normalize(name, Normalizer.Form.NFC).trim.toLowerCase.
replaceAll("""\P{IsL}""", ""). // Only keep letters
replaceAll(Normalizer.normalize("""[àâä]""", Normalizer.Form.NFC), "a"). // Then transliterate accented characters into non-accented ones
replaceAll(Normalizer.normalize("""[éèêë]""", Normalizer.Form.NFC), "e").
replaceAll(Normalizer.normalize("""[îìï]""", Normalizer.Form.NFC), "i").
replaceAll(Normalizer.normalize("""[ôòö]""", Normalizer.Form.NFC), "o").
replaceAll(Normalizer.normalize("""[ûùü]""", Normalizer.Form.NFC), "u").
replaceAll(Normalizer.normalize("""[ç]""", Normalizer.Form.NFC), "c")
import akka.dispatch.{FutureTimeoutException, Future}
import akka.actor.Actor
object FutureTest {
def main(args: Array[String]) {
val f1: Future[Int] = Future({
Thread.sleep(2000)
0
}, 500)
trait BDB {
val dbenv = {
new Environment(...)
}
def close() {
dbenv.close()
}
}
@francois
francois / gist:4714617
Created February 5, 2013 13:59
Ensure pgbench's aggregates and transaction tables agree (reformatted for clarity) Copied from Jeff Janes' post on http://postgresql.1045698.n5.nabble.com/Plug-pull-testing-worked-diskchecker-pl-failed-td5729299.html#red-arrow5729357
select
aid
, abalance
, count(*)
from (
select
aid
, abalance
from pgbench_accounts
union all
@francois
francois / gist:4564516
Last active December 11, 2015 07:09
Reproduction recipe for [How do you tell git to permanently ignore changes in a file?][1] [1]: http://stackoverflow.com/a/14370990/7355
#!/bin/sh
set -v
set -e
rm -rf repro
mkdir repro
cd repro
git init
touch a b
git add --all
global
daemon
group haproxy
log /dev/log local0
maxconn 4000
pidfile /var/run/haproxy.pid
stats socket /var/lib/haproxy/stats
user haproxy
defaults
@francois
francois / CommonJSONFormats.scala
Created December 15, 2012 20:44
I get this error: error: could not find implicit value for evidence parameter of type cc.spray.typeconversion.package.Unmarshaller[ShowsAdministrationServiceDefinition.this.ShowData] content(as[ShowData]) { I get that Scala can't find the implicit, but I don't understand why I haven't imported it yet. My code is as follows (Spray 0.9.0, Scala 2.…
import com.eaio.uuid.UUID
trait CommonJSONFormats extends DefaultJsonProtocol {
implicit def uuidFormat = new JsonFormat[UUID] {
def write(uuid: UUID) = JsString(uuid.toString)
def read(value: JsValue) = value match {
case JsString(x) => new UUID(x)
case _ => throw new DeserializationException("String expected")
}
@francois
francois / repro.rb
Created October 25, 2012 20:07
ASCII-8BIT vs UTF-8 failure using Sequel 3.40.0
#!/usr/bin/env ruby
# coding: utf-8
require "logger"
require "sequel"
require "sequel/extensions/pg_array"
require "json"
logger = Logger.new(STDERR)
logger.level = Logger::DEBUG
@francois
francois / counting_semaphore.rb
Created October 23, 2012 02:35
A CountingSemaphore implementation for Ruby.
require "thread"
class CountingSemaphore
def initialize(capacity, sleep_time=1.0)
@mutex = Mutex.new
@capacity = capacity
@original_capacity = capacity
@sleep_time = sleep_time
end