View log_django_queries.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logging | |
from django.db import connection | |
connection.force_debug_cursor = True | |
l = logging.getLogger('django.db.backends') | |
l.setLevel(logging.DEBUG) | |
l.addHandler(logging.StreamHandler()) | |
my_model = MyModel.objects.get() |
View reset-usb.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
View dell-D6000-dock-ubuntu.md
Caveats
- NOTE: I had to reboot after doing this to eliminate display artifacts.
- Also, the dock doesn't appear to support using both of the displayport ports simultaneously :'(
- And MST (https://en.wikipedia.org/wiki/DisplayPort#Multi-Stream_Transport_(MST) ) doesn't seem to work on this dock, so you can't daisy chain monitors.
TLDR
- download driver from http://www.displaylink.com/downloads/ubuntu
- unpack
View binary_tree.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, |
View merge-sort.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app = Celery('first_app', broker='redis://redis:6379/2') |
View usage-async-code.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'} | |
} |
NewerOlder