Wednesday, September 29, 2010

Issues with Sprint U301 USB modem (especially on Ubuntu Lucid)

These link say it all:
http://kerneltrap.org/mailarchive/linux-usb/2010/2/19/6257991

I'm doing some reliability testing to see what happens to the device if it loses
service.  With a connection up, I place the device inside a metal enclosure to
simulate the loss of network connectivity.

The device behaves as I would expect for the first ten to fifteen minutes (I
have not timed it).  The PPP connection takes a few minutes to timeout and die.
wvdial tries to dial a bit more and then quits.

The problems come after the device has sat idle for a few more minutes.  It
subsequently goes offline.  I am unable to revive it except by physically
disconnecting it from the USB port and reinserting it.
http://www.mail-archive.com/networkmanager-list@gnome.org/msg15988.html

It may be time to switch back to the U598 modem.

Friday, September 24, 2010

Thinkpad T510 laptops mouse/touchpad issues with Ubuntu v10.04

There have been 2 problems that I've observed with using Ubuntu Lucid v10.04 with the Thinkpad T510. The first is that the Synaptics touchpad seems to cause accidental scrolls and button clicks. The second is that the middle trackpoint doesn't work out of the box.

For the first issue, this link first clue me into the possible issue:
http://www.paralaptop.com/tag/ibm-thinkpad-t510-mouse-problems
Actually there is simple solution to fix the problem of T500 touchpad messing up while typing. What you need is just pressing Fn + F8 keys on your T500 laptop. There you should see any setting you can use to manage the system. Looking for the touchpad option and choose to only enable the touchpoint and disable the touchpad. This method is works fine whether on Lenovo T500 or T400 laptop.

Hitting Fn + F8 must be done after each reboot, so one way would be to install the gpointing-device-settings package (sudo apt-get install gpointing-device-settings) and then selecting the "Touchpad off" option:

http://www.andrewferrier.com/blog/2010/06/04/disabling-synaptics-touchpad-with-ubuntu-10-04/

For the record, I tried only to disable the vertical/horizontal scrolling checkboxes to no avail. It seems that the touchpad should be disabled if you're using the pointer device.

Another thing: the middle button does not work for scrolling without extra changes:

http://psung.blogspot.com/2010/04/thinkpad-trackpoint-scrolling-in-ubuntu.html

Create a new file /usr/lib/X11/xorg.conf.d/20-thinkpad.conf with the following contents:

Section "InputClass"
    Identifier "Trackpoint Wheel Emulation"
    MatchProduct "TrackPoint"
    MatchDevicePath "/dev/input/event*"
    Driver "evdev"
    Option "EmulateWheel" "true"
    Option "EmulateWheelButton" "2"
    Option "Emulate3Buttons" "false"
    Option "XAxisMapping" "6 7"
    Option "YAxisMapping" "4 5"
EndSection
Then restart X11 (or it may be easier to reboot).

Polycom VoiceStation 500 and Android headsets...a solution...

http://www.amazon.com/Voicestation-Analog-Conference-Phone-Bluetooth/dp/B000GGMLNM/ref=sr_1_1?s=electronics&ie=UTF8&qid=1285368276&sr=1-1

We called Polycom support and it appears to be a known technical issue with the Android stack. You're supposed to click on the Mode button for 3 seconds on the Polycom to pairing mode, which will show the device on the Android phone. However, all you see is the "Pairing but not connected" when trying to connect to the Polycom VoiceStation 500 unit. The issue is observed for both Android v1.6 (HTC Magic phones) and Motorola Droid phones running Android v2.2

Polycom says it is an issue with Google's Bluetooth stack. The latest v2.2 release does not seem to solve this compatibility issue, and there enough reports that the Android Bluetooth stack (BlueZ) has issues pairing with car stereos, keyboards, etc.

