Trace db queries in Django shell

import logging
l = logging.getLogger('django.db.backends')
l.setLevel(logging.DEBUG)
l.addHandler(logging.StreamHandler())

or use this command (requires Django Debug Toolbar installed):

$ python manage.py debugsqlshell

or add this to your settings:

#
# LOGGING
#

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'formatters': {
        'verbose': {
            'format': '%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s'
        },
        'simple': {
            'format': '%(levelname)s %(message)s'
        },
    },
    'handlers': {
        # 'file': {
        #     'level': 'DEBUG',
        #     'class': 'logging.FileHandler',
        #     'filename': '/home/aecweb/logs/django.log',
        # },
        'console': {
            'level': 'DEBUG',
            'class': 'logging.StreamHandler',
            'formatter': 'simple'
        },
        'mail_admins': {
            'level': 'ERROR',
            'class': 'django.utils.log.AdminEmailHandler',
        },
    },
    'loggers': {
        'django.db.backends': {
            'handlers': ['console', ],
            'level': 'DEBUG',
        },
    },
}

Build absolute url from relative url in Django

file myproject/utils.py

def build_absolute_url(request, relative_url):
    protocol = 'https' if request.is_secure() else 'http'
    domain = request.get_host()
    url = protocol + '://' + domain
    if not relative_url.startswith('/'):
        url += '/'
    return url + relative_url

Eventually, in templatetags.py

register = template.Library()

@register.filter
def build_absolute_url(request, relative_url):
    """ Sample usage:
        {{request|build_absolute_url:relative_url}}
    """
    from myproject.utils import build_absolute_url
    text = build_absolute_url(request, relative_url)
    return text

Accessing the model instance from within ModelAdmin?

Untested !
TODO: test this

    def get_object(self, request, model):
        object_id = request.META['PATH_INFO'].strip('/').split('/')[-1]
        # ?? object_id = resolve(request.path).args[0]
        try:
            object_id = int(object_id)
        except ValueError:
            return None
        return model.objects.get(pk=object_id)

Credits: http://stackoverflow.com/questions/949268/django-accessing-the-model-instance-from-within-modeladmin

RabbitMQ

Install and reload on Mac (macports)

$ sudo port install rabbitmq-server
$ sudo rabbitmq-plugins enable rabbitmq_management
http://localhost:15672 (guest/guest)

$ sudo port unload rabbitmq-server
$ sudo port load rabbitmq-server

$ sudo rabbitmq-plugins enable rabbitmq_tracing

Tools for Windows

ConEmu

Customizable Windows console emulator with tabs

Download from: https://github.com/Maximus5/ConEmu

AutoHotkey

Fast scriptable desktop automation with hotkeys

Download from: http://www.autohotkey.com/

Sample “AutoHotkey.ahk” file, to be saved in:
“C:\Users\USERNAME\Documents\AutoHotkey.ahk”

; IMPORTANT INFO ABOUT GETTING STARTED: Lines that start with a
; semicolon, such as this one, are comments.  They are not executed.

; This script has a special filename and path because it is automatically
; launched when you run the program directly.  Also, any text file whose
; name ends in .ahk is associated with the program, which means that it
; can be launched simply by double-clicking it.  You can have as many .ahk
; files as you want, located in any folder.  You can also run more than
; one .ahk file simultaneously and each will get its own tray icon.

; SAMPLE HOTKEYS: Below are two sample hotkeys.  The first is Win+Z and it
; launches a web site in the default browser.  The second is Control+Alt+N
; and it launches a new Notepad window (or activates an existing one).  To
; try out these hotkeys, run AutoHotkey again, which will load this file.

;#z::Run www.autohotkey.com
;
;^!n::
;IfWinExist Untitled - Notepad
;	WinActivate
;else
;	Run Notepad
;return


; Note: From now on whenever you run AutoHotkey directly, this script
; will be loaded.  So feel free to customize it to suit your needs.

; Please read the QUICK-START TUTORIAL near the top of the help file.
; It explains how to perform common automation tasks such as sending
; keystrokes and mouse clicks.  It also explains more about hotkeys.


#SingleInstance force
#r::Send ^r ;reload
#z::Send ^z ; undo
#y::Send ^y ; redo
#f::Send ^f ; find inside apps
#a::Send ^a ; select all
#c::Send ^c ; copy
#x::Send ^x ; cut
#v::Send ^v ; paste
#t::Send ^t ; new tab, Firefox
#s::Send ^s ; save inside apps
LWin & Tab::AltTab ; the motherlode, alt-tab!

#+f::Send ^+f ; find in files
#/::Send ^/ ; toggle comment
#p::Send ^p ; goto anything
#+n::Send ^+n ; new window

Access hidden files and folders on Mac to restore in Time Machine

  1. use this command to show hidden files and folders in Finder
$ defaults write com.apple.finder AppleShowAllFiles TRUE;killall Finder
  1. use Time Machine to restore files
  2. restore Finder settings:
$ defaults write com.apple.finder AppleShowAllFiles FALSE;killall Finder