Models | Examples |
---|---|
Display ads | Yahoo! |
Search ads |
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
# | |
# templatetags/kwacros.py - Support for macros in Django templates | |
# | |
# Based on snippet by | |
# Author: Michal Ludvig <[email protected]> | |
# http://www.logix.cz/michal | |
# | |
# modified for args and kwargs by Skylar Saveland http://skyl.org | |
# |
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 | |
""" | |
This simple script fetches your IP as seen by web pages, and displays it. | |
Execute this script locally like that: | |
$ curl -s https://raw.github.com/gist/3389407/myip.py | python | |
""" | |
import urllib2 |
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
""" | |
Script for upgrading all modules using pip command-line tool. | |
Source: http://stackoverflow.com/a/5839291/548696 | |
""" | |
import pip | |
from subprocess import call | |
for dist in pip.get_installed_distributions(): | |
call("pip install --upgrade " + dist.project_name, shell=True) |
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
class AwareDateTimeField(DateTimeField): | |
""" | |
This field is timezone-aware version of TastyPie standard DateTime field | |
""" | |
def convert(self, value): | |
""" | |
Convert any value stored in this field to the actual ISO-8601 string | |
:param value: | |
:return: deserialized value | |
:rtype: str or NoneType |
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
# Set default logging handler to avoid "No handler found" warnings. | |
import logging | |
try: # Python 2.7+ | |
from logging import NullHandler | |
except ImportError: | |
class NullHandler(logging.Handler): | |
def emit(self, record): | |
pass | |
logging.getLogger(__name__).addHandler(NullHandler()) |
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 functools import partial, wraps | |
def explicit_checker(func=None, names_arg='explicit_params'): | |
"""Decorator of function, allowing the function to receive names of attributes | |
that were explicitly set (either positionally or as keyword arguments). The | |
explicitly set arguments are received as set assigned to some keyword argument | |
at function call (default name is "explicit_params"). | |
Example usage: |
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
The MIT License (MIT) | |
Copyright (c) [2013] [Fanya Engler] | |
Permission is hereby granted, free of charge, to any person obtaining a copy of | |
this software and associated documentation files (the "Software"), to deal in | |
the Software without restriction, including without limitation the rights to | |
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | |
the Software, and to permit persons to whom the Software is furnished to do so, | |
subject to the following conditions: |
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 pytz | |
>>> from datetime import datetime | |
>>> pytz.timezone('US/Mountain').localize(datetime(year=2016, month=11, day=3, hour=12, minute=0)).astimezone(pytz.UTC).isoformat() | |
'2016-11-03T18:00:00+00:00' | |
>>> pytz.timezone('US/Mountain').localize(datetime(year=2016, month=11, day=7, hour=12, minute=0)).astimezone(pytz.UTC).isoformat() | |
'2016-11-07T19:00:00+00:00' |
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
""" | |
Convert time stamps in different time zones between each other | |
""" | |
from datetime import datetime | |
import pytz | |
DATETIME_FORMAT = '%c' | |