Skip to content

Instantly share code, notes, and snippets.

View bebosudo's full-sized avatar
💾

Alberto Chiusole bebosudo

💾
View GitHub Profile
@bebosudo
bebosudo / readme.md
Last active February 5, 2023 14:55
Istruzioni per gestire un sito web pubblicato su GitLab Pages

Istruzioni per gestire un sito web pubblicato su GitLab Pages

Richiedere l'accesso per pubblicare pagine richiede alcuni semplici step:

  1. Iscriversi a gitlab.com, o accettare l'invito arrivato sulla propria casella email
  2. Scegliere uno username qualunque (nome.cognome va benissimo) e una password
  3. Nella seconda schermata ci vengono rivolte alcune domande per statistica, si possono fornire risposte a piacere: scegliere un ruolo qualunque, ad es. Sviluppatore software (A), un motivo qualunque per essersi iscritti, ad es. Voglio imparare git (B), indicare che si usera' Gitlab come singolo (C) e infine scegliere di Unirsi ad un progetto esistente (D)
    Screenshot from 2023-02-05 14-58-59
  4. Si verra' quindi catapultati in una pagina con titolo Welcome to GitLab, che significa che non si e' stati ancora aggiunti al progetto/repository che contiene
@bebosudo
bebosudo / argparse_with_env_vars.py
Created November 11, 2022 07:00
A trick to support environment variables as a backup in Python's argparse when command line argument is not provided
#!/usr/bin/env python3
import argparse
import getpass
import logging
import os
# Check for values inside the environment variables and, if any, set them in the 'default'
# parameter of argparse, so that we don't duplicate code. Just make sure not to use '%(default)s'
# inside the help method, or it would print the env var and not the actual default, if an env var
@bebosudo
bebosudo / README.md
Created April 20, 2021 00:09
Workaround for MKL to use faster codepath on AMD CPUs
@bebosudo
bebosudo / scroll.html
Last active February 2, 2021 20:03
Track user scrolling through page with GA - Copied from: https://pastebin.com/8wjY9eHa, see original article https://growthrocks.com/blog/scroll-tracking-google-analytics/
<script>
document.addEventListener('scroll', function(){
var h = document.documentElement,
b = document.body,
st = 'scrollTop',
sh = 'scrollHeight';
var percent = parseInt ( (h[st]||b[st]) / ((h[sh]||b[sh]) - h.clientHeight) * 100);
@bebosudo
bebosudo / manga_fetcher.py
Created November 24, 2020 08:13
Download all chapters of a given manga from mangaeden.com
#!/usr/bin/env python
#
# Install selenium with 'pip install selenium' and the related
# geckodriver for the Firefox browser.
# Extracts all chapters of the given manga url, but downloads only the given
# chapter and the following ones, to avoid fetch already downloaded chapters.
#
# The trick is to use a small piece of js code to trigger the download,
# which will auto-download since we load Firefox with a profile that
# never asks to download mangaeden images.
@bebosudo
bebosudo / smack_my_IP_stack.py
Created May 22, 2020 13:58
Test if address is in network (in CIDR notation); IPv4 only, but IPv6 support should be easy
import socket, struct
def ip_addr_to_bin_str(ip):
# To support IPv6, play with socket.inet_pton.
return format(struct.unpack('!I', socket.inet_aton(ip))[0], 'b')
def ip_in_cidr_net(ip_address, cidr_network):
ip_bin = ip_addr_to_bin_str(ip_address)
# Extract the "base" IP from the network address
@bebosudo
bebosudo / apt_repository.py
Last active May 22, 2020 15:22
(IPv4 CIDR check only) Patched `apt_repository.py` ansible module, see https://github.com/ansible/ansible/pull/42536
#!/usr/bin/python
# encoding: utf-8
# Copyright: (c) 2012, Matt Wright <[email protected]>
# Copyright: (c) 2013, Alexander Saltanov <[email protected]>
# Copyright: (c) 2014, Rutger Spiertz <[email protected]>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
###########################
#
# Version: 1.8.5
#
# If you edit this file, do not forget to uncomment any lines
# that you change.
# The pound(#) symbol may be used anywhere for comments.
#
# To specify a key, you can use 'xbindkeys --key' or
# 'xbindkeys --multikey' and put one of the two lines in this file.
@bebosudo
bebosudo / darshan-util-3.4.0-fedora.Dockerfile
Last active November 7, 2022 17:54
Multi-stage dockerfile to build darshan-util: 'docker pull docker.io/bebosudo/darshan-util' (https://hub.docker.com/r/bebosudo/darshan-util)
# darshan-util
# http://www.mcs.anl.gov/research/projects/darshan/docs/darshan-util.html
#
# This container file collects all dependencies required to run the analysis
# tools on darshan log files.
# To build darshan-util we use a multi-stage build: the first FROM builds the
# program, while the second copies only the final files into it.
# The first image is discarded and we only keep the second image with the
# final executables. For more details see the official docs:
@bebosudo
bebosudo / TIL.md
Last active October 17, 2024 09:48
Things I Learned/Today I Learned

Python

  • Extra requirement packages can be defined for a python package, using square brackets: pip install "project[extra]", see https://stackoverflow.com/a/46775606/
  • dask is a really cool framework for distributed tasks! For example, one may set an object in shared memory using .scatter: https://docs.dask.org/en/latest/futures.html#move-data
  • To uninstall a package installed with pip -e git which gives "No files were found to uninstall", search for a LIBRARYNAME.egg-link or LIBRARYNAME.egg-info file, and rename/delete it; a list of dirs where pip searches when doing a freeze can be found with python -c 'import sys; print(sys.path)'
  • Path configuration files can change the python path: https://stackoverflow.com/questions/60338280/
  • To test whether a port can be used, bind to the port on all the interfaces; see snippet in the bash section below
  • Convert 123MB into bytes
units = {"KB": 2**10, "MB": 2**20, "GB": 2**30