Tuesday, December 22, 2009

My Review of Roku HD Player

I wouldn't have let Roku post this to my blog except I do approve of this message.

Originally submitted at Roku

The best-selling HD Player (as known as Netflix Player by Roku) plays High Definition video and connects to surround sound audio.

Only needs Youtube and Hulu to be perfect

By Danyel from Bay Ridge on 12/22/2009


5out of 5

Pros: Great value, Built in Wi-Fi, Easy to use, Compact, Video selection, Easily movable, Easy to set up, High quality picture, Reliability

Best Uses: Bedroom, Living room, Traveling, Friends House

Describe Yourself: Power User, Technophile, Early adopter

Move it from living room to bedroom to finish watching in bed.


Wednesday, July 22, 2009

Python File Type Plugin for Vim - Part 1

* Made a correction below. Using the ~/.vim/ftplugin directory for a file type plugin causes the plugin to be reloaded repeatedly causing any autocommands to be appended for BufWrite actions. This causes multiple executions of every autocommand every time you save the file. A better location is the ~/.vim/plugin directory. Where the plugin is loaded once at startup. I have changed the location below. *

I wanted to add some IDE style conveniences to my preferred editor, console Vim. Rather than reinventing the wheel I decided to search the Internet and start with what was already out there. I found a bunch of very useful scripts and snippets. In part 1 I am documenting some of what I found here by publishing a snippet that I have only made minor changes to to make it useful for my needs.

This script needs to be put in a file named python.vim and saved in ~/.vim/plugin. If the directory does not exist it needs to be created. The scripts create the pyflakes, pylinks, and pychecker commands that can be used at the vim command prompt, ':'. The pylint, pyflakes, pychecker packages will have to be installed as prerequisites for using these commands.

All three commands act on the current buffer's file name. Running one of the commands at the vim command prompt will open a Vim quickfix window which will seem familiar to anyone who has used a graphical IDE for development.

You can press c to close the quickfix window when it has the focus. You can double click with a mouse under X or press enter to go to the error or warning associated with the current quickfix line. This will take you to the line referred to by that message. You will have to restart vim if you have already loaded a python file during the currently loaded Vim session.

Here is the code:

function! PythonGrep(tool)
  set lazyredraw
  " Close any existing cwindows.
  let l:grepformat_save = &grepformat
  let l:grepprogram_save = &grepprg
  set grepformat&vim
  set grepformat&vim
  let &grepformat = '%f:%l:%m'
  if a:tool == "pylint"
    let &grepprg = 'pylint --output-format=parseable --reports=n --indent-string="        "'
  elseif a:tool == "pychecker"
    let &grepprg = 'pychecker --quiet -q'
  elseif a:tool == "pyflakes"
     let &grepprg = 'pyflakes'
    echohl WarningMsg
    echo "PythonGrep Error: Unknown Tool"
    echohl none
  if &readonly == 0 | update | endif
  silent! grep! %
  let &grepformat = l:grepformat_save
  let &grepprg = l:grepprogram_save
  let l:mod_total = 0
  let l:win_count = 1
  " Determine correct window height
  windo let l:win_count = l:win_count + 1
  if l:win_count <= 2 | let l:win_count = 4 | endif
  windo let l:mod_total = l:mod_total + winheight(0)/l:win_count |
  \ execute 'resize +'.l:mod_total
  " Open cwindow
  execute 'belowright cw '.l:mod_total
  nnoremap   c :cclose
  set nolazyredraw

command! Pyflakes call PythonGrep('pyflakes')
command! PyFlakes call PythonGrep('pyflakes')
command! Pychecker call PythonGrep('pychecker')
command! PyChecker call PythonGrep('pychecker')
command! Pylint call PythonGrep('pylint')
command! PyLint call PythonGrep('pylint')

" These three are successively more informative and aggressive in their
" warnings with pyflakes as the least noisy. Only uncomment one.
"autocmd BufWrite *.{py} :Pyflakes
autocmd BufWrite *.{py} :Pychecker
"autocmd BufWrite *.{py} :Pylint

