Wednesday, September 8, 2010

Installing 64-bit Adobe Flash player in Ubuntu Lucid 10.4 on Chrome

This blog link talks about installing the 64-bit Adobe Flash player on Ubuntu v9.04.  But what about v10.04?

http://nxadm.wordpress.com/2009/04/26/install-64-bit-adobe-flash-player-on-ubuntu-904/

First, you need to install the chromium-browser:
sudo apt-get install chromium-browser
Then you need to download the Adobe flash player:

http://go2.wordpress.com/?id=725X1342&site=nxadm.wordpress.com&url=http%3A%2F%2Fhome.scarlet.be%2Fvar%2Ftmp%2Flibflashplayer-latest_closed_beta.linux-x86_64.so.tar.gz

You then need to copy the libflashplayer.so inside the .tar.gz file and copy it into the /usr/lib/chromium-browser/plugins dir.
tar xvfpz libflashplayer-latest_closed_beta.linux-x86_64.so.tar.gz 
cp libflashplayer.so /usr/lib/chromium-browser/plugins/

The final step is that you need to modify the Chrome to launch with the --enable-plugins

http://www.ubuntugeek.com/howto-enable-flash-support-for-google-chromium-browser.html

chromium-browser --enable-plugins %U

Footnote: I was not able to use the Ubuntu flashplugin-installer .so file package on Ubuntu Lucid v10.4 with Chrome. These instructions (above) worked for me.

You must shutdown all Chrome instances before restarting the browser. If the plugin is correctly installed, you should see something like the following:
Shockwave Flash
Description: Shockwave Flash 10.0 r45
Location: /usr/lib/mozilla/plugins/libflashplayer.so
MIME types: 
MIME type Description File extensions
application/x-shockwave-flash Shockwave Flash 
.swf
application/futuresplash FutureSplash Player 
.spl
Footntoe: I copied libflashplayer.so into /usr/lib/mozilla/plugins instead of /usr/lib/chromium/plugins. Chrome seems to be able to load the Mozilla plugins correctly, and starting up Firefox will allow you to also use the same plug-in.

Dropbox on Ubuntu Linux

Dropbox's instructions to install on Ubuntu are pretty straightforward:

https://www.dropbox.com/downloading?os=lnx

But they forget to tell you that you need to also update your /etc/apt/sources.list too!

sudo vi /etc/apt/sources.list

deb http://linux.getdropbox.com/ubuntu lucid main
deb-src http://linux.getdropbox.com/ubuntu lucid main

sudo apt-get update
sudo apt-get upgrade nautilus-dropbox
sudo apt-key adv --keyserver pgp.mit.edu --recv-keys 5044912E

Roger

Tuesday, September 7, 2010

Emacs v23 and CRITICAL assertion errors

I install Emacs v23 on Ubuntu Lucid and saw these random error messages:

