Skip to content

Instantly share code, notes, and snippets.

View dolmen's full-sized avatar
😁
Happy!

Olivier Mengué dolmen

😁
Happy!
View GitHub Profile
@dolmen
dolmen / gomvfile.md
Last active April 23, 2020 08:29
Design for a Go tool for moving symbols from a package to another: gomvfile

gomvfile design draft

This is a design draft for a tool (gomvfile) that would allow to migrate a set of symbols from a package to another.

Strategy for symbols migration

  1. Isolate symbols that have to move: move all symbols to migrate into one or multiple separate source files. Those sources must not have depenencies on the internals (private symbols, private struct members) of the rest of the package.
  2. Use gomvfile to migrate the files to the target package

gomvfile

@dolmen
dolmen / mysql+ssh_employees.sh
Last active July 13, 2021 09:45
mysql wrapper to autologin using settings from ~/.mylogin.cnf, ~/.my.cnf and ~/.ssh/config
#!/bin/bash
# Copyright (c) 2016 Olivier Mengué
# License: Apache 2.0
# The connection settings to use are based on the filename of this script
suffix="$(basename "$0" .sh)"
# Connection through SSH
if [[ "_${suffix:0:9}" = _mysql+ssh ]]; then
@dolmen
dolmen / hello.go.sh
Created November 16, 2016 21:31
Wrapping a Go source with a few lines of shell to make it directly runnable (chmod u+x)
#!/bin/sh
f=$(mktemp -t XXXXXXXX.go); sed -n '3,$p' "$0" >"$f"; go run "$f"; e=$?; rm -f "$f"; exit $?
package main
import "fmt"
func main() {
fmt.Println("Hello")
}
@dolmen
dolmen / if-statement-with-initializer.pl
Created June 27, 2016 09:15
Equivalents of C++ 2016 "if statement with initializer", in Perl 5
# Equivalents of C++ 2016 "if statement with initializer", in Perl 5
# http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0305r0.html
#
if ((my $p = $m->try_emplace($key, $value)), !$p->second) {
FATAL("Element already registered")
} else {
process($p->second)
}
@dolmen
dolmen / strict_subs.pm
Created May 27, 2016 15:43
Injecting Sub::StrictSubs into 'use strict'
package strict_subs;
use strict;
use warnings;
use Sub::StrictDecl;
sub DB{}
sub import
{
@dolmen
dolmen / term256-css.pl
Created April 14, 2016 12:15
Map xterm-256 color indexes to CSS hex color
#!/usr/bin/env perl
use 5.010;
use strict;
use warnings;
my %map = (
0 => 0x000000,
1 => 0x800000,
2 => 0x008000,
3 => 0x808000,
@dolmen
dolmen / .bashrc
Last active February 14, 2016 15:42
My minicpan conf
alias minicpan='minicpan -c CPAN::Mini::LatestDistVersion&&cpandb --setup&&perl -MCPAN -e "CPAN::Index->force_reload"'
alias cpan-outdated="cpan-outdated --index 'file://$(sed -n 's/^local: *//p' ~/.minicpanrc)modules/02packages.details.txt.gz'"
@dolmen
dolmen / go-cover.sh
Created February 11, 2016 14:22
go coverage: test + html in one command
#!/bin/sh
go test -coverprofile=.coverage.out && exec go tool cover -html=.coverage.out
@dolmen
dolmen / fix-EqualError.go
Created February 8, 2016 17:56
Try at Go refactoring with 'eg'
package schema
// Trying to refactor with eg
// https://godoc.org/golang.org/x/tools/cmd/eg
// http://blog.ralch.com/tutorial/golang-tools-refactoring/#eg:00ccf7d8fd9b95979ef5475a7112405b
//
// Unfortunately, eg only supports single statements :(
import (
"database/sql"