In Vim a single double quote, ", is considered the beginning of a comment for the rest of the line.

The benefit of having the autocmd run one of the Python lint programs every time you save the file is that you can never get too far from sane working code as any errors and warnings pop up. This, in your face, style of development can keep you from pulling your hair out over something as simple as a semicolon or comma typo and can also warn you about more complex problems and proper coding style.

More to follow. I will try to combine the output of the three commands as their output doesn't seem to overlap for the most part. And the noisier programs (pychecker and pylint) don't appear to give the same advice when it comes to warnings. pylinker is by far the noisiest of them all but all it's warnings are configurable.

Warning: If you are using tabs for indenting you will have to modify the pylint parameter '--indent-string='. Set it to the empty string for tabs, or the actual number of spaces used for indenting. In my code above I have it set for 8 spaces which is project specific.

Thursday, April 2, 2009

Step One: Insert Foot in Mouth

This is a follow up to my Your Fancy Language is Burdensome and Dangerous post.

Python and Ruby don't have the APL array/vector/matrix syntax built in to the core language. But a little nudge from someone made me do the little bit of research I should have done before I wrote that post. And I rediscovered that I did not originate the idea that these languages need array/matrix math syntax thought.

There is a gem for Ruby called NArray and an egg for Python called Numpy that not only add array syntax but also coherent coercion rules and the ability to apply functions across arrays without calling map. I'm glad I found it because they are easy as pie to use and do exactly what I wanted and a heck of a lot more.

Check out this Python example:

from numpy import *
a = array([1,2,3])
b = array([4,5,6])
print a+b #equals array([5,7,9])
print (a+b)/4
print (a+b)%6


As you can see Numpy also replicates the integer type bug/feature which is very C like but is being dropped in Python 3000 in favor of coercing integers to float on divide. You can typecast the divisor to float to get floating point division and float results.

Tuesday, March 24, 2009

Vim auto completion

I responded to a comment on the Daily Vim about auto completion. I decided to post it here as well as the comment ended up being kind of long. The comment by Casey asks if there is a way to turn off omni auto completion for perl as it goes through the entire POD collection evey time. I provide several solutions. Read the original article for a quicj intro to auto completion in insert mode in Vim.

The original article points out that there is built in auto completion in Vim. All you have to do is use it is type Ctrl-x Ctrl-o in insert mode and vim will try to complete what you have started typing or pop up a list of all completions if the cursor is not immediately preceded by anything.

Original comment follows:

Try this command to change the auto completion to the simpler syntax highlighting hints as the auto completer.

:setlocal omnifunc=syntaxcomplete#Complete

If that is what you always want for Perl add this to your .vimrc after all your other auto commands.

autocmd Filetype perl setlocal omnifunc=syntaxcomplete#Complete

If you want syntax completion rather than omni completion for all file types use * for the file type. If you want to fail over to syntax completion for file types that don't have omni completion put this in your .vimrc after your other auto commands.

if has("autocmd") && exists("+omnifunc")
autocmd Filetype *
\ if &omnifunc == "" |
\ setlocal omnifunc=syntaxcomplete#Complete |
\ endif

You can also do something a little more complex which just disable the perlPOD part of the perl filetype omni complete.

Try this command:

let g:omni_syntax_group_exclude_perl = 'perlPOD'

generically it's:

let g:omni_syntax_group_exclude_{filetype} = 'comma,separated,list'

And you can get the complete list of syntax groups while in a file with the filetype in question with this command:

:syntax list

Then just add that command to your .vimrc to make it permanent.

Check out this help topic for more info:

:h ft-syntax-omni


And for the complete low down on the idiosyncrasies of each filetype check out:

:h compl-omni-filetypes

And here's another tip I picked up Ctrl-o : in insert mode will allow you to run a command and then return to insert mode. Neatly avoiding the Esc : ... i or a syndrome.

*Updated again

FYI Pressing Ctrl-o in insert mode puts you in normal mode for one command. You are not limited to using : to get to the ex command line. You can use p to put or y to yank etc.

*Further updates

