Monday, January 28, 2013

Effective Javascript

I've started reading my second "Effective" software book.

The first one I read before was Effective C++, by Scott Meyers,and the one I'm reading now is Effective JavaScript, by David Herman.

I like these books because:
  • The books are light, literally!  I hate heavy books.  Heavy books look good in libraries, but are pretty crappy everywhere else.
  • The reading is light, figuratively. Each of the points more or less stands alone and is only a few pages long.  This means you can read a couple of pages and still get something out of it.  
  • For me, the best part of these books is when I find a specific point that clearly points out that I've been doing something wrong for the last few years.  In these aha moments, I can 'feel' my future code improving.  

Saturday, January 26, 2013

Usability vs complexity (notepad vs vi)

I like to use apps that are easy to use.  One of the things that we all love about www.google.com is  that it's dirt simple.

However, I also like to use applications whose user interfaces are complex.  For example, instead of the relatively simple text editor notepad, I often favor a program call vi.  For those who don't know what vi is, it's a text editor, that I can hardly begin to describe.  Here are some seemingly ridiculous features that probably sound like a foreign language to the uninitiated:

  • There is a text insertion mode and a navigation mode.  If you press the character 'd' and then 'w', in one mode, you will see the characters 'dw' on the screen. In the other mode, you will delete a word.
  • There are things called folds.  If you create them, or have them created based on the text, you can quickly hide and show blocks of texts.
  • There is something called marks, which you can set.  You can them jump from one mark to another with just a few keystrokes (instead of pressing down or page down a hundred times).   
  • You can take advantage of other tools and do lots of other magic like text replacement with regular expressions.  

In order to use complex tools like vi, you need to read, practice and spend time looking up reference sheets.  So why go through the pain?  It's a trade-off.  Using a tool like vi enables me to do powerful things that save me time.

So, what is the right level of complexity versus usability? I guess it depends on the application.

Well, then again, maybe usability doesn't matter all that much.

Fantasy Football and Math

I knew that sports was a good way to introduce young students to math concepts.

At the most basic level, you need to be able to count to keep score.  From there, you need to calculate differences in order to see by how much you're winning or losing.  At the next level, you use multiplication and division for things like win/loss percentages and batting averages.  For most of history, these basic mathematical operations were enough for anyone to be sports literate.

Last year I went to Las Vegas for March Madness and the math while not complex, was fast and furious.  And now this year, as I am joining a fantasy football keeper league, here comes the next level of challenging math.  Picking players requires some serious thought in managing probabilities and hedging risks, not to mention salary inflation (brought on by team expansion) and game theory.  

The list of things I want to work on, build and learn is pretty full, but if it ever empties, it'd be a great learning experience to build some applications in the fantasy football space.

Here are some apis that may be of interest if time allows ...

Saturday, January 19, 2013

Simple way to run javascript code

I was browsing StackOverflow and I came across an unanswered question about a Javascript function.  Before answering the question, I wanted to run the function to make sure I completely understood what was going on.

On Ubuntu

To run a simple Javascript function, in Ubuntu, I followed the advice in this earthviaradio blog post and installed node.js. On Ubuntu, here is what I did.
  • Installed node.js.
  • sudo apt-get install nodejs
  • Wrote a test function. (I saved the file as test.js).
  • var sys=require("util");
    sys.puts("This is a test javascript file.  Hello world!");
  • Ran the function.  ( You should see the output in the console terminal ).
    node test.js

On Mac

If you already have homebrew, you can install node.js with this command.
brew install node
Then, you can run it in the same way as I noted above.

I've heard about nodejs a while ago, but I never spent any time to learn what it was.  This looks like a pretty cool resource to learn about nodejs:
http://www.hongkiat.com/blog/node-js-server-side-javascript/

Wednesday, January 16, 2013

Insertion Sort with a C++ vector and iterators

In order to practice my programming skills, I thought I'd write some basic sorting algorithms from scratch. Below is my code to do an insertion sort of a vector with iterators in C++.
This took me longer to write than I am willing to admit, indicating that I should continue practicing and writing these algorithms.
void insertion_sort( std::vector & v ) 
{
// leave if there is nothing to sort
if ( v.empty() )
{
return;
}

// go left to right along the vector
std::vector::iterator l2r_it;
l2r_it = v.begin();
l2r_it++;
for ( ; l2r_it != v.end(); l2r_it++ )
{
// go right to left along the vector
std::vector::iterator r2l_it = l2r_it ;
while ( r2l_it != v.begin() &&
*r2l_it < *(r2l_it - 1) )
{
int tmp = *r2l_it;
*r2l_it = *(r2l_it - 1);
*(r2l_it - 1 ) = tmp;

r2l_it--;
}
}
}

Sunday, January 13, 2013

Next computer

I'd really like a new computer.  Below, I listed some contenders.
The System 76 is the biggest, heaviest, and cheapest, and I like Ubuntu OS the best.

System 76 Lemur 4 Laptop
  • Preloaded with Ubuntu
  • $849 (with the RAM and Hard drive specs outlined below)
  • 4.5 lbs
  • 14.1 inch display
  • 8 GB DDR3 SDRAM 1600 Mhz, 2 x 4 GB
  • 120 GB SSD Hard drive
  • OS X Mountain Lion 
  • $1499 (with Specs below)
  • 4.5 lbs
  • 13.3 inch display
  • 8 GB DDR3 SDRAM 1600 Mhz, 2 x 4 GB
  • 128 GB SSD Hard Drive
  • OS X Mountain Lion
  • $1299 (with Specs below)
  • 2.96 lbs
  • 13.3 inch display
  • 8 GB DDR3 SDRAM 1600Mhz
  • 128 GB SSD Hard Drive
Dell XPS 13 Laptop, Developer Edition
  • Preloaded with Ubuntu
  • Has "developer profiles", like one for Ruby development or Android development, that makes installing all of the components needed to develop a specific type of application seamless.
  • $1549
  • 2.99 lbs
  • 13.3 inch display
  • 8 GB DDR3L RAM
  • 256 GB SSD Hard drive

Gnome 3

For my home computer, I have been using the Ubuntu operating system with the Unity interface for the last year.  I chose the Unity interface, because it was the default one chosen for me.  About a week ago, I was having some issues with remote desktops not opening nicely in Ubuntu+Unity so I started using the Gnome 3 interface.  Here are some notes on window management with Gnome and Ubuntu.

Workspaces
For those who don't know, "Workspaces" are a way to group windows.  I typically put all social (time-wasting) programs into one workspace, things I'm actively working with in another window, and some reference material in another workspace.  Here is a screen shot of my desktop showing active windows in the current workspace and a few other workspaces shown on the right.

You can see your workspaces by:
  1. Move your mouse to the top left hand corner of the screen.
  2. Press Alt+F1.
  3. Press the Windows button.
You can switch workspaces, by pressing Alt+Ctrl+Up or Down direction.

You can switch between windows that are in any workspace by pressing Alt+Tab. I'm not sure if there is a way to make alt+tab to work for only windows in the current workspace.

Window size management
To maximize your window:
  1. Drag the window to the top of the screen.  If you hold it there for a moment, and then release, it just works.
  2. Press Windows+Up direction.
To change the window to half of the screen:
  1. Drag the window to the left or right of the screen.
  2. Press Windows+Left or Right direction.
Other Resources
http://www.filiwiese.com/installing-gnome-on-ubuntu-12-04-precise-pangolin/