Saturday, November 27, 2010

Turning off numlock on a Kinesis...

Hit Keypad + "7":

Or follow the long Kinesis instructions:

http://www.kinesis-ergo.com/tech_support/trouble.htm

With a Kinesis contoured keyboard, press the keypad button to turn on the embedded keypad. To change the state of Num lock, press the number row "7" key (Num Lk is printed on the front face). Normally the keyboard will beep twice and the keyboard light next to the "1" will illuminate when Num lock is turned on. The keyboard will beep once and the light will go out when Num lock is turned off.

Monday, November 22, 2010

Getting a Brother MFC-8480 to scan in Ubuntu 10.04

This Brother multi-function printer/scanner/fax actually has support for scanning documents in Ubuntu. The directions, which are somewhat scattered, are posted here:

http://welcome.solutions.brother.com/bsc/public_s/id/linux/en/download_scn.html

1. This Brother printer is classified as the brscan3 model, so we can download it from here:
http://welcome.solutions.brother.com/bsc/public_s/id/linux/en/download_scn.html#brscan3

2. sudo dpkg -i /tmp/brscan3-0.2.11-2.amd64.deb

3. sudo brsaneconfig3 -a name=MyScanner model=BR8480TDN IP=10.0.1.11

4. sudo apt-get install sane xsane

5. Click on Graphics->Simple Scan. You can start scanning by clicking the "Start Scan" button.

To verify your drivers are installed properly:

dpkg -l | grep
sudo brsaneconfig3 -q

Wednesday, November 17, 2010

jQuery extend() removes undefined values...

If you pass in an undefined value into the data for the $.ajax call(), this undefined field will be removed during the $.ajax() call when extending the variables:

var params = { width:1680, height:1050, picture: undefined };

$.ajax({url: 'www.myurl.com', data: params});