For those times when you just want to save keystrokes or avoid typos:

Ctrl-P completes from previous words in document
Ctrl-N completes from following words in document
Ctrl-X Ctrl-F completes file names
0 Ctrl-D removes all indent for the current line

Tuesday, March 3, 2009

I think bio-engineering and habitat engineering are smarter

I posted this in the comments section of a science post about the current thinking that the only solution to climate change is climate engineering. I think that is a back idea. Not just because it encourages the fantasy of terraforming other planets and wild irrational space travel. But also because it's a wrong headed idea based on a premise that we don't have the technology to survive and thrive in any environment. It is only in our best interests to do so. My TEDTalks.com fueled diatribe follows.

Geo-engineering is a bad idea and a waste of resources that should be going to bio-engineering and habitat engineering research, development, and manufacturing. The threats to our existence on our planet are much farther ranging than climate change. Climate change is a natural process. Ice ages are where the glaciers that created the great lakes and that have recently melted away in places came from. We've got a swing by the gravitational force of the black hole at the center of our galaxy through direct alignment with our Sun. Which should be an interesting demonstration of just how powerful the magnetic and gravitational field of a black hole at that distance is when focused through the gravitational field as powerful as our Suns. We've got the possiblities of several disasters that are happen on a cyclical basis around that same time. The two super volcanoes. One right here in or I should say that is Yellowstone Park. The occasional reversal, polarity flipping, and 1000 year disappearances of the earths magnetic field that coincidently keeps the Sun from burning off our atmosphere. There is also the Atlantic shelf that should wipe the Americas clear of anything not bedrock if it shifts significantly. And that is not even mentioning the many unmonitored solar objects which could really ruin our day or the fact that the moon is slowly floating away and will have a massive effect on our climate.

My point is that if we are planning to survive beyond our infancy. Yes I say infancy because it is infantile to chase after the idea of money as a life goal. And yes I say idea because that is all money or any possession is. I say let us come up with a plan that lays out exactly what kind of technology we would need to survive all of these events. No, not survive, but thrive in the face of all of these events and more. The "rich" are holding back the future because they incorrectly be!ieve it is unprofitable to them to have everyone off the grid and living free. If you could satisfy all of your energy needs from the Sun via locally and communally generated windpower, water power, sea power, thermoelectric, magnetosphere, solar collector, or what have you. And you dealt with others as equals. Everyone being responsible for themselves and the world as a whole without arbitrary governance by ignorance encouraged by profiteers. And you were educated about the realities of our ability to harness even the simplest of technologies to solve all of our problems like drought, famine, hunger, transportation, shelter, communication, and survival. You would no longer be a consumer. In fact for the cost of a car (~$20,000) you could buy all the equipment needed to setup a microfactory and be a manufacturer. Check out http://www.fabathome.com/ and http://www.ted.com/index.php/talks/neil_gershenfeld_on_fab_labs.html Or check out the virtues of collaboration over institutions http://www.ted.com/index.php/talks/clay_shirky_on_institutions_versus_co... And check out 6 ways mushroms can save the world http://www.ted.com/index.php/talks/paul_stamets_on_6_ways_mushrooms_can_... Or open source architecture http://www.ted.com/index.php/talks/cameron_sinclair_on_open_source_archi... We need to collaborate on using the technology that is already available to build the technology needed to thrive during extreme adversity. We must evolve beyond the womb of the Earth. To do so we don't need to travel to other planets and terraform them to match our requirements. What we need is to evolve by raising the bar and saying we aren't dependent on a very fragile environment to survive. We have the technology we need the will.

Wednesday, February 18, 2009

Your Fancy Language is Burdensome and Dangerous

I found this quote about the PL/I language in Wikipedia to be very poignant today. The quote's sentiment and the PL/I language are from the 1960's.
PL/I is considered by some to be a turning point where it was found that large languages with a lot of complexity that allow programmers to do almost anything (such as coerce types with no semantic relationship to one another) are burdensome and dangerous rather than "more powerful."

