# Coding Musings

#### Finding an Exit from a Maze using undirected graphs.

We can think of a maze as a rectangular grid of cells with paths between adjacent cells. If we want to find if there is a path from a given cell to a given exit from the maze, where the exit is represented by a cell, you can represent the maze as an undirected graph.

The nodes of the graph are cells of the maze, and two nodes are connected an undirected edge if they are adjacent and there is no wall between them. Therefore we can surmise we just need to see if a path, series of edges connecting the nodes, to determine if the two nodes are connected.

See code below.

#### Spark – Streaming Data, Capturing and Querying

Today we will look at how to capture streaming data and perform some simple queries as the data is streamed. We will use the regular expressions library and the PySpak library.  The streaming data comes from a weather station that transmits different weather at different intervals.  We will need to find the correct data out of the stream and output the results.

Let’s get started.

#### Spark – SQLContext

Today we will look at the SQLContext object from the PySpark library and how you can use it to connect to a local database.  In the example below we will:
Connect to a local PostgreSQL database and read the contents into a dataframe.
Run some simple SQL queries
And join two data frames together

Let’s get started.

#### Hadoop Spark – Word Count

One of the first things to do in most programming languages is create a “Hello World!” program.  The equivalent in Spark is to create a program that will read the contents of a file and count the number of occurrences of each word.

Below I will show a basic example, so let’s start counting.

The great thing about the Panda’s library for Python is how easily it can manipulate data sources.  We will look at one of the first things you will want to do, read a .csv file.

In this posting I will again be using WebGL.  However as opposed to just drawing a triangle and doing a gradient fill, which you can see here.  Gradient Triangle.

The code listed below will use WebGL to draw a cube and make it rotate.

#### WebGL Rotating a Cube

WebGL is really a fascinating topic to me. Being able to utilize the power of a local machine’s GPU via the web browser is a very novel concept.

If one was to ask back in 1996 would you be able to render Open GL code in a web browser via  GPU, even the most tech savvy may have replied, “Open GL? GPU? what are those things, you speak about?”

#### Train an NGram Model

Will take the ngrams, reading and writing from the SQLite database and train the model utilizing Katz-Backoff methodology on the likelihood of the next word.

See code below

#### File Handler for RDS Formatted Files

Using a list, load RDS formatted files into standard data frame. Allows for grouping multiple files into one data frame for processing.

See code below

#### SQLite Interface Class for R

I wrote an interface class to help with working with the SQLite database.

Methods include, selectQuery, updateQuery, readTable, writeTable

see code below