Skip to content

Instantly share code, notes, and snippets.

View ltpitt's full-sized avatar
🥋
A black belt is a white belt that never quit.

Davide Nastri ltpitt

🥋
A black belt is a white belt that never quit.
View GitHub Profile
@ltpitt
ltpitt / fake_user.py
Last active December 28, 2020 08:30
A script simulating user interaction with a computer
from time import sleep
from pyautogui import press, typewrite, hotkey, moveTo, position
from random import uniform
import win32gui
enabled = True
mouse_micro_move_enabled = True
open_notepad_write_stuff_close_it_enabled = True
action_timer = 300
@ltpitt
ltpitt / tmux-cheatsheet.markdown
Last active April 12, 2019 11:32 — forked from MohamedAlaa/tmux-cheatsheet.markdown
tmux shortcuts & cheatsheet

Tmux is awesome

Tmux is a terminal multiplexer and if you never used it you really have to try it.
It changed my life, to be honest.

What is a multiplexer, btw?

Long story short: it allows you to have multiple terminal sessions at the same time and to keep your session alive and working also if you disconnect from a *nix server.

You want more detail about multiplexing?

Thank you, WikiPedia:

@ltpitt
ltpitt / send_ssh_command.py
Created November 8, 2018 11:42
Send an ssh command using Python
import base64
import paramiko
key = paramiko.RSAKey(data=base64.b64decode(b'AAA...'))
client = paramiko.SSHClient()
client.get_host_keys().add('ssh.example.com', 'ssh-rsa', key)
client.connect('ssh.example.com', username='THE_USER', password='THE_PASSWORD')
stdin, stdout, stderr = client.exec_command('which solsql')
for line in stdout:
print('... ' + line.strip('\n'))
client.close()
@ltpitt
ltpitt / python_searching.py
Last active October 30, 2018 15:11
Python search algorythms implementations
# Here's a simple animation to understand how linear and binary search work
# http://www.davidenastri.it/files/binary-and-linear-search-animations.gif
data = [1,22,31,44,57,61,73,89,900]
target = 22
def linear_search(data, target):
for index in range(len(data)):
if data[index] == target:
return index
@ltpitt
ltpitt / python_threading.py
Last active November 1, 2022 07:57
Python simple threading implementation for ping
# Global Interpreter Lock (GIL)
#
# Python doesn't allow multi-threading in the truest sense of the word. It has a multi-threading package
# but if you want to multi-thread to speed your code up, then it's usually not a good idea to use it.
# Python has a construct called the Global Interpreter Lock (GIL).
# The GIL makes sure that only one of your 'threads' can execute at any one time.
# A thread acquires the GIL, does a little work, then passes the GIL onto the next thread.
# This happens very quickly so to the human eye it may seem like your threads are executing in parallel,
# but they are really just taking turns using the same CPU core.
# All this GIL passing adds overhead to execution.
@ltpitt
ltpitt / appendToQueryString.js
Created July 18, 2018 13:09
JS snippet to append parameters to a query string without duplicating them
appendToQueryString = function (param, val) {
var queryString = window.location.search.replace("?", "");
var parameterListRaw = queryString == "" ? [] : queryString.split("&");
var parameterList = {};
for (var i = 0; i < parameterListRaw.length; i++) {
var parameter = parameterListRaw[i].split("=");
parameterList[parameter[0]] = parameter[1];
}
parameterList[param] = val;
@ltpitt
ltpitt / create_start_docker.sh
Created June 29, 2018 07:59
Create a Docker image and start a Docker container
sudo docker build -t myimage .
sudo docker run -p 80:80 myimage
@ltpitt
ltpitt / install_docker.sh
Last active June 28, 2018 14:25
Bash snippet to install Docker on Ubuntu Xenial 16.04 and newer
# Install Docker - Xenial 16.04 and newer
apt-get install apt-transport-https ca-certificates curl software-properties-common -y
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
apt-get update
apt-get install docker-ce
docker run hello-world
@ltpitt
ltpitt / raspiboy_pico8_kill_close.py
Created March 31, 2018 18:34
Short and long press button for Raspiboy - Kill PICO-8 and shutdown functions
from gpiozero import Button
import subprocess
from signal import pause
def shutdown():
print("Halting system...")
subprocess.check_call(['sudo', 'poweroff'])
def kill_pico8():
print("Killing PICO-8...")
@ltpitt
ltpitt / docker-destroy-all.sh
Created December 20, 2017 15:55 — forked from JeffBelback/docker-destroy-all.sh
Destroy all Docker Containers and Images
#!/bin/bash
# Stop all containers
docker stop $(docker ps -a -q)
# Delete all containers
docker rm $(docker ps -a -q)
# Delete all images
docker rmi $(docker images -q)