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 math | |
def atkin(nmax): | |
""" | |
Returns a list of prime numbers below the number "nmax" | |
""" | |
is_prime = dict([(i, False) for i in range(5, nmax+1)]) | |
for x in range(1, int(math.sqrt(nmax))+1): | |
for y in range(1, int(math.sqrt(nmax))+1): | |
n = 4*x**2 + y**2 | |
if (n <= nmax) and ((n % 12 == 1) or (n % 12 == 5)): |
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 getDivisors(number, primes): | |
""" | |
Returns an unsorted list of the divisors of 'number' using the list of prime numbers 'primes' | |
""" | |
if number == 1: return [number,] | |
if number in primes: | |
return [1, number] | |
divisors = [] | |
for p in primes: | |
if number % p == 0: |
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
cache = {1:1, 2:1} | |
def fib(n, cache): | |
if n not in cache: | |
cache[n] = fib(n-1, cache) + fib(n-2, cache) | |
return cache[n] | |
assert([fib(i, cache) for i in range(1,10)] == [1,1,2,3,5,8,13,21,34]) |
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
# -*- coding: utf-8 -*- | |
from django.db import models | |
from django.contrib.auth.models import User | |
from django.utils.translation import ugettext_lazy as _ | |
from myproject.apps.taskmanager import managers | |
import datetime | |
from django.utils.timezone import utc | |
class Task(models.Model): | |
# Relations |
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
# -*- coding: utf-8 -*- | |
from django.shortcuts import render | |
from django.shortcuts import get_object_or_404 | |
from django.http import HttpResponseRedirect | |
from django.core.urlresolvers import reverse | |
from myproject.apps.taskmanager import models | |
from myproject.apps.taskmanager import forms | |
def home(request): |
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 urllib2, json | |
# Change the APIKEY_VALUE by your API key | |
APIKEY_VALUE = "example-api-key-value-0000" | |
APIKEY = "?hapikey=" + APIKEY_VALUE | |
HS_API_URL = "http://api.hubapi.com" | |
def getTotalNumberOfContacts(): | |
# First, we build the correct url |
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 __future__ import absolute_import | |
import os | |
from celery import Celery | |
from django.conf import settings | |
# Indicate Celery to use the default Django settings module | |
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'myproject.settings') | |
app = Celery('myproject') | |
app.config_from_object('django.conf:settings') |
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.task.schedules import crontab | |
from celery.decorators import periodic_task | |
from myapp.utils import scrapers | |
from celery.utils.log import get_task_logger | |
from datetime import datetime | |
logger = get_task_logger(__name__) | |
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
# -*- coding: utf-8 -*- | |
from django.db import models | |
from django.utils.translation import ugettext_lazy as _ | |
import jsonfield | |
class TaskHistory(models.Model): | |
# Relations | |
# Attributes - mandatory | |
name = models.CharField( |
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
# -*- coding: utf-8 -*- | |
from celery.task.schedules import crontab | |
from celery.decorators import periodic_task | |
from celery.utils.log import get_task_logger | |
from datetime import datetime | |
from myapp.models import TaskHistory | |
logger = get_task_logger(__name__) | |
OlderNewer