View jsonl
#!/usr/local/bin/jq -cf
# This script transforms a JSON input containing a single array into the "JSON Lines" format (http://jsonlines.org)
# See https://stackoverflow.com/questions/42178636/how-to-use-jq-to-output-jsonl-one-independent-json-object-per-line
#
# Install:
# - save this file as "jsonl"
# - install jq (https://stedolan.github.io/jq/)
# - chmod u+rx jsonl
#
View structintmap.go
package structintmap
import "reflect"
func StructIntMap(value interface{}) map[string]int {
m := make(map[string]int)
structIntMap(reflect.ValueOf(value), m, "")
return m
}
View hello.c
///usr/bin/cc -o "${0%.c}" "$0" && exec "./${0%.c}"
// Author: Olivier Mengué
// Install: chmod u+x hello.c
#include <stdio.h>
int main()
{
puts("hello world");
View darwin-signames.sh
# From /usr/include/signal.h
cc -E -dM /usr/include/signal.h | sed -nE 's/^#define (SIG[A-Z0-9]+ +[1-9][0-9]{0,1})$/\1/p' | sort -n -k 2
# Or
kill -l
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")
}