Skip to content

Instantly share code, notes, and snippets.

Avatar

aaronpolhamus

View GitHub Profile
@aaronpolhamus
aaronpolhamus / redis_handlers.py
Created Aug 9, 2020
task locking with redis + celery
View redis_handlers.py
"""Task locking with redis in celery is hard, and good examples are tough to come by. This is the approach that's
worked for me, based on great work that other folks have posted:
* https://breadcrumbscollector.tech/what-is-celery-beat-and-how-to-use-it-part-2-patterns-and-caveats/
* http://loose-bits.com/2010/10/distributed-task-locking-in-celery.html
* https://redis.io/topics/distlock
This isn't polished,but hopefully it's useful. To verify it in our local test env we register the following test task in
our definitions file:
*** definitions.py ***
View nvidia_docker_torch_test.sh
# [1] Docker installation: https://docs.docker.com/install/linux/docker-ce/fedora/
# [2] Docker compose: https://github.com/Yelp/docker-compose/blob/master/docs/install.md
# [3] NVIDIA docker installation: https://github.com/NVIDIA/nvidia-docker/issues/553#issuecomment-381075335
# [4] Tensorflow docker installation: https://www.tensorflow.org/install/docker
# [1] install dnf-plugins-core
sudo dnf -y install dnf-plugins-core
# [1] setup stable repository
sudo dnf config-manager \
View fedora_nvidia_setup.sh
# Credits:
# [1] https://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html (CUDA)
# [2] https://www.if-not-true-then-false.com/2015/fedora-nvidia-guide/ (Drivers)
yum install nano
# In /etc/sysconfig/selinux update to SELINUX=disabled (takes down firewall and speeds up downloads)
# [1] Install kernel headers
sudo dnf install kernel-devel-$(uname -r) kernel-headers-$(uname -r)
View scheduler_test_dag.py
from datetime import datetime
from airflow.models import DAG
from airflow.operators.python_operator import PythonOperator
DAG = DAG(
dag_id='scheduler_test_dag',
start_date=datetime(2017, 9, 9, 4, 0, 0, 0), #..EC2 time. Equal to 11pm hora México
max_active_runs=1,
View airflow.conf
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
View airflow-scheduler.service
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
View airflow
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@aaronpolhamus
aaronpolhamus / api_demo.py
Created Jun 16, 2017
Python API client demo for Google Drive SDK
View api_demo.py
#!/usr/bin/env python
from __future__ import print_function
import os
from apiclient.discovery import build
from httplib2 import Http
from oauth2client import file, client, tools
try:
import argparse
View demo_cv.py
import numpy as np
import cv2
file_name = '/home/ubuntu/motocross.mp4'
cap = cv2.VideoCapture(file_name)
counter = 0
while(True):
# Capture frame-by-frame
@aaronpolhamus
aaronpolhamus / plot.py
Created Jun 8, 2016
run this script interactively to test whether python is connecting to X11 as expected
View plot.py
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
t = np.arange(0.0, 2.0, 0.01)
s = np.sin(2*np.pi*t)
plt.plot(t, s)
plt.xlabel('time (s)')
plt.ylabel('voltage (mV)')
You can’t perform that action at this time.