Friday, March 29, 2013

Emacs: press F5 to reload Firefox browser

this is great for web developers. Press a key in Emacs to save your work, then reload a page in a real browser!  If you're doing debugging with Python logging, this is all you need to do for rapid development.



(require 'net-utils)

(defun save-buffers-reload-browser ()
  (interactive)
  (save-some-buffers t)
  (run-network-program "Firefox" "localhost" 32000 "reload"))

(global-set-key (kbd "") 'save-buffers-reload-browser)

Wednesday, March 27, 2013

Web Editing with Emacs tricks


this is awesome and very useful:

C-c C-f
Skip across a balanced tag group (which extends from an opening tag through its corresponding closing tag) (sgml-skip-tag-forward).   (Backward = C-c C-b)



C-c C-d
Delete the tag at or after point, and delete the matching tag too (sgml-delete-tag). If the tag at or after point is an opening tag, delete the closing tag too; if it is a closing tag, delete the opening tag too.       



C-c /
Insert a close tag for the innermost unterminated tag (sgml-close-tag). If called within a tag or a comment, close it instead of inserting a close tag.       


HTML Mode -- Emacs Manual

Monday, March 25, 2013

Thursday, March 21, 2013

Profiling Django

Install django-extensions


http://pythonhosted.org/django-extensions/runprofileserver.html


1) sudo pip install django-extensions

2) add 'django_extensions' to your app's INSTALLED_APPS list.


Run server in profiling mode

python  ./manage.py runprofileserver --prof-path=/tmp 8001

Do a query


time curl -i http://localhost:8001/account/eventboard/update/


Write little reporting module


prof.py -- given later

Run report


/tmp/account.eventboard.update.017442ms.1363891644.prof :
         202963 function calls (197801 primitive calls) in 17.443 seconds

   Ordered by: internal time, call count
   List reduced from 2280 to 5 due to restriction <5>

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
    26201   14.956    0.001   14.956    0.001 /usr/lib/python2.7/ssl.py:154(read)
        2    0.725    0.363    0.725    0.363 /usr/lib/python2.7/ssl.py:301(do_handshake)
      937    0.470    0.001   15.069    0.016 /usr/lib/python2.7/socket.py:406(readline)
       10    0.318    0.032    0.318    0.032 /usr/lib/python2.7/socket.py:223(meth)
        2    0.238    0.119    1.291    0.646 /usr/local/lib/python2.7/dist-packages/httplib2/__init__.py:982(connect)


In this case, most of the page delay was transferring SSL data -- probably from Google Analytics. Huzzah!




#!/usr/bin/env python
# prof.py

import glob, logging, hotshot.stats, pstats, sys

logging.basicConfig(stream=sys.stderr)
LOG = logging.getLogger(__name__)

for path in sys.argv[1:] or glob.glob('/tmp/*.prof'):
    if 'static.' in path:
        continue
    try:
        stats = hotshot.stats.load(path)
    except ValueError:
        stats = pstats.Stats(path)

    stats.sort_stats('time', 'calls') # sort the output based on time spent
    print path,':'
    stats.print_stats(5) # print the top culprits


Monday, March 18, 2013

Understanding the Git Workflow

The following article gives a more sophisticated view of clear code communication using Git trees.  Over the (recommended!) NVIE "A successful Git branching model" you can do squash commits and other techniques to quickly write reliable and easily reviewed code.

Understanding the Git Workflow

Thursday, March 14, 2013

Emacs: save all modified buffers


add to ~/.emacs.d/init.el:

(global-set-key 
 (kbd "")
 (lambda ()
   (interactive)
   (save-some-buffers t)))


JSHint picks bits of fluff from your JavaScript




Install


sudo apt-get install npm
sudo npm install jshint -g


Usage

JSHint doesn't understand Django tags.  This hack lets us check some of the code anyway:

egrep -v '{%'  _v2-brandcard.js | jshint --verbose /dev/stdin

Saturday, March 2, 2013

notes on the Mele A3700 Android media player #2

Now using "thoggen" to rip DVD's main feature into a single video, so the little Android apps can play them.  Default video type is OGV, which is a little weird. I ripped a sample 9 minute sample full resolution to see we could get to work:

Results so far:

Dolphin: works, software, unusable
ES Media Player: no OGV
FireAir: no OGV
JoeVLC: it works! Alas out of sync
MX Player: works! Hardware decoder works too!
QQ Player: nope
RockPlayer2: software, unusable
TvdVideo: nope

http://www.cyberciti.biz/tips/linux-dvd-ripper-software.html

notes on the Mele A3700 Android media player

This device is a cheap ($130) box which lets you play movies on your TV. As it runs Android, you can get a zillion apps to do other things, especially for playing games.  It comes with a white remote which is a mouse!  The idea is to connect it to your HDMI TV, a USB hard drive, then you'll never have to leave the couch again.



It's very cranky.

I bought this device to play DVDs (ISOs).  For some reason this is nearly impossible to do under normal Android apps.  Here are the results so far:

Joe VLC: ISO tried to play, then croaked
QQ Player: tries to play, no menu control
Rockplayer2 -- plays ISOs, software only, video completely separate from audio.

Also tested:
Dolphin player: no ISO
ES Media Player: no ISO
FireAir Player: no ISO
MX Player: no ISO(?)
Super-HD player: no ISO
TVD Player: no ISO