Skip to content

Instantly share code, notes, and snippets.

View akiross's full-sized avatar
🥷
Ninja

Alessandro Re akiross

🥷
Ninja
View GitHub Profile
@akiross
akiross / gist:1ed04769792297b94d007b2adfa92c29
Created May 10, 2021 10:25
Markdown image alignment concept
# Concept for specifying alignment in markdown/rst/similar thing
Specifying how to align images, text etc in markdown is not great.
Here's a concept on how that could be written
The following image is on the left:
|[1]-|
[1]: image.png
from line_profiler import LineProfiler
def do_profile(follow=[]):
def inner(func):
def profiled_func(*args, **kwargs):
try:
profiler = LineProfiler()
profiler.add_function(func)
for f in follow:
profiler.add_function(f)
@akiross
akiross / processes.py
Created May 29, 2020 15:12
Python multiprocessing with queues example
"""Example on how to use processes to write and read data using multiprocessing.
This example allows to build readers and writers with a given "baseline" speed
to simulate readers/writers with different properties (e.g. fast readers, slow
writers, or vice versa).
By adjusting baseline speeds and numbers of writers and readers, you can see
what happens to the data being processed.
"""
import contextlib
@akiross
akiross / autocompile.cpp
Last active April 26, 2020 14:39
Compile a C/C++ program without make, but using a simple header that is valid in both C/C++ and (ba)sh.
#if 0
# Run this file with bash to compile the C++ program.
CC=g++
FLAGS=
# Output file will have the same name of this file without extension
OUT_FILE=${BASH_SOURCE%.cpp}
# Ensure we are not overwriting
@akiross
akiross / coronactivities.md
Created March 14, 2020 11:09
Cose nuove da imparare a fare col computer nei giorni di noia e di clausura.

Ciao, in questi giorni di coronavirus ci sono tante persone che non sanno cosa fare e, incredibilmente, mi accorgo che la mia vasta conoscenza sull'uso dei computer può tornare utile per dare una possibilità agli altri di imparare qualcosa di nuovo, interessante e utile :) (insomma, alternative più "attive" e "creative" allo stare davanti a netflix o alla TV).

Ti mando questo documento che racchiude alcuni consigli per iniziare con queste attività a costo praticamente nullo: basta solo avere un computer e una connessione ad internet per poter iniziare e il software che consiglio va su qualunque tipo di computer (Windows, Mac, Linux). Sono software che vanno benissimo per chi vuole iniziare e anche per avviarsi verso usi professionali.

Spero possano interessarti (e sentiti libera di girare questo documento a chi è a casa che si annoia). Buon divertimento!

Programmare

È l'attività che raccomando di più almeno per i seguenti motivi: 1. è utile nella vita, per automatizzare cose e facilitare il lavoro2. forn

@akiross
akiross / find_sshable_hosts.py
Created March 20, 2019 08:57
Search and test ssh connections on a network
# This is a shitty script that uses nmap to find hosts with port 22 open
# and attempt a connection to them using some username and password, then
# retrieves the hostname if the login is successful.
# Use this script to find a ssh-able host in your (small) network when you
# don't know its IP or mac address.
#
# Also, I wanted to try paramiko. Which is very neat.
import re
import time
@akiross
akiross / starlettews.py
Created March 16, 2019 18:35
A simple example of using websockets with starlette.io (it's super easy, wow!)
from starlette.applications import Starlette
from starlette.responses import HTMLResponse
from starlette.websockets import WebSocket
from jinja2 import Template
import uvicorn
template = """\
<!DOCTYPE HTML>
<html>
@akiross
akiross / cifs_automount.md
Last active February 16, 2025 08:29
Automatically mount shared windows folders at boot on linux w/ systemd

Automount of CIFS (smbfs) folders w/ systemd

i.e. mounting your Windows shares on Linux at boot

First, let's see how to mount the remote directory. Assume that there is a shared folder over the network at \\192.168.1.1\users\self\shared which is accessible with user myuser and password secret123.

We could mount it manually in /mnt/winshare with:

# mount -t cifs //192.168.1.1/users/self/shared /mnt/winshare -o user=myuser,password=secret123

This should work on your Linux box, because systemd will basically call mount with the same arguments: What (//192.168.1.1/users/self/shared), Where (/mnt/winshare) and Options (user=myuser,password=secret123).

@akiross
akiross / minimon.py
Created January 29, 2019 12:32
A simple bokeh app to plot ping to some hosts
#!/bin/env python3
# A simple bokeh app to plot ping to some hosts
# Run this program with:
# bokeh server --show minimon.py --args host1 host2 host3
# MIT Licensed
import re
import time
import select
@akiross
akiross / threademo.py
Created January 21, 2019 20:27
PyQt5 Threading Demo
import sys
import time
from itertools import count
from PyQt5 import QtCore, QtWidgets
class Worker(QtCore.QThread):
data_ready = QtCore.pyqtSignal(str)
def __init__(self):