Skip to content

Instantly share code, notes, and snippets.

@raphael
raphael / metrics.go
Last active September 15, 2016 16:40
// metriks is the local instance of metrics.Metrics
var metriks *metrics.Metrics
// lock synchronizes access to the metrics sink
var lock = sync.RWMutex{}
// NewMetrics initializes goa's metrics instance with the supplied
// configuration and metrics sink
func SetMetrics(m metrics.Metrics) {
lock.Lock()
@raphael
raphael / account.go
Last active April 16, 2016 00:02
Lives in package "test", one such function generated per action per possible response
package test
import (
"bytes"
"fmt"
"io"
"log"
"net/http"
"net/http/httptest"
"regexp"
Response(OK, func() {
Media(CollectionOf(Bottle, func() { View("tiny") }), "tiny")
})
@raphael
raphael / log.go
Last active February 11, 2016 01:07
package log
/**************** Types ****************/
// The logger interface supports Printf and Structured logging
type Logger interface {
// fmt.PrintXX style
Printf(fmt string, vals ...interface{})
// Structured style
require 'rubygems'
require 'ruote'
require 'flexmock'
require 'spec'
# Workitem fields validation
# This participant validates the fields of the current workitem
# Especially useful to validate the initial workitem
# An input definition may include the following:
# - name: Input name, compulsory
@raphael
raphael / mario.rb
Created January 27, 2011 20:47 — forked from anonymous/mario.rb
Ruote - Async External
require 'thread'
# for the Queue class
require 'rubygems'
require 'yajl'
require 'ruote'
PDEF = Ruote.process_definition do
puts "Synchronous read: #{File.read('/sys/block/ram0/size')}"
puts "Asynchronous read..."
t = Thread.new do
puts File.read('/sys/block/ram0/size')
puts 'Done reading'
end
t.join
#include <sys/types.h> /* See NOTES */
#include <sys/socket.h>
#include <unistd.h>
#include <stdio.h>
#include <errno.h>
int main() {
int fd[2];
int r = pipe(fd);
if (getsockopt(fd[0], SOL_SOCKET, 0, NULL,NULL) == ENOTSOCK) {
munmap(0x7f7f9e340000, 4096) = 0
dup2(27, 2) = 2
select(31, [3 28 30], [], NULL, {0, 90000}) = 2 (in [28 30], left {0, 90000})
read(28, "456", 16384) = 3
read(28, "", 16384) = 0
read(30, "123", 16383) = 3
read(30, "", 16383) = 0
select(31, [3 28 30], [], NULL, {0, 90000}) = 2 (in [28 30], left {0, 90000})
read(28, "", 16384) = 0
read(30, "", 16383) = 0
Program received signal SIGPIPE, Broken pipe.
0x95f831da in write$NOCANCEL$UNIX2003 ()
(gdb) backtrace
#0 0x95f831da in write$NOCANCEL$UNIX2003 ()
#1 0x95f83132 in _swrite ()
#2 0x95f52f41 in __sfvwrite ()
#3 0x95fa9844 in fwrite$UNIX2003 ()
#4 0x96ecbef1 in __gnu_cxx::__verbose_terminate_handler ()
#5 0x96eca10c in __gxx_personality_v0 ()
#6 0x96eca14b in std::terminate ()