Skip to content

Instantly share code, notes, and snippets.

Christophe Meessen chmike

Block or report user

Report or block chmike

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
chmike / sliceDump.go
Last active Mar 14, 2019
Go language function to dump a byte slice in hexadecimal and ASCII
View sliceDump.go
func dumpByteSlice(b []byte) {
var a [16]byte
n := (len(b) + 15) &^ 15
for i := 0; i < n; i++ {
if i%16 == 0 {
fmt.Printf("%4d", i)
if i%8 == 0 {
fmt.Print(" ")
chmike /
Created Sep 12, 2018
GoGenerics proposal

Go Generics proposal

After more than twenty five years of C++ programming, I'm still under its influence. It may be visible in this proposal. Also, english is not my native language. When in disagreement, make sure it isn't due to inaccurate expression on my part.

First, the concepts I will use in this document to avoid misunderstandings.

definition of generic type or function : type or function with generic parameters. generic parameters : the parameters of a generic definition. type of a generic parameter : the draft proposal calls them contracts. specialized generic definition : a generic definition with its generic arguments (types).

chmike / checkDomain.go
Created Jun 29, 2018
Check domain name validity in Go
View checkDomain.go
// checkDomain returns an error if the domain name is not valid
// See and
func checkDomain(name string) error {
switch {
case len(name) == 0:
return nil // an empty domain name will result in a cookie without a domain restriction
case len(name) > 255:
return fmt.Errorf("cookie domain: name length is %d, can't exceed 255", len(name))

Problems with Go's shorthand declaration :=

The shadow variable trap

The problem

It is best illustrated with the following Go code snippet.

var x int
chmike / GetTimeAsDouble.h
Created Dec 12, 2012
Get the current time as a double float in second units. Handy to compute processing time interval.
View GetTimeAsDouble.h
#include <sys/time.h>
// Return the current time as a double float in second units
double getTimeAsDouble()
struct timeval t;
::gettimeofday( &t, NULL );
return double(t.tv_sec) + double(t.tv_usec)/1000000.0;
chmike / IncrementalStats.h
Created Dec 12, 2012
Compute incrementally mean and std dev
View IncrementalStats.h
#include <cmath>
//! One kibibyte unit size (see
const size_t KiB = 1024;
//! One mebibyte unit size (see
const size_t MiB = 1024*1024;
//! Convert timeval structure to a double
double toDbl( struct timeval& t )
chmike / PrintHex.h
Created Dec 12, 2012
Print binary data in haxadecimal
View PrintHex.h
#ifndef PRINTHEX_H
#define PRINTHEX_H
#include <stdio.h>
// Display data in hexadecimal
inline void printHex( const void* data, size_t len, const char* margin )
if( len == 0 )
You can’t perform that action at this time.