Skip to content

Instantly share code, notes, and snippets.

View tadeck's full-sized avatar

Tom Jaskowski tadeck

View GitHub Profile
@tadeck
tadeck / kwacros.py
Created August 18, 2012 19:50 — forked from skyl/kwacros.py
Django Template macros with args and kwargs
#
# 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
#
@tadeck
tadeck / myip.py
Created August 18, 2012 19:59
Python script for getting public IP address
#!/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
@tadeck
tadeck / pip_upgrade_all.py
Created October 11, 2012 10:25
pip upgrade all Python modules
"""
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)
@tadeck
tadeck / tastypie_aware_datetime_field.py
Created November 5, 2012 13:02
Timezone-aware version of TastyPie's DateTimeField
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
@tadeck
tadeck / default_logger.py
Created April 21, 2013 00:42
The snippet adding support for logging even if code using it does not add handlers to module's logger. Shamelessly copied from python-requests.
# 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())
@tadeck
tadeck / explicit_checker.py
Created August 9, 2013 19:08
Decorator allowing function to receive information on the parameters that were passed to it during call, regardless of whether they were positional or keyword-based.
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:

Business Models

Advertising

Models Examples
Display ads Yahoo!
Search ads Google
@tadeck
tadeck / LICENSE.txt
Last active October 28, 2016 14:52 — forked from fengler/LICENSE.txt
sg-creator
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:
@tadeck
tadeck / offset_detection_pytz.py
Created November 7, 2016 17:24
How to convert local time to different UTC time stamps depending on whether there is, or there isn't DST in effect
>>> 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'
@tadeck
tadeck / tz_convert.py
Created November 8, 2016 19:15
Tool for converting time stamps between time zones
"""
Convert time stamps in different time zones between each other
"""
from datetime import datetime
import pytz
DATETIME_FORMAT = '%c'