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 / Conda.bat
Created August 26, 2017 06:56
Conda cheatsheet
# For Windows users# Note: <> denotes changes to be made
#Create a conda environment
conda create --name <environment-name> python=<version:2.7/3.5>
#To create a requirements.txt file:
conda list #Gives you list of packages used for the environment
conda list -e > requirements.txt #Save all the info about packages to your folder
@ltpitt
ltpitt / InstallTensorflow1_1Requirements.bat
Last active August 26, 2017 11:13
Install TensorFlow 1.1 Python Requirements for Deep Learning
conda install -c anaconda pillow
conda install -c conda-forge tensorflow=1.1
conda install jupyter
conda install tqdm
conda install matplotlib
@ltpitt
ltpitt / bubble_sort.py
Created August 28, 2017 08:23
Python implementation of bubble sort
def bubble_sort(a_list):
for number in range(len(a_list)-1,0,-1):
for index in range(number):
if a_list[index]>a_list[index+1]:
temp_list = a_list[index]
a_list[index] = a_list[index+1]
a_list[index+1] = temp_list
my_list = [99,45,13,78,33,85,7,99,21]
bubble_sort(my_list)
@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)
@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 / 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 / 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 / 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 / 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 / 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()