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 / export-400px.pl
Last active March 1, 2019 08:08
Nautilus script to convert a photo to reduced width of 400px
#!/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 February 19, 2019 13:19
Go: checkJSONRoundtrip
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 January 24, 2019 10:48
Mini Swagger spec not validated by online.swagger.io/validator
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 July 3, 2018 16:13
Transform a JSON input containing a single array into the "JSON Lines" format
#!/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
#
@dolmen
dolmen / structintmap.go
Created June 13, 2018 10:20
StructIntMap
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 February 6, 2018 10:37
C source runnable from shell
///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 January 17, 2018 21:32
List signal names on OS X
# 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
@dolmen
dolmen / structintmap.go
Created November 2, 2017 18:12
StructIntMap
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 October 27, 2017 10:55
MySQL: convert all DATETIME to TIMESTAMP
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 April 14, 2017 16:16
Proposal to add ReaderFunc to package io
/*
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