It echoes my low opinion of most of the toy languages that seem to be escapees from a Compiler 101 college course masquerading as the cure for the inability of some people to program. I find it to be very relevant to the object oriented mass hysteria and popularity of the latest scripting languages of the moment.

My opinion of C++ with the STL and templates and generic algorithms and iterators and iostreams is lower than my original opinion of C++ before it became standardized. What problem does all that junk solve. More to the point, what problem did object oriented programming ever solve beyond speed to delivery?

Object oriented programming is a morass and a tar pit. It's the all promise and no delivery. It eats up 90% of your programming time forcing you to write witty little programming ditties when you should be writing elegant, concise solutions that aren't 90% object oriented overhead.

Object oriented code hides not only the method invocation but also confuses the issue as to which method is actually called. Multiple inheritance in C++ and other languages demonstrated that the only part of multiple inheritance worth saving in other new object oriented implementations was the interface definition which is basically a template which is basically a macro. It saves you the onerous task of cutting and pasting. In C it's called a macro and it's frowned upon because it obfuscates what the final code does and looks like.

In summary. First write code quickly using only 10% of your programming time. Second scratch head and guesstimate what your code actually does and what are it's unintended consequences. Third hope there aren't any bugs that make your invisible untraceable code do something you didn't intend and use more resources then are necessary to do it.

I'm not saying I don't appreciate Python, Ruby, Perl, C++, Java, and the like. I'm just saying it's not that hard to write the little bit of code it takes to implement most software projects. Especially since the main benefit of most new languages is their extensive built in libraries. Not that you couldn't do the same thing in C by including the proper headers and linking in the proper libraries.

To be brutally honest I think in assembler so even C seems a bit like unnecessary overhead and a bunch of macros hiding the actual code.

I've been reading up on a couple of APL like programming languages J and K but after reading some of the original code for the original J implementation all I see it a bunch of nested for loops creating everything on the stack and avoiding calls to the C standard library to allocate memory.

Now I like APL and I hope to write my own version of it one day because it solves a real programming problem through it's expressiveness. The problem it solves is how to communicate complex and simple vector and matrix operations programmatically to a computer without having to jam a for loop into your equation. The analogy would be the poor man's version tacked on to most of the recent programming languages with list comprehensions and regular expressions. Which are not the same thing.

There are some nice examples of K and J at Wikipedia. I'm not recommending checking out APL as anything other than an educational exercise. I could kick myself for not learning it sooner as it shows how a well thought out programming language was written way back in time that blows the doors off all the fancy flavor of the year languages which waste our time by forcing us programmers to learn an unending stream of new syntax with exceptions that can't even express programming logic as simply and concisely as the A language, APL(A Programming Language) could more than half a century before.

Saturday, January 17, 2009

How to Mount an Old CDROM Disk on Mac OS X

I had a little trouble with a really old PCPlus DVD on my Mac OS X Mac Book Pro. I wanted to try to install some old Windows 95/98 compilers and software using Wine so I could do some Wine compatible Windows development on the cheap. The old PCPlus DVD had a complete copy of Borland C++ Builder and Delphi and an old copy of IE4 and IE5 among other oldies that are hard to find without massive trojan infestations on the net these days. These ancient versions are often the perfect solution to the problem of finding software that works on Wine and doesn't have an onerous disk space and .net requirement.

The problem is I can't see all the files on the DVD. I've seen this problem before and known that it has something to do with the Joliet File System extension. Luckily there is a quick fix. A quick check of the man page for mount and then mount_cd9660 shows that the -r and -j options to mount_cd9660 allow the mounting of ISO 9660 file systems while ignoring the Rock Ridge and Joliet specific extensions.

umount /dev/disk1
mkdir ~/DISK_LABEL
/sbin/mount_cd9660 -r -j /dev/disk1 ~/DISK_LABEL

And voila! All the files are there and all the files are mapped to uppercase. No sudo is required with this method.

Friday, January 2, 2009

The Story of Stuff

This is a must see. It connects all the dots in the global economy. I saw this video over a year ago on Terra Nova. It is now an approachable interactive evolving educational website.