View structintmap.go
package main
import "reflect"
func StructIntMap(value interface{}) map[string]int {
m := make(map[string]int)
structIntMap(reflect.ValueOf(value), m, "")
return m
}
View DATETIME-to-TIMESTAMP.sql
SELECT CONCAT('ALTER TABLE `',TABLE_SCHEMA,'`.`', TABLE_NAME, '` ', GROUP_CONCAT(' MODIFY COLUMN "', COLUMN_NAME, '` TIMESTAMP ',IF(IS_NULLABLE = 'NO','NOT',''),' NULL'),';')
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA = DATABASE()
AND DATA_TYPE = 'DATETIME'
GROUP BY TABLE_SCHEMA, TABLE_NAME
View ReaderFunc.go
/*
https://play.golang.org/p/iWDGHj_-X_
This programs generates 32 random bytes formatted à la "hexdump -C".
It does it in just 2 lines of code using the power of the standard library
and a trick to convert a func Read([]byte) (int, error) into an io.Reader.
Inspiration: see HandlerFunc in net/http
View gomvfile.md

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

View mysql+ssh_employees.sh
#!/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
View hello.go.sh
#!/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")
}
View if-statement-with-initializer.pl
# 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)
}
View strict_subs.pm
package strict_subs;
use strict;
use warnings;
use Sub::StrictDecl;
sub DB{}
sub import
{
View term256-css.pl
#!/usr/bin/env perl
use 5.010;
use strict;
use warnings;
my %map = (
0 => 0x000000,
1 => 0x800000,
2 => 0x008000,
3 => 0x808000,