Skip to content

Instantly share code, notes, and snippets.

Olivier Mengué dolmen

View GitHub Profile
@dolmen
dolmen / export-400px.pl
Last active Mar 1, 2019
Nautilus script to convert a photo to reduced width of 400px
View export-400px.pl
#!/usr/bin/env perl
# Install as a Nautilus script:
# perl export-400px.pl --install
#
# Install dependencies:
# sudo aptitude install libimage-exiftool-perl libpath-tiny-perl imagemagick zenity
#
# Author: Olivier Mengué
# Created: Sun Feb 28 20:30:55 2016 +0100
@dolmen
dolmen / jsonroundtrip_test.go
Created Feb 19, 2019
Go: checkJSONRoundtrip
View jsonroundtrip_test.go
package main_test
import (
"encoding/json"
"reflect"
)
func checkJSONRoundtrip(t *testing.T, value interface{}, expectedJSON json.RawMessage) bool {
b, err := json.Marshal(value)
if err != nil {
@dolmen
dolmen / mini-pet.yaml
Last active Jan 24, 2019
Mini Swagger spec not validated by online.swagger.io/validator
View mini-pet.yaml
swagger: "2.0"
info:
version: "1.0.0"
title: "Swagger Petstore"
license:
name: "Apache 2.0"
url: "http://www.apache.org/licenses/LICENSE-2.0.html"
host: "petstore.swagger.io"
basePath: "/v2"
tags:
@dolmen
dolmen / jsonl
Created Jul 3, 2018
Transform a JSON input containing a single array into the "JSON Lines" format
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
}
@dolmen
dolmen / hello.c
Last active Feb 6, 2018
C source runnable from shell
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");
@dolmen
dolmen / darwin-signames.sh
Created Jan 17, 2018
List signal names on OS X
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
}
@dolmen
dolmen / DATETIME-to-TIMESTAMP.sql
Created Oct 27, 2017
MySQL: convert all DATETIME to TIMESTAMP
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
@dolmen
dolmen / ReaderFunc.go
Created Apr 14, 2017
Proposal to add ReaderFunc to package io
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
You can’t perform that action at this time.