This will invoke the $.ajax function, which then invokes the extend() function:
   ajax: function( origSettings ) {
        var s = jQuery.extend(true, {}, jQuery.ajaxSettings, origSettings);

The extend() function tries to remove out the undefined/null values:
jQuery.extend = jQuery.fn.extend = function() {
       // Only deal with non-null/undefined values                                                                                                                                                                                          
        if ( (options = arguments[ i ]) != null ) {
            // Extend the base object                                                                                                                                                                                                        
          
                // Don't bring in undefined values                                                                                                                                                                                           
                } else if ( copy !== undefined ) {
                    target[ name ] = copy;

Python 2.x and Unicode

Suppose you tried the following:
>>> a = u"Hey\u2019t"
>>> b = a.encode('utf-8')
>>> b.encode('utf-8')
Traceback (most recent call last):
  File "", line 1, in 
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 3: ordinal not in range(128)
The encode('utf-8') takes a Python unicode object and converts it into a Python ASCII string object. When you try to encode a Python string object into UTF-8, Python throws an error above.

The best slide talk that discusses these issues can be found here: http://farmdev.com/talks/unicode/

Python 2.x has these problems in general because it has created separate typed objects, u' for unicode, and ' for string (ASCII), both derived from the basestring type. Python 3.0 solves this issue by unifying the string object.

Wednesday, November 10, 2010

nth-child vs. eq CSS selectors

The eq() and nth-child() CSS selectors are not the same..

http://api.jquery.com/nth-child-selector/

The :nth-child(n) pseudo-class is easily confused with :eq(n), even though the two can result in dramatically different matched elements. With :nth-child(n), all children are counted, regardless of what they are, and the specified element is selected only if it matches the selector attached to the pseudo-class. With :eq(n) only the selector attached to the pseudo-class is counted, not limited to children of any other element, and the (n+1)th one (n is 0-based) is selected.

Or how someone else explains it....
http://forum.jquery.com/topic/eq-0-vs-nth-child-1-with-find-inconsitency

:eq() selects an element based on it's index in the array of selected elements.
:nth-child() selects all elements that are the nth child of their parent.

Sunday, November 7, 2010

WymEditor strips out <embed> tags

WymEditor seems to strip out <embed>/<object> tags so does not seem to have the ability to embed YouTube clips. The way to fix it is to patch the latest WymEditor release, or download the GitHub files. Here are two blog posts that talk about the issue:

http://simonwoodside.com/weblog/2009/2/8/how_to_make_wym_editor/
http://meridimus.com/post/167515648/wymeditor-flash

I took the diff of these changes and patched the 0.5rc2 release accordingly:

1757d1756
<       "param",
2124a2124,2150
>     "param":
>     {
>       "attributes":
>       [
>         "type",
>         "value",
>   "name"
>       ],
>       "required":[
>       "name"
>       ],
>       "inside":"object"
>     },
>  "embed":
>     {
>       "attributes":
>       [
>         "width",
>         "height",
>         "allowfullscreen",
>         "allowscriptaccess",
>         "wmode",
>         "type",
>         "src"
>       ],
>    "inside":"object"
>     },
2166,2178d2191
<     "param":
<     {
<       "attributes":
<       {
<         "0":"type",
<         "valuetype":/^(data|ref|object)$/,
<         "1":"valuetype",
<         "2":"value"
<       },
<       "required":[
<       "name"
<       ]
<     },
3381c3394
<     "object", "ol", "optgroup", "option", "p", "param", "pre", "q",
---
>     "ol", "optgroup", "option", "p", "pre", "q",
3384c3397
<     "thead", "title", "tr", "tt", "ul", "var", "extends"];
---
>     "thead", "title", "tr", "tt", "ul", "var", "extends", "object"];
3387c3400
<     this.inline_tags = ["br", "hr", "img", "input"];
---
>     this.inline_tags = ["br", "hr", "img", "input", "param", "embed"];

This issue has been filed as a ticket on the trac.wymeditor.org. If you want to create an account, you have to visit http://trac.wymeditor/trac/register. The link that's made available on the web site doesn't quite work. You can download the patched file here:

http://trac.wymeditor.org/trac/ticket/221

Update: There is already a plug-in that adds these tags into the code:

https://github.com/wymeditor/wymeditor/blob/master/src/wymeditor/plugins/embed/jquery.wymeditor.embed.js

Fixing brightness controls on the T510 laptop

Ubuntu v10.04 (Lucid) with the Thinkpad T510 Nvidia Quadro 3100M has issues with trying to adjust the brightness controls. Apparently the issue is related to X11. To the issue, you need to edit /etc/x11/xorg.conf, and restart X:

http://www.nvnews.net/vbulletin/showthread.php?p=2204839#post2204839
Section "Screen"
 Identifier "Default Screen"
 DefaultDepth 24
EndSection

Section "Module"
 Load "glx"
EndSection

Section "Device"
 Identifier "Default Device"
 Driver "nvidia"
 Option "NoLogo" "True"
 Option  "RegistryDWords" "EnableBrightnessControl=1"
EndSection


The brightness controls will then work with this extra tweak!

Saturday, November 6, 2010

Updating entries from a SQL join

Suppose I want to update onl the entries from an INNER JOIN. Well apparently in SQL I can do the following:

UPDATE TABLE1 AS A LEFT JOIN TABLE2 AS B ON A.F1=B.F1 SET A.X = 1, B.Y = 2

According to the MySQL docs, the "table_references" can refer to any type of SELECT syntax we want to use. We can set any value referring to the two entries by giving each of the tables being joined an alias (in the example above, we refer to TABLE1 as 'A' and TABLE as 'B')

http://dev.mysql.com/doc/refman/5.0/en/update.html

UPDATE [LOW_PRIORITY] [IGNORE] table_references
    SET col_name1={expr1|DEFAULT} [, col_name2={expr2|DEFAULT}] ...
    [WHERE where_condition]