Skip to content

Instantly share code, notes, and snippets.

View jackton1's full-sized avatar

Tonye Jack jackton1

View GitHub Profile
@lrvick
lrvick / get_results.py
Created June 22, 2011 17:02
Get async celery results from subtasks
from celery.result import AsyncResult
from celery.execute import send_task
def get_results(queries):
result = send_task('task1',queries)
results = result.get()
#this does not return ids until _after_ all the tasks are complete, for some reason.
while results:
#pop first off queue, this will shorten the list and eventually break out of while
first_id = results.pop(0)
@lrvick
lrvick / results.py
Created June 22, 2011 18:03 — forked from ask/get_results.py
Get async celery results from nested subtasks as they complete
from tasks import task1
def get_results(queries):
query_procs = task1.delay(queries).get().join()
results = []
for query_proc in query_procs:
# while the following iterate() is happening, the other query_procs are ignored.
# ideas on iterating over all of them at once?
for result in query_proc.iterate():
yield result
@dmitshur
dmitshur / gist:6927554
Last active October 5, 2024 06:15
[Legacy GOPATH mode] How to `go get` private repos using SSH key auth instead of password auth.
@mobilemind
mobilemind / git-tag-delete-local-and-remote.sh
Last active November 2, 2024 08:30
how to delete a git tag locally and remote
# delete local tag '12345'
git tag -d 12345
# delete remote tag '12345' (eg, GitHub version too)
git push origin :refs/tags/12345
# alternative approach
git push --delete origin tagName
git tag -d tagName
@Bouke
Bouke / gist:11261620
Last active August 3, 2023 01:46
Multiple Python installations on OS X

Previous versions used homebrew to install the various versions. As suggested in the comments, it's better to use pyenv instead. If you are looking for the previous version of this document, see the revision history.

$ brew update
$ brew install pyenv
$ pyenv install 3.5.0
$ pyenv install 3.4.3
$ pyenv install 3.3.6
$ pyenv install 3.2.6
$ pyenv install 2.7.10

$ pyenv install 2.6.9

@wolever
wolever / task_debouncer.py
Created November 4, 2016 22:38
A task debouncer for Celery.
import time
import redis
def get_redis_connection():
return redis.connect()
class TaskDebouncer(object):
""" A simple Celery task debouncer.
@majackson
majackson / migrations.md
Last active November 14, 2024 15:33
Django migrations without downtime

Django Migrations without Downtime

The following instructions describe a set of processes allowing you to run Django database migrations against a production database without having to bring the web service down.

Note that in the below instructions, migrations are all run manually at explicit points, and are not an automatic part of the deployment process.

Adding Fields or Tables

Adding a (nullable) field or a new table

  1. Make the model or column addition in your code.
'use strict';
const co = require('co');
const EventEmitter = require('events');
const Promise = require('bluebird');
const AWS = require('aws-sdk');
const ssm = Promise.promisifyAll(new AWS.SSM());
const DEFAULT_EXPIRY = 3 * 60 * 1000; // default expiry is 3 mins
@jackton1
jackton1 / drf_optimize.py
Last active October 6, 2023 22:37
Optimize Django Rest Framework model views queries.
from django.db import ProgrammingError, models
from django.db.models.constants import LOOKUP_SEP
from django.db.models.query import normalize_prefetch_lookups
from rest_framework import serializers
from rest_framework.utils import model_meta
class OptimizeModelViewSetMetaclass(type):
"""
This metaclass optimizes the REST API view queryset using `prefetch_related` and `select_related`
if the `serializer_class` is an instance of `serializers.ModelSerializer`.
@1st1
1st1 / bench.py
Last active November 1, 2022 11:43
immutables benchmark
import pyrsistent
import immutables
import time
I = 1_000_000
KEY = '5'
for N in [5, 10, 20, 30, 100, 200, 300, 400, 500, 1000]:
print('=============')