Sign up to create your own snipts, or login.

Public snipts » Fotinakis's snipts » python The latest python snipts from Fotinakis.

showing 1-4 of 4 snipts for python
  • Disassembler for Python bytecode
    $ python -m dis test.py 
      1           0 LOAD_CONST               0 ('Hello world')
                  3 PRINT_ITEM          
                  4 PRINT_NEWLINE       
                  5 LOAD_CONST               1 (None)
                  8 RETURN_VALUE        
    

    copy | embed

    0 comments - tagged in  posted by Fotinakis on Jul 14, 2009 at 1:50 a.m. EDT
  • Simple generation of random string in Python
    import string
    import random
    
    print "".join(random.sample(string.letters+string.digits, 8))
    

    copy | embed

    0 comments - tagged in  posted by Fotinakis on Jun 18, 2009 at 1:14 p.m. EDT
  • Django mod-wsgi hook file
    import os, sys
    import django.core.handlers.wsgi
    
    path = '/var/www/sub.example.com'
    if path not in sys.path: sys.path.append(path)
    
    os.environ['DJANGO_SETTINGS_MODULE'] = 'project_name.settings'
    
    application = django.core.handlers.wsgi.WSGIHandler()
    

    copy | embed

    0 comments - tagged in  posted by Fotinakis on Apr 22, 2009 at 3:36 p.m. EDT
  • Mass dynamic Django hosting based on hostname
    <VirtualHost *:80>
            ServerAdmin webmaster@localhost
            DocumentRoot /var/www/root
    
            RewriteEngine On
            RewriteMap tolower int:tolower
    
            # Redirect all www.
            RewriteCond   %{HTTP_HOST}                 ^www\..*$
            RewriteRule   ^(.+)                        %{HTTP_HOST}$1          [C]
            RewriteRule   ^www\.(.*) http://$1 [R=301,L]
    
            # For all admin media
            RewriteRule ^/media(.*) /usr/share/python-support/python-django/django/contrib/admin/media$1 [L]
    
            # For each project's static files
            RewriteRule ^/static(.*) /var/www/${tolower:%{SERVER_NAME}}/static$1
            RewriteRule ^/favicon.ico /var/www/${tolower:%{SERVER_NAME}}/static/images/favicon.ico
    
            # For each project's documentation
            RewriteRule ^/docs(.*) /var/www/${tolower:%{SERVER_NAME}}/docs/build/html$1
    
            # For each project's WSGI hook
            RewriteRule ^/(?!var/www/)(.*) /var/www/${tolower:%{SERVER_NAME}}/apache/django.wsgi/$1
            RewriteRule . - [E=APPLICATION_GROUP:${tolower:%{SERVER_NAME}}]
    
            WSGIProcessGroup %{GLOBAL}
            WSGIApplicationGroup %{ENV:APPLICATION_GROUP}
    
            # Run mod_wsgi in daemon mode, with daemons named by the site name 
            WSGIDaemonProcess %{ENV:APPLICATION_GROUP} processes=5 threads=10 python-path=/path/to/common display-name=%{GROUP}
    
            <Directory /var/www/*/apache>
                    Order allow,deny
                    Allow from all
                    Options ExecCGI
                    AddHandler wsgi-script .wsgi
            </Directory>
    
            <Directory /var/www/*/docs>
                    # You can protect the docs directories here
            </Directory>
    
            ErrorLog /var/log/apache2/error.log
    
            # Possible values include: debug, info, notice, warn, error, crit, alert, emerg.
            LogLevel warn
    
            CustomLog /var/log/apache2/access.log combined
    </VirtualHost>
    

    copy | embed

    0 comments - tagged in  posted by Fotinakis on Apr 22, 2009 at 3:31 p.m. EDT
Sign up to create your own snipts, or login.