Skip to content

Instantly share code, notes, and snippets.

Avatar

Cosimo Streppone cosimo

View GitHub Profile
@cosimo
cosimo / geoip2_lookup.py
Created Sep 16, 2022
Simple GeoIP2 IP latitude, longitude lookup in Python 3
View geoip2_lookup.py
#!/usr/bin/env python3
"""
Looks up an IP address using GeoLite2 City Database
"""
from functools import lru_cache
import geoip2.database
import geoip2.errors
@cosimo
cosimo / wget-exit-codes.txt
Last active Aug 27, 2022
wget exit codes
View wget-exit-codes.txt
This is the list of exit codes for wget:
0 No problems occurred
1 Generic error code
2 Parse error — for instance, when parsing command-line options, the .wgetrc or .netrc…
3 File I/O error
4 Network failure
5 SSL verification failure
6 Username/password authentication failure
7 Protocol errors
@cosimo
cosimo / parse-options.sh
Created Sep 21, 2012
Example of how to parse options with bash/getopt
View parse-options.sh
#!/bin/bash
#
# Example of how to parse short/long options with 'getopt'
#
OPTS=`getopt -o vhns: --long verbose,dry-run,help,stack-size: -n 'parse-options' -- "$@"`
if [ $? != 0 ] ; then echo "Failed parsing options." >&2 ; exit 1 ; fi
echo "$OPTS"
@cosimo
cosimo / elasticsearch_out_of_sync_shards.py
Last active Jun 2, 2022
Check if any elasticsearch index replica shards are out-of-sync compared to the relative primary (used to rectify some network partition-caused outdated shard problems)
View elasticsearch_out_of_sync_shards.py
#!/usr/bin/env python3
# encoding: utf-8
"""
Identify out-of-sync replica shards for an Elasticsearch index
--------------------------------------------------------------
This program will output a list of all shards for a given index, identifying
the ones that are out-of-sync with respect to the primary shard.
@cosimo
cosimo / es-dump.sh
Created Apr 26, 2022
Basic usage of elasticsearch-dump
View es-dump.sh
#!/bin/bash
ES_HOST=localhost
ES_PORT=9200
ES_USERNAME=elasticsearch
ES_PASSWORD=oohlala
ES_URL="https://$ES_USERNAME:$ES_PASSWORD@$ES_HOST:$ES_PORT"
dump_mapping() {
local index_name="$1"
@cosimo
cosimo / gcloud-snippets.sh
Created Jan 12, 2022
Random gcloud command line snippets
View gcloud-snippets.sh
#!/bin/bash
# =============================================================================
#
# Very random gcloud related snippets
#
# =============================================================================
set -e
set -o nounset
@cosimo
cosimo / x-forwarded-for.vcl
Created Jan 13, 2012
Varnish X-Forwarded-For VCL snippet
View x-forwarded-for.vcl
# See http://www.varnish-cache.org/trac/ticket/540
sub inject_forwarded_for {
# Rename the incoming XFF header to work around a Varnish bug.
if (req.http.X-Forwarded-For) {
# Append the client IP
set req.http.X-Real-Forwarded-For = req.http.X-Forwarded-For ", " regsub(client.ip, ":.*", "");
#unset req.http.X-Forwarded-For;
}
else {
@cosimo
cosimo / inv.py
Last active Oct 1, 2021
Display ansible inventories with Python and the rich console library
View inv.py
"""
Display Ansible inventories as a tree of environments, groups and hosts as leaves.
A nice diversion/excuse to dive into the rich console library.
It will expand simple host ranges, allowing grep commands to find
group names for given hosts.
Usage:
./inv.py
./inv.py | grep -B10 some-hostname
@cosimo
cosimo / delete-unreferenced-charts.py
Created Sep 14, 2021
Clean up older versions of charts from chartmuseum
View delete-unreferenced-charts.py
#!/usr/bin/env python3
import os
import yaml
import requests
CHARTMUSEUM_URL = 'https://your.chartmuseum.url'
@cosimo
cosimo / nvidia-kernel-crash.log
Last active Aug 9, 2021
nvidia modeset kernel crash + screen freeze
View nvidia-kernel-crash.log
Aug 9 11:26:21 cosimo-desktop kernel: [8778506.500704] nvidia-modeset/: page allocation failure: order:4, mode:0x40cc0(GFP_KERNEL|__GFP_COMP), nodemask=(null),cpuset=/,mems_allowed=0
Aug 9 11:26:21 cosimo-desktop kernel: [8778506.500709] CPU: 1 PID: 244 Comm: nvidia-modeset/ Tainted: P OE 5.4.0-72-generic #80~18.04.1-Ubuntu
Aug 9 11:26:21 cosimo-desktop kernel: [8778506.500709] Hardware name: MSI MS-7A71/Z270-A PRO (MS-7A71), BIOS 1.20 04/07/2017
Aug 9 11:26:21 cosimo-desktop kernel: [8778506.500710] Call Trace:
Aug 9 11:26:21 cosimo-desktop kernel: [8778506.500714] dump_stack+0x6d/0x8b
Aug 9 11:26:21 cosimo-desktop kernel: [8778506.500716] warn_alloc+0xfe/0x160
Aug 9 11:26:21 cosimo-desktop kernel: [8778506.500718] __alloc_pages_slowpath+0xe19/0xe50
Aug 9 11:26:21 cosimo-desktop kernel: [8778506.500900] ? _nv032044rm+0x1e/0x30 [nvidia]
Aug 9 11:26:21 cosimo-desktop kernel: [8778506.501066] ? os_release_spinlock+0x1a/0x20 [nvidia]
Aug 9 11:26:21 cosimo-desktop kernel: [8778506.501