Pages

Friday, January 31, 2014

Rolled Car on I-215

A car rolled on I-215, just outside of our office
Someone is having a rough day.
Later after traffic has started to pile up

Friday, January 24, 2014

Lego: Lord of the Rings - 100% Completed

Lego: Lord of the Rings - 100% completion
Tonight we finally 100% completed the Lego: Lord of the Rings game.  This means absolutely nothing to anyone else, other than to me and the love of my life (also my best friend).  We spent almost 37 hours together on local co-op, over the last two months, collecting everything the game had to offer.  We were then honored with a bonus end cut-scene (which you can watch online, without the actual work).  Now we need to find another similar co-op game to play together.





PLUG - Regular Expressions

PLUG - 1/21/2014 - David Oswald - "Regular Expressions" 
Provo Linux Users Group's (PLUG) David Oswald presents on Regular Expressions, for the January 21, 2014 meeting.  The saved YouTube video presentation is 55 minutes.  The examples are in Perl, but the concepts are universal.  Covers rxrx "RegEx Doctor", backtracking and NFA concepts.

"What is backtracking? How do character classes work? What is the "Little Engine that Could(n't)"?"






Notes


Definitions:
  • Literal Characters: abcd... ABC... 123...
  • Operators: m// (match), s/// (substitute), =~ or !~ (bind)
  • Meta-characters: \ | ( ) [ { ^ $ * + ? .
  • Meta symbols: \b \D \t \3 etc...
Example:
$string = "hello world";
say "Match" if $string =~ m/hello/;

Syntactic Shortcuts:
$_ = "hello world";
say "match" if /hello/;

DFA / NFA / Hybrid Engines - (Deterministic Finite Automata) DFAs and (Non-deterministic Finite Automata) NFAs have exactly the same capabilities and limitations. The only difference is notation convenience.
  • DFA: simpler, text-directed match, no backtracking, more limited, awk/egrep
  • NFA: regex-directed match, backtracking, more flexible semantics, grep/less/sed/more/Perl/PHP/Python
Focus for this presentation: Non-Deterministic Finite Automata (NFA) Engines

Two big NFA rules:
  1. The match that begins earliest wins.
  2. The standard quantifiers are greedy.
rxrx - Excellent RegEx debugging tool ("RegEx Doctor") :
  • rxrx - command-line REPL and wrapper for Regexp::Debugger
Quick rxrx overview:
Install:
 cpan Regexp::Debugger

Usage:
 rxrx
 perl -MRegexp::Debugger -E 'Regexp::Debugger::rxrx(@ARGV)'

To set the regex:
 /[SOMETHING]/

To set the string:
 '[SOMETHING]'

To start match engine: 'm'

To quit: 'q'

Commands:
      / : Enter a pattern
      ' : Enter a new literal string
      " : Enter a new double-quoted string
      m : Match current string against current pattern
 q or x : quit debugger and exit
      h : help

Match Commands:
       - : back step
 [enter] : forward step
       c : proceed visually quickly to the end

Backtracking - When partial match fails, the engine backtracks to try an alternative path.  Where the greatest performance hit comes from.

Example of large backtracking out of control:
# fails in 218 steps
/(a*)*[^Bb]$/
'aaaaaab'

Backtracking can be put under control by using "possessive quantifiers": (*+, ++, ?+, {n,m}+)
# fails in 79 steps
/(a*)*+[^Bb]$/

Possessive quantifiers - change the "greedy" quantifiers to "lazy" quantifiers that attempt to match the minimal amount.  Greedy quantifiers attempt to match the greatest left most match.  Lazy quantifiers attempt to match the least left most match.
/.*foo/   # Greedy ; backtrack backwards.
/.*?foo/  # Lazy; backtrack forward.

More NFA rules:
  1. Matches occur as far left as possible.
  2. Alternation has left-to-right precedence.
  3. Alternative matches if every item listed in the alternative matches sequentially.
  4. Backtracking occurs to try higher-pecking-order assertions.
  5. Quantifiers must be satisfied within their permissible range.
  6. Each atom matches according to its designated semantics.
Shorter segments are often easier:
if( /Brian/ && /John/ ) { ... }
# vs
if( /Brian.*John|John.*Brian/ ) { ... }

Progressive matching - starting where the previous pattern starts off

Extended Bracketed Character Classes - Character classes can now have set semantics (intersections, unions, subtraction, symmetric difference, complement)

When to use RegExes:

RegExes are for matching patters, not for things that have a parser, like HTML and JSON.  Should also not be used for Email Addresses.

"Regexes optimal for small HTML parsing problems, pessimal for large ones" -- Tom Christiansesn

Appropriate Alternatives:

  • Complex grammars - use parsing classes
  • Fixed-width fields - use unpack, substr
  • Comma Separated Values - use CSV libraries
  • Uncomplicated, predictable data - Regular Expressions!


What to Watch on Netflix

What to Watch on Netflix
Ever not sure what to watch on Netflix?  Found this awesome flowchart that will help solve this for you.  Pretty clever.


Netflix Change Account - Konami Code

Samsung Smart TV
We recently reactivated our Netflix account only to run into this error when reloading our account on our Samsung Smart TV:

"We're having trouble playing these titles for you right now. Please try again later or select a different title"


After a bit of research I found a suggestion to deactivate and reactivate the device, from within the Netflix application.  This is the same procedure you would use if you needed to change which Netflix account, the application uses.  At first I thought it was a joke, as it uses an old Nintendo gaming cheat code (Konami Code), but it turned out to be legit:

"While logged into the old account and with the app showing the list of movies, hit the following sequence of buttons on the TV remote: up, up, down, down, left, right, left, right, up, up, up, up."

After following this sequence, we were prompted to deactivate the device.  We then logged back into Netflix and were prompted to reenter our account information.  This time it worked.  Not sure why it was broken in the first place, but glad we found a workaround.

Later, I found another method of deactivating the device, from within the online Netflix account.  I have not had a chance to try this, as our TV's Netflix App is back to functioning, but if it happens again, we will be sure to try this first.

Netflix

Wednesday, January 1, 2014

365 Photo Project

Happy New Year 2014

As part of my New Year's resolution, I am going to do the:


The purpose of the 365 Day Photo Challenge is to "document a year of your life by taking a photo a day."