Skip to content

Instantly share code, notes, and snippets.

Avatar

Leonardo Antunes antunesleo

View GitHub Profile
@antunesleo
antunesleo / reset-usb.sh
Created Feb 10, 2021
reset all usb 3 ports
View reset-usb.sh
echo -n "0000:00:14.0" | sudo tee /sys/bus/pci/drivers/xhci_hcd/unbind && echo -n "0000:00:14.0" | sudo tee /sys/bus/pci/drivers/xhci_hcd/bind
@antunesleo
antunesleo / dell-D6000-dock-ubuntu.md
Created Feb 6, 2021 — forked from noahp/dell-D6000-dock-ubuntu.md
Dell Universal Dock D6000 on ubuntu
View dell-D6000-dock-ubuntu.md
@antunesleo
antunesleo / binary_tree.py
Created Aug 27, 2020
An binary tree sample implementation (insert, traverse_inorder, traverse_preorder, traverse_postorder included)
View binary_tree.py
def binarytree(value):
return Node(value)
class Node(object):
def __init__(self, value):
self.__value = value
self.__left_node = None
self.__right_node = None
View crop-image-borders.py
def crop_image_borders(image_path):
image = Image.open(image_path)
image.load()
ndarray_image = np.asarray(image)
ndarray_image_mask = ndarray_image.max(axis=2)
non_empty_columns = np.where(ndarray_image_mask.max(axis=0) > 0)[0]
non_empty_rows = np.where(ndarray_image_mask.max(axis=1) > 0)[0]
image_bbox = (min(non_empty_rows), max(non_empty_rows),
min(non_empty_columns), max(non_empty_columns))
cropped_ndarray_image = ndarray_image[image_bbox[0]:image_bbox[1] + 1,
@antunesleo
antunesleo / merge-sort.py
Created Apr 25, 2020
Merge sort in python
View merge-sort.py
def merge_sort(ar, start, end):
qtd = end - start
if qtd > 1:
mid = int((start + end) / 2)
merge_sort(ar, start, mid)
merge_sort(ar, mid, end)
intercalate(ar, start, mid, end)
return ar
def intercalate(ar, start, mid, end):
View celery-app-for-docker.py
app = Celery('first_app', broker='redis://redis:6379/2')
View usage-async-code.py
validate_user(user) # First validate user, then jump to next line
save_db_user(user) # First save_db_user, them jump to next line
start_to_send_confirmation_email(user) # We don't want to wait the email be sent to jump to next line, here we should develop some async stuff
return user
View routing-tasks.py
app = Celery('first_app', broker='redis://localhost/2')
# New code below
app.conf.task_routes = {
'celery_stuff.tasks.serve_a_beer': {'queue': 'beer'},
'celery_stuff.tasks.serve_a_coffee': {'queue': 'coffee'}
}
View first_app_with_serve_a_coffee.py
from celery_stuff.tasks import serve_a_beer, serve_a_coffee # Importing the task
def start_serve_a_beer():
""" Starts the execution of a celery task with the delay method.
the delay method doesn't wait the task execution be finished.
"""
serve_a_beer.apply_async(('weiss', '500ml'))
print('This will be executed before the serve_a_beer task be finished')