Skip to content

Instantly share code, notes, and snippets.

@IrSent
IrSent / comb_sort.py
Created April 4, 2017 07:33
Comb sort
# -​*- coding: utf-8 -*​-
from __future__ import unicode_literals, print_function
import random
def random_list(start=1, stop=1001, length=1000):
if stop <= length:
raise ValueError('stop value must be greater than length')
else:
return random.sample(xrange(start,stop), length)
@IrSent
IrSent / download.py
Created November 22, 2016 06:20
Python File Download # Ways of handling file download using Requests library
# Ways of handling file download using Requests library
import contextlib
import os
import requests
def download_file(url, dest_dir):
# reassurance that the connection will be closed:
# Requests cannot release the connection back to the pool unless you consume all the data or call Response.close
with contextlib.closing(requests.get(url=url, stream=True)) as response:
@IrSent
IrSent / celery.py
Created November 12, 2016 19:12
Celery Best Practices
# Safe Queue Celery App Settings
from __future__ import absolute_import, unicode_literals
from celery import Celery
app = Celery('some_project',
broker='amqp://',
backend='amqp://',
include=['some_project.tasks'])