Skip to content

Instantly share code, notes, and snippets.

View arkanister's full-sized avatar

Rafael Souza da Silva arkanister

View GitHub Profile
@arkanister
arkanister / week_range.py
Last active October 12, 2018 14:04
How to get the first and last day of a week based on a date.
# coding: utf-8
"""
Sometimes we really need to get the first and the last date
on a week, this function will help you to get this whatever
day your week starts.
"""
import datetime
MO, TU, WE, TH, FR, SA, SU = range(1, 8)
# coding: utf-8
"""
What if I wanna handle a python dict as a object?
This object provides the ability to a dict behave as a python object.
Usage:
>>> a = ObjectDict({'foo': 'bar', 'bar': {'foo': [{'bar': 'foo'}]}})
>>> a.foo
@arkanister
arkanister / running-dbviews-on-django.md
Created September 24, 2018 16:52
How to use DB Views with Django?

Sometimes is necessary to create database scripts and run it as a view in Django, but it could be hard, because you must manage the scripts outside the Django project structure.

To make it simple I've created a simple way to run those database view scripts integrated with django.

Setup

To make it possible, is necessary to create an engine to find and run these scripts inside the django apps. In your project create a file named db.py and put the bellow code inside:

# coding: utf-8
/* ========================================================================
* Share
* ========================================================================
* Copyright 2017 Arkanister.
* ======================================================================== */
/**
* <a href="https://github.com/arkanister/" title="Arkanister Profile" data-share="facebook">Share on Facebook</a>
* <a href="https://github.com/arkanister/" title="Arkanister Profile" data-share="twitter">Twitter</a>
@arkanister
arkanister / gravatar.py
Created January 16, 2015 19:06
Django gravatar url by template filter
# coding: utf-8
import hashlib
import httplib
import urllib
from django import template
from django.conf import settings
register = template.Library()
GRAVATAR_DOMAIN = "gravatar.com"