For Android-based headsets, you can use the 3.5mm to 2.5mm cable that comes with the Polycom VoiceStation 500. However, the cable that comes with this one has two types of a cable: 1) a 2.5mm to 2.5mm cable (which doesn't work on Droid 3.5mm headset), and 2) a 2.5mm to Y-pronged 3.5mm for computer microphone and output.

If you use the 2nd cable included (and use the green-labeled connection for headset), you can at least use the Polycom for voice conference calls while relying on the Droid headset for microphone input. We're in the process of ordering a 2.5mm female to 3.5mm adapter to see if we can use both the Polycom's microphone/speaker.

At least this solution allows Droid-based phones to use the Polycom, though you're certainly paying a premium for Bluetooth support that doesn't work. The Polycom unit seems to work fine though with iPhone's.

In case you want to learn more about how the Android Bluetooth stack works, here is a slide presentation that I found:
http://www.slideshare.net/erinyueh/android-bluetooth-introduction

Thursday, September 23, 2010

Switched to using http://deluxetemplates.net

I've switched to using the templates at: http://www.deluxetemplates.net/
You have to unzip the XML template and then upload the file according to these instructions:

http://www.deluxetemplates.net/1999/04/how-to-install-blogger-xml-template.html

How to install a Blogger Template

Follow Most Simple Guide to Install your Favorite Blogger Template.
1. Click in Download button and save file in PC [hard drive].

2. File that you have downloaded is .ZIP file so need to be extracted. Extract / Unzip it.

3. Log in Blogger dashboard

4. Click Design link in dashboard panel.

5. Now click in Edit HTML link in tab bar.

6. Click Browse button and look for folder that is created after extracted file that you have downloaded.

7. Folder has a XML file and TXT file or Internet shortcut, you select only XML file.

8. Click Upload button.

9. Confirm and Save.

One thing I had to do is reinstall Prettify based on this Stack Overflow thread:
http://stackoverflow.com/questions/1852537/how-to-use-prettify-with-blogger-blogspot

<link href='http://google-code-prettify.googlecode.com/svn/trunk/src/prettify.css' rel='stylesheet' type='text/css'/> 
<script src='http://google-code-prettify.googlecode.com/svn/trunk/src/prettify.js' type='text/javascript'></script>
After "</head>" replace "<body>" with "<body onload='prettyPrint()'>"

One more thing: some designs may turn off the navbar at the top. Some people find it annoying, but I found it very useful. You will need to go into the Design->Edit HTML and look for the CSS navbar-iframe style. Here is the code commented out:

/*#navbar-iframe {
display: none !important;
}*/

OpenOffice and Windows PowerPoint PPT/PPTX files in Ubuntu 10.04

One of the recent issues I encountered was opening PowerPoint documents in OpenOffice. I noticed font-rendering issues. It made me realize that the Ubuntu 10.04 install doesn't come with the Vista/Windows 7 fonts.

I followed these instructions:
http://embraceubuntu.com/2007/09/16/installing-vista-fonts-in-ubuntu/

sudo apt-get install cabextract
sudo apt-get install curl
sudo apt-get install wget
I then downloaded this installer script:
wget http://plasmasturm.org/code/vistafonts-installer/vistafonts-installer
The installer script will download the Microsoft PowerPoint Viewer (25MB fil) and extract the various fonts (Calibri, Cambria, Candara, etc.).
mkdir ~/.fonts
chmod a+x ~/vista-fonts-installer
to make the file/script executable.
Then run the script using:
$ ./vista-fonts-installer

Notice inside the vista-fonts-installer.sh, there is this line:
fc-cache -fv ~/.fonts
The installer script wants you to download your fonts into ~/.fonts. If you intend to share the instance with multiple users, it may be better to move them into /usr/share/fonts/vista or /usr/share/fonts/windows7. You should run "fc-cache -fv /usr/share/fonts/[dir]" if you move your font files.

My script therefore got changed to:

#!/bin/sh
# Copyright (c) 2007 Aristotle Pagaltzis
# 
# 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:
# 
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
# 
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.

set -e

exists() { which "$1" &> /dev/null ; }

if ! [ -d /usr/share/fonts/windows7 ] ; then
 exec 2>&1
 echo 'There is no .fonts directory in your home.'
 echo 'Is fontconfig set up for privately installed fonts?'
 exit 1
fi

# split up to keep the download command short
DL_HOST=download.microsoft.com
DL_PATH=download/f/5/a/f5a3df76-d856-4a61-a6bd-722f52a5be26
ARCHIVE=PowerPointViewer.exe
URL="http://$DL_HOST/$DL_PATH/$ARCHIVE"


if ! [ -e "$ARCHIVE" ] ; then
 if   exists curl  ; then curl -O "$URL"
 elif exists wget  ; then wget    "$URL"
 elif exists fetch ; then fetch   "$URL"
 fi
fi

TMPDIR=`mktemp -d`
trap 'rm -rf "$TMPDIR"' EXIT INT QUIT TERM

cabextract -L -F ppviewer.cab -d "$TMPDIR" "$ARCHIVE"

cabextract -L -F '*.TT[FC]' -d /usr/share/fonts/windows7 "$TMPDIR/ppviewer.cab"

( cd /usr/share/fonts/windows7 && mv cambria.ttc cambria.ttf && chmod 644 \
 calibri{,b,i,z}.ttf cambria{,b,i,z}.ttf candara{,b,i,z}.ttf \
 consola{,b,i,z}.ttf constan{,b,i,z}.ttf corbel{,b,i,z}.ttf )

fc-cache -fv /usr/share/fonts/windows7


The other thing you may need to do is logout and log back in. This will let you insure that the fonts are loaded properly.

Installing Java on Ubuntu 10.04

sudo apt-get install python-software-properties
sudo add-apt-repository 'deb http://archive.canonical.com/ lucid partner'
sudo apt-get update
sudo apt-get install sun-java6-jre sun-java6-plugin sun-java6-fonts

If you want JDK for development, you should also do:

sudo apt-get install sun-java6-jdk

Wednesday, September 22, 2010

JSONP and cross-domain Ajax calls

I was looking at this demo and trying to figure out how the cross-domain Ajax works:

http://www.prettyklicks.com/demo/fbjson.php

Some background info is here:
http://www.ibm.com/developerworks/library/wa-aj-jsonp1/?ca=dgr-jw64JSONP jQuery&S_TACT=105AGY46&S_CMP=grsitejw64

Here's the nitty/gritty - it boils down to avoid using the XMLHttpRequest object, injecting a <script src> tag that retrieves a JSON-encoded response but wrapped in a callback function, and then creating the callback function in the native browser that then gets invoked.

Both client and server need to be equipped to handle this technique. On the client side, JQuery does all of this magic under the covers with its JSONP implementation. On the server side, the server needs to wrap a JSON data if a callback= parameter is specified.

The JavaScript code has this line:
var url = "http://graph.facebook.com/prettyklicks/feed?limit=5&callback=?";
But the actual URL call translates to:
http://graph.facebook.com/prettyklicks/feed?limit=5&callback=jsonp1285193963567
It turns out there's a bit of jQuery and server-side magic going on. On the server side, It seems that when this callback= function will wrap a function that can then be executed by the DOM tree, similar to what's being done here:

http://code.google.com/p/django-rest-interface/issues/detail?id=39

So the server will return a result such as the following (note the jsonp1285197073066() function):
jsonp1285197073066({
   "data": [
      {
         "id": "45075726743_434059296743",
         "from": {
            "name": "Jason John Adams",
            "id": "1205845313"
         },
         "to": {
            "data": [
               {
                  "name": "Pretty Klicks",
                  "category": "Artist",
                  "id": "45075726743"
               }
            ]
         },
.
.
.
});
On the client-side, the JQuery's ajax() function has some checking for whether the Ajax() call actually seems to have a regexp check to see if there is a & or ? appended at the end of the URL call for JSON Ajax calls. It uses this regexp to replace the ? with a generated function name to call.
jsre = /=\?(&|$)/,
This section seems to rename the callback to ?jsonp=jsc (i.e. jsonp1285193963567).
var jsc = now(),
.
.
// Build temporary JSONP function
  if ( s.dataType === "json" && (s.data && jsre.test(s.data) || jsre.test(s.url)) ) {
   jsonp = s.jsonpCallback || ("jsonp" + jsc++);



   // Replace the =? sequence both in the query string and the data
   if ( s.data ) {
    s.data = (s.data + "").replace(jsre, "=" + jsonp + "$1");
   }


This section then creates a function based on the callback name (jsonp):

s.url = s.url.replace(jsre, "=" + jsonp + "$1");

   // We need to make sure
   // that a JSONP style response is executed properly
   s.dataType = "script";

   // Handle JSONP-style loading
   window[ jsonp ] = window[ jsonp ] || function( tmp ) {
    data = tmp;
    success();
    complete();
    // Garbage collect
    window[ jsonp ] = undefined;

    try {
     delete window[ jsonp ];
    } catch(e) {}

    if ( head ) {
     head.removeChild( script );
    }
   };
  }
So what's happening is that jQuery creates a function that will take as an argument tmp, which corresponds to the data from the JSON response. So when the script finishes loading, it will be executed and the Ajax callback is called.
function success() {
   // If a local callback was specified, fire it and pass it the data
   if ( s.success ) {
    s.success.call( callbackContext, data, status, xhr );
   }

   // Fire the global callback
   if ( s.global ) {
    trigger( "ajaxSuccess", [xhr, s] );
   }
  }
The last part of the equation is that script tags are inserted in the HEAD document with the src= set to the external URL. By doing is this way, the result will be evaluated by the function that we previously added to the window object.
// If we're requesting a remote document
  // and trying to load JSON or Script with a GET
  if ( s.dataType === "script" && type === "GET" && remote ) {
   var head = document.getElementsByTagName("head")[0] || document.documentElement;
   var script = document.createElement("script");
   script.src = s.url;
   if ( s.scriptCharset ) {
    script.charset = s.scriptCharset;
   }

   // Use insertBefore instead of appendChild  to circumvent an IE6 bug.
   // This arises when a base node is used (#2709 and #4378).
   head.insertBefore( script, head.firstChild );

   // We handle everything using the script element injection
   return undefined;
  }
This success function can then be used by the $.getJSON call from http://www.prettyklicks.com/demo/fbjson.php to retrieve and process the data:

function(json){
      var html = "
    "; //loop through and within data array's retrieve the message variable. $.each(json.data,function(i,fb){ html += "
  • " + fb.message + "
  • "; }); html += "
";

Friday, September 17, 2010

Finding the encoding of a MySQL table

Inside a MySQL database, you can type the following:

sql> show variables like "character_set%"
    -> ;
+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client     | latin1                     | 
| character_set_connection | latin1                     | 
| character_set_database   | utf8                       | 
| character_set_filesystem | binary                     | 
| character_set_results    | latin1                     | 
| character_set_server     | latin1                     | 
| character_set_system     | utf8                       | 
| character_sets_dir       | /usr/share/mysql/charsets/ | 
+--------------------------+----------------------------+
8 rows in set (0.00 sec)

Thanks to https://wincent.com/wiki/Finding_out_the_encoding_of_a_MySQL_database

http://blog.awarelabs.com/2008/django-tips-utf-8-ascii-encoding-errors-urllib2-and-mysql/

Django uses a default character set of UTF-8, so when it connects to the MySQL database, it uses UTF-8. If you use mysql to interface, you will notice that the character_set_results are set to latin1 (otherwise known as ASCII).

Thursday, September 16, 2010

Design for Non Designers - Jason Putorti's talk

Jason Putorti - http://jasonputorti.com/

Slides from the talk: http://www.slideshare.net/novaurora/10-things-ceos-need-to-know-about-design

Annotated notes:

- Jason left Mint.com after it was bought by Intuit.
- He was offered a job at Bessemer Ventures.
He consults with about 3 dozen companies in the portfolio.

1. Design can change businesses

- The whole premise of Mint.com: “We want your bank passwords. Trust me.”
- The visual design affects creditability in a very emotional way.
- A Craigslist design was not going to work.
- Notice on the site: Safe & Secure is dead last.
- Don't think of an elephant.
- No motivation to sign-up.
- Overwhelm the customer with benefits.

- Zappos.com
- Shoes is a commodity business. Focused on crafting customer experience.
- Often times Zappos upgrades your shipping to 2-day for free (wow!).

- Picture of the first MP3 player (not Apple obviously - Creative Labs?)
- Whole process: rip, burn, copy, very cumbersome.
- Lots of friction
- This product had 1st mover advantage.
- However, Apple was the 1st with product/market fit
- ITunes: designed around the music experience

- I'm on Twitter. vs. You should follow me on twitter here.-> 173% increase in clips
No big design/code changes: just a quick text change to compel the user to
take action.

- ABTest.com
- Use this site test 2 different versions of the same page (layout changes)

2. Design is more than pretty pictures.

- What is design? Design thinking: essential ability to combine empathy, creativity, and rationality to meet user needs & drive business success.

User experience:
How your product feels
Refers to Jesse James Garrett's book: Elements of User Experience (http://www.jjg.net/elements/)
Going through signup: completing a task in the product all the way to the error message in the product.
Make error messages things that users can take action on!

Customer experience:
It represents the sum of all the interactions a customer has with a company.
You should assign a value for each of them to better quantify.

Signup flow:
Completing a product.
Error message in the product
Vieiwng your home page
Reading a marketing email
Dealing with customer service

Your brand is how customers feel about you.
Shows AT&T logo
(You can hear people groan – translates to people associating the company with dropped calls)
Steve Ballmer picture

3. Great design: talks benefits, not features.

Four examples:
Mint.com: Understand your money vs. providing 20 different color configurations
“Remove your personal data” vs. “computer fuzzy-matching algorithm
iPod Ad: “All kinds of fun”
No GB storage spcs, video clip of just people having fun
CampignMonitor.com
The site has clear calls to action.
It has a clear visual heirarchy.
At the bottom there are creditability logos (Ebay, Intel, etc.)

4. Great design: thinks in flows, not screens.

1.User enters email address/login.
2.User enters pw.
3.User clicks Login button
4.System validates login

Submit button: just don't let them submit. Hide submit button and validate while the user's typing. You may consider disabling the submit button.

5. Great design: doesn't make the user think
Low-hanging fruit
Banana: if users can't find the banana, they are going to leave.
Yahoo example:
Focused on making the site a portal, put too much stuff because click impressions and banner ads made money. Thought about business objective, not the user objective.
Google
They put search right in the middle!

Take note of task flows in your product.
The truth is that people really don't want to use your software. Make it easy.

Put your site on an interaction scale.
Obvious <-----------> Requires Thought

Measure it this way.

Make it obvious what's clickable.
If you can't, make it discoverable.
Mint.com example: Hover over the pie charts, then click. The user has to discover it, but only has to learn once.

People don't read, they scan.
Newspaper have figured this out. They have a visual heirarchy that allows people to drill into stories in which they're interested.

Minimize noise
American Airlines site: it's an example of marketing departments gone wild.
Need someone to say no.
Bright colors, too much text.

- Omit needless words.

Users pick the 1st reasonable option..
- Example: Intacct.com: I am....

Too many options leads to paralysis.
Intacct.com offers 3 ways to do a demo:
Schedule a Live Demo
On-demand Demo
Intact Test Drive

American Airlines site:
Put a person on the page → go straight to their eyes.

Want to get famous? make fun of a site. He shows an example of a mockup of
what AA's site could look like redesigned.

6. A great design process starts with a great story

- Does everyone on your team know what the experience will be like interacting with your offering five years from now on?

How would it work if it were magic? OpenTable futuristic example: turning it into a concierge service.

7. Uses design as a lever.

The best marketing tool you can have is a well-designed application.
Business development:
Assign your revenue with valuable and legitimate users tasks.
Mint.com does this well to save you money.

Negative interactions drive negative social media.
Easy tools of mass command: easy to kill your brand.
No amount of money can buy the media to fix a boring product.
Have a brand czar.

8. A great design process gets people out of the office.

Have your teams spend at least 2 hours watching people experience your product or service.
Ex: logging people out because they were constantly going to take care of other things.


9. A great design process...has a bible.

A startup needs a brand czar.
Large company should have a style guide.
As opposed to each department have its own customer-facing guidess.


10. A great design process...repeats and refines.
In the last six weeks, have you held a celebration of a recently introduced design problem?

Q&A:

Jason: considers himself the defender of user experience. Tensions with the Mint.com biz dev: wanted to do a whole bunch of pop-ups of financial products. Rather than doing it this way, he put it in the activity stream. This way, it did not tick people off yet still achieved the comapny's goals.

Role of Product Manager: gather intelligence like the CIA.
Loudest users don't always represent the majority.
Mint.com: at one point wanted to consider managing transactions, but you introduce a whole tons of complexity (i.e. reconciling inconsistencies of your balance).

Wednesday, September 15, 2010

Using ObjectDoesNotExist to catch DoesNotExist errors

The Django documentation discusses the DoesNotExist error as follows:

http://docs.djangoproject.com/en/dev/ref/models/querysets/#id5
get() raises a DoesNotExist exception if an object wasn't found for the given parameters. This exception is also an attribute of the model class. Example:

Entry.objects.get(id='foo') # raises Entry.DoesNotExist

The DoesNotExist exception inherits from django.core.exceptions.ObjectDoesNotExist, so you can target multiple DoesNotExist exceptions.
How does it actually work? The Stack Overflow thread has this discussion:
http://stackoverflow.com/questions/2143506/django-where-does-doesnotexist-come-from

If you dig through the django.db.models.base.py file, you see these lines:
class ModelBase(type):

     super_new = super(ModelBase, cls).__new__
     new_class = super_new(cls, name, bases, {'__module__': module})

     if not abstract:
            new_class.add_to_class('DoesNotExist',
                    subclass_exception('DoesNotExist', ObjectDoesNotExist, module))
            new_class.add_to_class('MultipleObjectsReturned',
                    subclass_exception('MultipleObjectsReturned', MultipleObjectsReturned, module))

.
.
.
   def add_to_class(cls, name, value):
        if hasattr(value, 'contribute_to_class'):
            value.contribute_to_class(cls, name)
        else:
            setattr(cls, name, value)


You then have to wade through the bottom of the file to see what subclass_exception() actually does:
if sys.version_info < (2, 5):
    # Prior to Python 2.5, Exception was an old-style class                                                                                                                                                                                  
    def subclass_exception(name, parent, unused):
        return types.ClassType(name, (parent,), {})
else:
    def subclass_exception(name, parent, module):
        return type(name, (parent,), {'__module__': module})
It seems that Django creates a DoesNotExist exception for the class itself dynamically. The parent object is ObjectDoesNotExist, so you can use that parent to be able to catch exceptions thrown by multiple classes.

Tuesday, September 14, 2010

Emacs and PyFlakes

If you happen to be running Ubuntu v8.04, doing an apt-get install Pyflakes will install version 0.20. The Ubuntu packages confirmed this finding for me:

https://launchpad.net/ubuntu/+source/pyflakes/0.2.1+svn14502-1ubuntu1/+build/545566

Doing a Google search, you will see reports that Emacs hangs when using triple quotes ('''). You end up seeing really high CPU load and the only way to solve the issue is by killing the process. In fact, there was a $500 bounty to solve this issue 2 years ago:

http://www.plope.com/bounty_solved
I have solved our problem with triple-quotes.

 The problem is that Emacs expects PyFlakes to only output error
 messages, but on a syntax error, PyFlakes prints out an error message,
 then the *entire* contents of the module that it cannot import, and
 *finally* a line that contains a number of spaces equal to the offset
 into the file of the syntax error (in the case of my real-world file,
 the triple-quote was 3,896 characters into the file, so PyFlake's line 
 of spaces was that long as well).  The offending code is in the
 "pyflakes" command-line program and looks like this:

    print >> sys.stderr, 'could not compile %r:%d:' % (filename, lineno)
    print >> sys.stderr, line
    print >> sys.stderr, " " * (offset-2), "^"

 By removing or commenting out those last two lines, so that PyFlakes 
 only outputs its error message, you will stop flooding the Emacs
 regular-expression engine with data.  It's actually the long line of
 spaces that causes the problem, and it's one regular expression that's
 really sensitive to it (this is from the Emacs 22 flymake.el):

     ;; ant/javac
     (" *\\(\\[javac\\] *\\)?\\(\\([a-zA-Z]:\\)?[^:(\t\n]+\\)\:\\([0-9]+\\)\:[ \t\n]*\\(.+\\)"
      2 4 nil 5))

 For some reason (I'm not an RE engine guru), something about the way
 it's matching spaces takes exponential time when given several thousand
 spaces.  Go figure.  Anyway, I see no point in throwing anything but 
 error messages at Flymake, so I comment out both the printing of the
 module and the spaces from PyFlakes.


The problem was corrected in PyFlakes v0.3.0 according to the release notes:
http://divmod.org/trac/browser/tags/releases/Pyflakes-0.4.0/NEWS.txt
0.3.0 (2009-01-30):
20   - Display more informative SyntaxError messages.
21   - Don't hang flymake with unmatched triple quotes (only report a single
22     line of source for a multiline syntax error).
23   - Recognize __builtins__ as a defined name.
24   - Improve pyflakes support for python versions 2.3-2.5
25   - Support for if-else expressions and with statements.
26   - Warn instead of error on non-existant file paths.
27   - Check for __future__ imports after other statements.
28   - Add reporting for some types of import shadowing.
29   - Improve reporting of unbound locals
The trick to fixing this issue on Ubuntu v8.04? Use pip install pyflakes, which will download the 0.4.0 version.

sudo apt-get remove pyflakes
sudo pip install pyflakes

VMWare Image for CDH3

I made this posting 2 months ago (http://getsatisfaction.com/cloudera/topics/vmware_image_for_cdh3) and apparently Cloudera has yet to release a fix for this VMWare:

In any case, here is the same posting:

VMWare image for CDH3 -- eth0 does not show up as an installed driver. The previous cloudera-training-0.3.3 VmWare image did not have this issue, but cloudera-training-0.3.4
does seem to be missing the appropriate driver. By default I can't access the Internet.

I managed to bypass this issue by activating eth1 by editing /etc/network/interfaces:
sudo bash 
vi /etc/network/interfaces: 

auto eth1 
iface eth1 inet dhcp 
/etc/init.d/networking restart 
Also, I tried to install VMWare Tools to see if the eth0 issue would go away, but after rebooting, the problem still persisted. I certainly didn't see this issue on the previous VmWare image.

In any case, here are instructions to install VMWare Tools:
sudo apt-get install linux-headers-`uname -r` (this is necessary to get the right headers) 
Click on install VMWare Tools 
mount /cdrom 
cd /cdrom 
Copy VMWare tool source code to /tmp and extract the files (the actual filename will depend on your VMWare version [which the VMWare installer would have reported in case of a mismatch]):
cp VMWareTools*.tar.gz /tmp 
cd /tmp 
tar -xzvf VMWareTools*.tar.gz 
cd vmware-tools-distrib/ 
sudo ./vmware-install.pl

Changing the behavior of Emacs' list-buffers mode

I encountered the same issue with Emacs.  The issue is that when you hit Ctrl-X, Ctrl-B to see all of your buffers with the window split in 2, the buffer list shows up on the other side.  It's hugely annoying since you lose the previous buffer screen.

http://stackoverflow.com/questions/1231188/emacs-list-buffers-behavior

In GNU emacs, every time I hit Ctrl-x Ctrl-b to see all of my buffers, the window is split to show the buffer list, or if I have my window already split in 2 (for instance, I will have a shell running in the lower window), the buffer list appears in the other window.

My desired behavior is for the buffer list to appear in my active window so that I can select the buffer I want and continue to working in the same window, rather than having to Ctrl-x Ctrl-o to the other buffer, selecting the buffer (with enter) and editing that buffer in the other window... I've googled for it but it doesn't seem to be a common desire? I wonder if anyone has an elispy (or other) solution?

Simplest solution?

Edit your .emacs:

(global-set-key "\C-x\C-b" 'buffer-menu)

Monday, September 13, 2010

Brother 8480DN Duplex printing

Brother has a table listing of Linux drivers:
http://welcome.solutions.brother.com/bsc/public_s/id/linux/en/download_prn.html

To download the BR8480DN printer driver, the PPD is made available here:
http://pub.brother.com/pub/com/bsc/linux/dlf/BR8480_2_GPL.ppd.gz

gzip -d BR8480_2_GPL.ppd.gz

You can use "Provide PPD file" and use the gzip unzipped PPD file. This will then allow you to setup duplex mode to print!

You should choose DuplexTumble or DuplexNoTumble here:
http://www.infres.enst.fr/~demaille/a2ps/doc-4.12/a2ps_11.html

Dropbox and shared folders

We know that Dropbox uses Amazon S3 for its storage back-ends. For 2GB of storage, Amazon will charge them $.30 (assuming $.15/GB). This obviously doesn't include their other hosting costs but we're using it as a basic measurement.

Once you start using shared folders (especially if your company starts creating shared folders), then pretty quickly your storage capacity gets filled up. You have to look at Dropbox's simple statement here:
https://www.dropbox.com/help/14
When you sign up for a free Dropbox account, we'll give you 2GB of storage space forever. Deleted files and previous versions of files don't count against your quota, but any shared folders you have joined do.
The implications are huge about using shared folders. This statement pretty much means that every person who ends up using the shared folder has to be upgraded to a $10/month plan, which means that Dropbox can comfortably begin to make more than 10x for each user account once they're dependent on using it. And the organization that uses the share folders also must pay for the monthly cost to increase storage quota as well!

Saturday, September 11, 2010

Ubuntu 10.04 and Sprint 3G/4G

The instructions are here:

http://jebus.nu/tech-corner/sprint-u300

You can probe your USB devices and see which one has a CMOTECH, a South Korean company that manufactures eVDO data modems.
# lsusb
Bus 002 Device 008: ID 16d8:6008 CMOTECH Co., Ltd. 
Unlike the link, the product ID was 6008. So I used the following command to add the unit as a serial device:
sudo modprobe usbserial vendor=0x16d8 product=0x6008
The /etc/udev/rules.d/50-u301modem.rules looks like:
ACTION!="add", GOTO="3G_End"

SUBSYSTEMS=="usb", ATTRS{idProduct}=="6008", ATTRS{idVendor}=="16d8", RUN+="/sbi
n/modprobe usbserial vendor=0x16d8 product=0x6008"
LABEL="3G_End" 

Note: for Ubuntu 12.04, you don't need to make these changes. In fact, you shoud remove the rules, sudo service restart udev, and restart Gnome (logout).  Ubuntu 12.04 already seems to have rules for these modems (at least the U600 device), and having this rule appears to conflict with the Mobile Broadband option that gets provided.

Thursday, September 9, 2010

Emacs and Pyflakes using a /tmp directory

One of the issues in how most instructions to use Pyflakes with Emacs is to create a temporary buffer xxx_flymake.py in the file you're editing. This issue can cause problems when trying to view other people's Python files in which you have no write permissions. The typical example code for editing your .emacs file is as follows:

(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)
We can change the code to use the Emacs Lisp make-temp-file:

(defun flymake-create-temp-in-system-tempdir (filename prefix)
  (make-temp-file (or prefix "flymake")))

(when (load "flymake" t)
  (defun flymake-pyflakes-init ()
    (let* ((temp-file (flymake-init-create-temp-buffer-copy
                       'flymake-create-temp-in-system-tempdir))
           (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)

I give credit to http://github.com/purcell/emacs.d/blob/master/site-lisp/flymake-ruby/flymake-ruby.el for showing how it can be done for editing Ruby environments.

Another thing that can be done is to move all Emacs temporary files to the /tmp dir, or your own ~/.emacs.d/tmp directory:
(setq temporary-file-directory "~/.emacs/tmp")

(setq backup-directory-alist
      `((".*" . ,temporary-file-directory)))
(setq auto-save-file-name-transforms
      `((".*" ,temporary-file-directory t)))

Wednesday, September 8, 2010

Ubuntu Tweak installation

sudo add-apt-repository ppa:tualatrix/ppa

sudo apt-get update

sudo apt-get install ubuntu-tweak

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))