Skip to content

Instantly share code, notes, and snippets.

View pije76's full-sized avatar

panjianom pije76

View GitHub Profile
@pije76
pije76 / mollweide.py
Created August 28, 2017 02:14 — forked from zeimusu/mollweide.py
The mollweide equal area map projection. Convert longitude and latitude to and from 2d, flat cartiesian coordinates
#!/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:
@pije76
pije76 / activate_timezone.py
Created August 16, 2017 07:55 — forked from arulmr/activate_timezone.py
Getting user timezone from IP in Django
import pytz
from django.utils import timezone
....
timezone.activate(pytz.timezone(user_time_zone))
@pije76
pije76 / models.py
Created August 15, 2017 09:51 — forked from vinyll/models.py
Advanced user inheritance with Django
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):
"""
@pije76
pije76 / models.py
Created August 15, 2017 09:19 — forked from mhulse/models.py
Django basic/simple category/sub-category model.
# ...
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'
@pije76
pije76 / zip2tz.csv
Created August 13, 2017 18:42 — forked from benjiwheeler/zip2tz.csv
Zip to Time Zone csv
We can't make this file beautiful and searchable because it's too large.
'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'
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']
@pije76
pije76 / maps_url.py
Created August 9, 2017 05:31 — forked from willcharlton/maps_url.py
Python (3) snippet to generate google maps url and timezone for a given address.
#!/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
@pije76
pije76 / utcisoformat.py
Created July 30, 2017 08:51 — forked from bryanchow/utcisoformat.py
Convert Django DateTimeField values to ISO format in UTC
# 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
@pije76
pije76 / geonames.py
Created July 30, 2017 01:52 — forked from pamelafox/geonames.py
Geonames Python wrapper
import sys
import urllib
import urllib2
import json
import logging
class GeonamesError(Exception):
def __init__(self, status):
@pije76
pije76 / zodiac_tag.py
Created July 29, 2017 21:10 — forked from amiroff/zodiac_tag.py
Django template filter that returns appropriate zodiac for a given date (in Turkish)
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)),