Skip to content

Instantly share code, notes, and snippets.

@fabienhinault
fabienhinault / ts_display.sh
Created November 9, 2017 12:37
Transform a json file containing timestamps to add a readable date
mkdir -p /tmp/toto ;
tmpfile=$(mktemp /tmp/toto/data-XXXXXX.json);
ts=$(date -u -d"2017/04/01 00:00:00" "+%s");
curl -X GET --header 'Accept: application/json' "https://host/path?ts=$ts000" | sed 's/"/\\"/g' | sed -r 's/(\.[0-9]{12})([0-9]*)/\1/g' | sed -r 's/(([^0-9][0-9]{0,12})*):([0-9]{10})([0-9]{3}),((:?[0-9]{0,12}[^0-9:])*)/printf "%s%s%s" "\1" ":\\\"\3\4 $(date +%FT%TZ -u -d @\3)\\\"," "\5";/ge' > $tmpfile;
# first sed escapes double quotes, because they will be printed by "print"
# second sed truncate all numbers to 12 digits after point, in order to detect timestamps easier (timestamps here are milliseconds)
# third sed appends to all timestamps, their equivalent dates
firefox $tmpfile
#!/bin/bash
cd ~
git clone https://github.com/magicmonty/bash-git-prompt.git .bash-git-prompt --depth=1
cat >> ~/.gitconfig << EOF
[user]
@fabienhinault
fabienhinault / gist:e95f26112947d4b5c26166f771c8d83d
Created October 26, 2017 16:28
jq request for timestamps
jq 'def thousandthToDate: . / 1000 | todate; walk(if type == "object" and has("dateControle") then .dateControle |= tostring + " " + thousandthToDate else . end)' controle.json
@fabienhinault
fabienhinault / AbstractBox.java
Created September 17, 2017 15:59
lights challenge
/**
* Created by fab on 16/09/17.
*/
public abstract class AbstractBox {
abstract void turn(boolean b, int i, int i1, int i2, int i3);
abstract void toggle(int left, int bottom, int right, int top);
#!/bin/bash
# place it under ~/.local/share/nautilus/scripts/
# and make it executable chmod u+x nautilus_backup.bash
for f in $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS
do
cp -a $f $f~$(date --utc '+%Y-%m-%d_%H_%M_%S')
done
#!/bin/sh
find <log_dir> -not -empty | xargs ls -t | head -n 1 | tailf
#!/bin/sh
find <log_dir> -not -empty | xargs ls -t | head -n $1 | tail -n 1 | xargs less -NX
cp --archive $1 $1~$(date --utc '+%Y-%m-%d_%H_%M_%S')
@fabienhinault
fabienhinault / anonymize.py
Last active July 20, 2017 14:22
Python3 script used to anonymize bulletins.ps
#!/usr/bin/python3
import re
import io
import unicodedata
f = open('/home/fab/Documents/dp/election/bulletins.ps',
encoding="latin-1")
output = open('/home/fab/Documents/dp/election/bulletins_anonym_1.ps', 'w',
encoding='latin-1')
@fabienhinault
fabienhinault / bulletins_anonym_1.ps
Last active February 27, 2017 23:47
postscript file for vote bulletins
%!PS
%%DocumentMedia: a4 595 842 80 () ()
/pageHeight 842 def
/pageWidth 595 def
<< /PageSize [pageWidth pageHeight] >> setpagedevice
/mm { 2.834645669 mul } def