** (emacs:10826): CRITICAL **: murrine_style_draw_box: assertion `height >= -1' failed

https://bugs.launchpad.net/ubuntu/+source/light-themes/+bug/538499

The way to fix it is here:

Modify the entry in /usr/share/themes/Ambiance/gtk-2.0/gtkrc from GtkRange::trough-under-steppers = 0 to GtkRange::trough-under-steppers = 1.

I credit this article to pointing out how to fix the issue.

http://thehacklist.blogspot.com/2010/06/resolving-murrinestyledrawbox-assertion.html

Saturday, September 4, 2010

Copying .emacs and .emacs.d files from one server to another via ssh

Copying from a server to your local dir:
rsync -avz -e ssh user@localhost.com:.emacs .
rsync -avz -e ssh user@localhost.com:.emacs.d .

Or copying from your local dir to another server:

rsync -avz <dir> -e ssh user@localhost:.

Thursday, September 2, 2010

Django Emacs Wiki

Django's Emacs Wiki page is horribly outdated -- many of the links to download the related scripts do not work. Furthermore, the documentation to get them installed requires digging through different parts of the web sites to find the right way to get them loaded. Furthermore, there's very little information about the pros/cons between the various Emacs helper scripts either.

In the order of the items listed, here is my experience with the ones listed on the page:
  • django-mode.el: download link is dead
  • django-html-mode.el: download link is dead
  • django-html-mumamo-mode: tells you to download the latest branch
  • Yasnippet: good for Django autocompletion only
In my previous blog posting, I wrote about some of the basic important Emacs helper programs. PyChecker and Uniqify are definite musts, but Yasnippets actually will conflict if you try to install django-html-mumamo-mode. In the interest of taking advantage of the django-html-mumamo-mode's ability to do Django block indents (the Django snippets for Yasnippet will not do this for you), I commented out the django-mode helpers from Yasnippet:
;(require 'django-html-mode)
;(require 'django-mode)
;(yas/load-directory "~/.emacs.d/plugins/django-mode/snippets")
The instructions on the Django page are to install the latest branch:
bzr branch lp:nxhtml
The problem is that you end up downloading the latest snapshot, which caused some problems for me when I tried into enter into django-html-mode. Instead, I downloaded the 4/25/10 release directly from the NXHTML page by visiting http://ourcomments.org/cgi-bin/emacsw32-dl-latest.pl. The release is hard to find on the main page but if you click on Download latest nXHTML (zip file)" you can retrieve the file.

I unzipped this file directly into ~/emacs.d, which creates an nxhtml/ directory.

Inside my .emacs file, I add three lines:
(load "~/.emacs.d/nxhtml/autostart.el")
(setq mumamo-background-colors nil)
(add-to-list 'auto-mode-alist '("\\.html$" . django-html-mumamo-mode))
The first line will invoke the NXHTML script to load. If you have Emacs v23, you shouldn't have to install the NXML library.

The second line deals with an issue of NXHTML changing the color background to blue. For more info, see
http://stackoverflow.com/questions/1146701/turning-off-chunk-coloring-in-emacs-nxhtml-mode.

The third line will force .HTML files into django-html-mumamo-mode. You can also use django-xhtml-mumamo-mode, which will have a "Valid/Invalid" at the bottom of the Emacs screen to inform you whether your HTML code is presumably XHTML-compliant.



http://code.djangoproject.com/wiki/Emacs

Using HTTPS inside Django unit tests

The Django documents at http://docs.djangoproject.com/en/dev/topics/testing/ discuss how to write unit tests for verifying the is_ajax() command:
The extra keyword arguments parameter can be used to specify headers to be sent in the request. For example:

>>> c = Client()
>>> c.get('/customers/details/', {'name': 'fred', 'age': 7},
...       HTTP_X_REQUESTED_WITH='XMLHttpRequest')
...will send the HTTP header HTTP_X_REQUESTED_WITH to the details view, which is a good way to test code paths that use the django.http.HttpRequest.is_ajax() method.
But what about testing for HTTPS connections? (i.e. HttpRequest.is_secure())

The key to figuring out this issue is to dig into django.test.client.py code, where self.client.get() and self.client.post() are defined. You will notice both of these routines will both ultimately call self.request():
def get(self, path, data={}, follow=False, **extra):
        """                                                                                                                                                             
        Requests a response from the server using GET.                                                                                                                  
        """
        r = {
            'CONTENT_TYPE':    'text/html; charset=utf-8',
            'PATH_INFO':       urllib.unquote(parsed[2]),
            'QUERY_STRING':    urlencode(data, doseq=True) or parsed[4],
            'REQUEST_METHOD': 'GET',
            'wsgi.input':      FakePayload('')
        }
        r.update(extra)

        response = self.request(**r)

    def post(self, path, data={}, content_type=MULTIPART_CONTENT,
             follow=False, **extra):
        """                                                                          
        Requests a response from the server using POST.                                                                                                                 
        """
.
.
.
        response = self.request(**r)

    def request(self, **request):
        """                                                                                                                                                             
        The master request method. Composes the environment dictionary                                                                                                  
        and passes to the handler, returning the result of the handler.                                                                                                 
        Assumes defaults for the query environment, which can be overridden                                                                                             
        using the arguments to the request.                                                                                                                             
        """
        environ = {
            'HTTP_COOKIE':       self.cookies.output(header='', sep='; '),
            'PATH_INFO':         '/',
            'QUERY_STRING':      '',
            'REMOTE_ADDR':       '127.0.0.1',
            'REQUEST_METHOD':    'GET',
            'SCRIPT_NAME':       '',
            'SERVER_NAME':       'testserver',
            'SERVER_PORT':       '80',
            'SERVER_PROTOCOL':   'HTTP/1.1',
            'wsgi.version':      (1,0),
            'wsgi.url_scheme':   'http',
            'wsgi.errors':       self.errors,
            'wsgi.multiprocess': True,
            'wsgi.multithread':  False,
            'wsgi.run_once':     False,
        }
        environ.update(self.defaults)
        environ.update(request)
Because the arguments **request originally came from the **extra parameters, we can override wsgi.url_scheme to be "https":
kwargs = {}
        kwargs["wsgi.url_scheme"] = "https"
        kwargs["HTTP_X_REQUESTED_WITH"] = 'XMLHttpRequest'

        response1 = self.client.post('%s' % my_url,
                                     {'test1' : '123456'}
                                     **kwargs)
Why does overriding the wsgi.url_scheme variable work? If you use the Python debugger and put an pdb.set_trace() inside one of your view handlers, you will notice the Django unit test runner uses django.core.handlers.wsgi.WSGIRequest for its request object (and not django.http.HttpRequest). We can then look inside django.core.handlers.wsgi.WSGIRequest to see how the is_secure() function is used:
def is_secure(self):
        return 'wsgi.url_scheme' in self.environ \
            and self.environ['wsgi.url_scheme'] == 'https'
So by overriding the wsgi.url_scheme variable, we can force our application to mimic the behavior when HTTPS is used.

For more on writing basic unit tests in Django, see this article link too: http://dougalmatthews.com/articles/2010/jan/20/testing-your-first-django-app/

Emacs with Django/Python

The indent-region command is useful for reformatting....Here are some short-cuts when doing Python/Django editing within Emacs:

Ctrl-Alt-a - goes to the beginning of the class
Ctrl-Alt-e - goes to the end of the class
Ctrl-c + > - shift region right
Ctrl-c + < - shift region left
Ctrl-c + Ctrl-h - lists all the related Python keys
Ctrl-x + 2 - split screen horizontally
Ctrl-x + 3 - split screen vertically
Ctrl-x + Ctrl-o - switch between windows
Alt-x + ansi-term - goes into full ANSI terminal shell
Ctrl-Alt-\ - reindent the current region (useful for fixing up blocks)

Things to add into your .emacs file:
  • Uniqify - makes it less confusing what files you're actually viewing within various Django dirs (i.e. views.py<1> becomes mymodule/views.py)

    The key is to use the 'forward' naming scheme to put part of the directory at the beginning of the buffer name.
  • PyFlakes - Shows you unused imports, mistakes on the-fly, etc. See Stack Overflow discussion at: http://stackoverflow.com/questions/1257236/django-emacs-as-textmate-replacement
  • Yasnippet - Useful for Django template editing.  You need to install Yasnippet (use the normal install instructions) before using the Django HTML snippets code here:
    mkdir ~/.emacs.d/plugins
    cd ~/.emacs.d/plugins
    wget http://code.google.com/p/yasnippet/downloads/detail?name=yasnippet-0.6.1c.tar.bz2&can=2&q=
    tar xvjf yasnippet-0.6.1c.tar.bz2
    
    apt-get install bzr
    
    cd /tmp
    bzr branch lp:python-mode
    bzr branch lp:django-mode
    
    mv /tmp/python-mode/python-mode.el ~/.emacs.d
    mv /tmp/django-mode/*.el ~/.emacs.d
    mv /tmp/django-mode/snippets ~/.emacs.d/plugins
    

My .emacs file looks like:
(require 'uniquify)
(setq uniquify-buffer-name-style 'forward)

(when (load "flymake" t) 
(defun flymake-pyflakes-init () 
(let* ((temp-file (flymake-init-create-temp-buffer-copy 
'flymake-create-temp-inplace)) 
(local-file (file-relative-name 
temp-file 
(file-name-directory buffer-file-name)))) 
(list "pyflakes" (list local-file)))) 
(add-to-list 'flymake-allowed-file-name-masks 
'("\\.py\\'" flymake-pyflakes-init)))
(add-hook 'python-mode-hook 'flymake-mode)

(add-to-list 'load-path "~/.emacs.d/plugins/yasnippet-0.6.1c")
(add-to-list 'load-path "~/.emacs.d")
(require 'yasnippet)
(yas/initialize)
(yas/load-directory "~/.emacs.d/plugins/yasnippet-0.6.1c/snippets")
(require 'django-html-mode)
(require 'django-mode)
(yas/load-directory "~/.emacs.d/plugins/django-mode/snippets")
The key is that I have to unpack the yasnippet code first. The django-mode yasnippets also depend on python-mode.el, so I have to install it. Note: there is a difference between python.el (which comes with the native Python install) and python-mode.el, which has to be downloaded separately.

One extra change was to modify django-html-mode.el to recognize .HTML files by default as Django/HTML files:

(add-to-list 'auto-mode-alist '("\\.html$" . django-html-mode))