This file contains hidden or 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 python3 | |
from math import sin, cos, pi, sqrt, asin, log | |
sqrt2 = sqrt(2) | |
def solveNR(lat, epsilon=1e-6): | |
"""Solve the equation $2\theta\sin(2\theta)=\pi\sin(\mathrm{lat})$ | |
using Newtons method""" | |
if abs(lat) == pi / 2: |
This file contains hidden or 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 pytz | |
from django.utils import timezone | |
.... | |
timezone.activate(pytz.timezone(user_time_zone)) |
This file contains hidden or 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 django.db import models | |
from django.utils import timezone | |
from django.contrib.auth.models import (AbstractBaseUser, | |
BaseUserManager as DjBaseUserManager) | |
from model_utils.managers import InheritanceManager | |
class BaseUserManager(DjBaseUserManager, InheritanceManager): | |
""" |
This file contains hidden or 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
# ... | |
class Category(Base): | |
slug = models.SlugField(_(u'slug'), max_length=100, unique=True) | |
title = models.CharField(_(u'title'), max_length=250) | |
parent = models.ForeignKey('self', blank=True, null=True, related_name='child') | |
class Meta: | |
verbose_name_plural = 'Categories' |
We can't make this file beautiful and searchable because it's too large.
This file contains hidden or 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
'00501','Holtsville','NY','America/New_York' | |
'00544','Holtsville','NY','America/New_York' | |
'01001','Agawam','MA','America/New_York' | |
'01002','Amherst','MA','America/New_York' | |
'01003','Amherst','MA','America/New_York' | |
'01004','Amherst','MA','America/New_York' | |
'01005','Barre','MA','America/New_York' | |
'01007','Belchertown','MA','America/New_York' | |
'01008','Blandford','MA','America/New_York' | |
'01009','Bondsville','MA','America/New_York' |
This file contains hidden or 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 django import forms | |
from django.contrib.auth.models import User | |
class UserProfileForm(forms.ModelForm): | |
class Meta: | |
model = User | |
fields = ['first_name', 'last_name', 'email'] | |
This file contains hidden or 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 python3 | |
""" | |
So far only tested on python3 interpreter. | |
Given an address, this script outputs a google maps url to the address. | |
""" | |
import requests, sys, time | |
from urllib.parse import quote_plus |
This file contains hidden or 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
# Convert Django DateTimeField values to ISO format in UTC | |
# Useful for making Django DateTimeField values compatible with the | |
# jquery.localtime plugin. | |
# | |
# https://gist.github.com/1195854 | |
from pytz import timezone, utc | |
from django.conf import settings | |
This file contains hidden or 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 sys | |
import urllib | |
import urllib2 | |
import json | |
import logging | |
class GeonamesError(Exception): | |
def __init__(self, status): |
This file contains hidden or 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
register = template.Library() | |
@register.filter(name='zodiac') | |
def zodiac(value): | |
""" Return appropriate zodiac for a given date | |
Usage in templates: {{ your_object.date_of_birth|zodiac }} """ | |
signs = ( | |
(u"Oğlak", range(356, 365)), | |
(u"Oğlak", range(1, 20)), | |
(u"Kova", range(21, 52)), | |
(u"Balık", range(52, 79)), |