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 / 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 29, 2024 05:51
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):
@akiross
akiross / boolsel.py
Last active December 5, 2018 11:07
Extract items from an iterable based on a boolean condition
def boolean_selector(iterable, condition):
"""Extract the next item of a conditional group out of an iterable.
Given an iterable and a condition function over its elements, this function
returns two iterators which can be used to pick the next element out of
the iterable based on the desired boolean condition function.
Example:
div5, non_div5 = boolean_selector(range(100), lambda x: x % 5 == 0)
@akiross
akiross / Pipfile
Last active December 5, 2018 11:45
Basic json-log viewer with filtering
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"
[dev-packages]
neovim = "*"
[packages]
flask = "*"
@akiross
akiross / view_rotation.py
Created December 3, 2018 09:53
Plot rotation against x,y (similar to gnuplot surface rotation)
# This is a pseudocode tbh
def on_mouse_move(self, pos):
# Normalized distance of cursor motion
dist = (pos - self.last_mouse_pos) / (win_w, win_h)
# Build rotation matrices around
# y axis (when moving mouse horizontally)
rot_x = rotation_matrix(260 * dist.x(), 0, 1, 0)
# x axis (when moving mouse vertically)
rot_y = rotation_matrix(260 * dist.y(), 1, 0, 0)