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 email | |
import imaplib | |
import os | |
class PortalEmail(): | |
""" | |
Interface to downloading attachments from | |
an email address and save them to a folder. | |
TODO: Implement the with context protocol |
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
from celery_app import Celery | |
celery = Celery("tasks", backend="amqp", broker="amqp://guest@localhost") | |
@celery.task(name='test_task') | |
def test_task(): | |
return "boom!" |
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
s3_resource = boto3.resource('s3') | |
zip_obj = s3_resource.Object(bucket_name="bucket_name_here", key=zip_key) | |
buffer = BytesIO(zip_obj.get()["Body"].read()) | |
z = zipfile.ZipFile(buffer) | |
for filename in z.namelist(): | |
file_info = z.getinfo(filename) | |
s3_resource.meta.client.upload_fileobj( | |
z.open(filename), | |
Bucket=bucket, |
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
{ | |
"description": "<h2>A CHILDHOOD CLASSIC</h2><p>This is children's bedroom furniture at its very best. The Huckleberry Cabin Bed is wonderfully sturdy and combines storage with a cool place to snuggle down - it's a real childhood classic.</p><img src=\"https://www.gltc.co.uk/pws/client/images/catalogue/products/l2427/original/l2427_1.jpg\" alt=\"\">|<h2>KEY FEATURES</h2><p>Made from a solid beech frame, with MDF panels and a solid pine slatted base; it's painted in Ivory, so it coordinates well with our <a href=\"/category/dept/bedroom-furniture\">Islander Bedroom Furniture</a> range. Features deep drawers and large cupboards that extend the full width of the bed, and a practical ambidextrous ladder/safety rail attachment, to suit your space. Tested to BS: 8509; suitable for 4yrs+. Assembly service available (£100), includes <a href=\"/content/bed-mattress-guarantee\">10 Year GLTC Guarantee</a>.</p><img src=\"https://www.gltc.co.uk/pws/client/images/catalogue/products/l2427/original/l2427_2.jpg\" |
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
from collections import defaultdict | |
table = [{"name": "a", "value": 10}, {"name": "b", "value": 110}, {"name": "b", "value": 10}] | |
c = defaultdict(int) | |
for d in table: | |
c[d['name']] += d['value'] | |
print c |
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
required = ['a', 'b', 'c'] | |
data = json.loads(request.data) | |
missing_fields = set(required) - set(data.keys()) | |
if len(missing_fields) == 0: | |
return Response(status=200) | |
else: | |
error = {"error": "missing required fields", "missing_fields": missing_fields} | |
return Response(response=dumps(error), status=400) |
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
# -*- mode: ruby -*- | |
# vi: set ft=ruby : | |
Vagrant::Config.run do |config| | |
config.vm.define :mongo1 do |mongo1| | |
mongo1.vm.box = "precise64" | |
mongo1.vm.network :hostonly, "192.168.33.20" | |
mongo1.vm.customize ["modifyvm", :id, "--memory", 512] | |
end |
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
a = [1, 5, 10, 15] | |
b = [3, 6, 8, 20] | |
def query_arrays(a, b, k): | |
i,j=0,0 | |
merged_array = [] | |
while i <= len(a)-1 and j <= len(b)-1: | |
if a[i] < b[j]: | |
merged_array.append(a[i]) | |
i += 1 |
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
''' | |
@desc: An algorithm to reverse a list of characters. | |
@param: A list of characters. | |
''' | |
def reverse_algorithm(my_string): | |
length_of_string, i, reversed_string = len(my_string), 0, [] | |
while i < length_of_string: | |
reversed_string.append(my_string[length_of_string-1-i]) | |
i += 1 | |
return reversed_string |
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
#!/usr/bin/env python | |
import os | |
import re | |
import subprocess | |
import sys | |
modified = re.compile('^(?:M|A)(\s+)(?P<name>.*)') | |
CHECKS = [ |
NewerOlder