Skip to content

Instantly share code, notes, and snippets.


Leonardo Antunes antunesleo

View GitHub Profile
antunesleo /
Created Feb 10, 2021
reset all usb 3 ports
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 /
Created Feb 6, 2021 — forked from noahp/
Dell Universal Dock D6000 on ubuntu
antunesleo /
Created Aug 27, 2020
An binary tree sample implementation (insert, traverse_inorder, traverse_preorder, traverse_postorder included)
def binarytree(value):
return Node(value)
class Node(object):
def __init__(self, value):
self.__value = value
self.__left_node = None
self.__right_node = None
def crop_image_borders(image_path):
image =
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 /
Created Apr 25, 2020
Merge sort in python
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):
app = Celery('first_app', broker='redis://redis:6379/2')
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
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'}
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')