Skip to content

Instantly share code, notes, and snippets.

Avatar

Thomas Guyot-Sionnest dermoth

  • Montreal
View GitHub Profile
@dermoth
dermoth / getopt.sh
Last active Nov 25, 2020
Bash + gnu getopt example
View getopt.sh
#!/bin/bash
set -eu
trap 'echo "$NAME: Failed at line $LINENO" >&2' ERR
NAME=${0##*/}
print_help() {
echo "Usage: $NAME <opts> <args>" >&2
exit 1
}
@dermoth
dermoth / xchat_auto_ghost.py
Created Aug 15, 2017
AutoGhost X-Chat2 Module
View xchat_auto_ghost.py
"""AutoGhost X-Chat2 Module
NB: This module assumes SASL Authentication. It does not perform any auth;
merely ghost on connect *after* successful SASL authentication (and likely
before any other module can perform manual service auth).
"""
import xchat # pylint: disable=F0401
__module_name__ = "AutoGhost"
@dermoth
dermoth / blk_ra.sh
Created Aug 15, 2017
Script performing read-ahead on bitcoin's blockfiles
View blk_ra.sh
#!/bin/bash
#
# blk_ra.sh - Script performing read-ahead on bitcoin's blockfiles
#
# In order to speed up data loading, this script performs read-ahead
# operations on the next block to be read by the bitcoin node.
#
# The expected setup for this speed-up to be effective is:
#
# - Blockchain index and chainstate database on SSD
View t.py
# Copyright(C) 2017 by Abe developers.
# test_chain.py: test Abe Chain code with static data
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
@dermoth
dermoth / bench.py
Created Mar 20, 2015
arista-eosext/PCAPDecoder decode benchmark
View bench.py
#!/usr/bin/env python
import timeit
import locale
locale.setlocale(locale.LC_ALL, '') # Default user locale
#locale.setlocale(locale.LC_ALL, 'en_US') # ... or force it with this
runcnt=10000000
result = timeit.timeit(
@dermoth
dermoth / csv2tsv.py
Created Feb 26, 2015
Convert CSV to TSV, properly handling intra-field commas, newlines and quoted double-quotes, as per rfc4180 section 2. Also convert TSV separators to C-style escapes.
View csv2tsv.py
#!/usr/bin/env python
#
# Convert CSV to TSV, properly handling intra-field commas, newlines and
# quoted double-quotes, as per rfc4180 section 2. Also convert TSV separators
# to C-style escapes.
#
from __future__ import print_function
import sys, csv
@dermoth
dermoth / gist:9337183
Last active Aug 29, 2015
Bash (()) and error handling
View gist:9337183
[thomas_guyot@localhost ~]$ bash --version
GNU bash, version 3.2.25(1)-release (x86_64-redhat-linux-gnu)
Copyright (C) 2005 Free Software Foundation, Inc.
[thomas_guyot@localhost ~]$ trap 'echo Argh' ERR
[thomas_guyot@localhost ~]$ variable=0
[thomas_guyot@localhost ~]$ ((variable++))
[thomas_guyot@localhost ~]$ echo $?
1
[thomas_guyot@localhost ~]$ echo $variable
1
@dermoth
dermoth / check_things.php
Created Apr 13, 2013
Template php nagios check
View check_things.php
<?php
# Template php nagios check
#
# Meant to work along with nagios's check_http. In addition to the
# returned string which is a standard nagios result, the script returns
# 403 and 503 errors on WARNING and CRITICAL respectively to make
# check_http return an equivalent status. The HTTP status printed by
# check_http is also the script result.
#
# Author: Thomas Guyot-Sionnest <tguyot@gmail.com>
@dermoth
dermoth / list_domains.sh
Last active Dec 16, 2015
CGI script in plain Bash...
View list_domains.sh
#!/bin/bash
# Send all command output to STDERR while allowing us to write to STDOUT
# using fd 3
exec 3>&1 1>&2
set -eu
trap "echo -e 'Status: 500 Internal Server Error\n' >&3; exit 0" ERR
View range-2i_try2
{
"inputs":{
"bucket":"webaccesslogs",
"index":"ts_int",
"start":1338712811,
"end":1338712814,
"timeout":60000
},
"query":[
{