Tech Junkie Blog: 2018

Tuesday, June 19, 2018

In this post we are going to install the Putty client for Windows.  Which is the most common way to connect to a Linux instance remotely.

Here are the steps to install Putty:

1.  Go to the URL
2. Click on the "Download" link

3. Click select the 64-bit version

4.  Click "Open" to install if your are using "Chrome"

5.  Click "Next" on the "Welcome" screen
6.  Accept the file path
7.  Eventually you will get to the "Product Features" install everything on the hard drive, then click "Install"

8. Click "Finish"

Monday, June 18, 2018

The indexOf() method searches for the element in the array that matches the passed in value.
In this example we will search for the value 60.50 in the array.  The indexOf() method takes two arguments.  The first argument is the value to search for, the second argument is optional and specifies the index to start the search at.  If the second argument is omitted the search will start at the first element of the array.

        var oilPrices = [70.15, 69.50, 71.23, 74.32, 76.99];

        var searchAtBeginning = oilPrices.indexOf(60.50);

        var searchAtIndex = oilPrices.indexOf(60.50,2);

        console.log("searchAtBeginning: " + searchAtBeginning);
        console.log("searchAtIndex: " + searchAtIndex);

Here is the output:

As you can see the first indexOf() method call returns the index of 1 because that's where 60.50 resides.  It was able to find the element because the second argument was omitted there the search starts at the beginning array.  The second indexOf() method call has the value of 2 as the second argument that tells the method start the search at index 2 in the array.  Since the value 60.50 exists at index 1, the method returns a -1 which means it cannot find the value.

Monday, June 11, 2018

The some() array works similar to the every() method, it also returns true or false when the condition is met.  some() needs to match just one element in the array that meets the condition to return true.  So lets run the same code that we ran for the every() method.  We will test to see if the array is greater than 50 for the first condition, and then we will test to see if the array is greater than 70 for the second condition.  For the every() method the first condition returns true, while the second condition returns false.  Let's see what happens with the some() method.

        var oilPrices = [70.15, 69.50, 71.23, 74.32, 76.99];

        var greaterThanFifty = oilPrices.some(function (value) { return value > 50; });

        var greaterThanSeventy = oilPrices.some(function (value) { return value > 70 });

        console.log("greaterThanFifty: " + greaterThanFifty);
        console.log("greaterThanSeventy: " + greaterThanSeventy);

As you can see both conditions return true because at least one of the element in the array meets the condition.

Monday, June 4, 2018

The every() method is a method that tests a condition on every array element and makes sure that all the elements meets the criteria.  It returns true or false.

The code below test to see if the oil prices array is greater than $50 or greater than $70

        var oilPrices = [70.15, 69.50, 71.23, 74.32, 76.99];

        var greaterThanFifty = oilPrices.every(function (value) { return value > 50; });

        var greaterThanSeventy = oilPrices.every(function (value) { return value > 70 });

        console.log("greaterThanFifty: " + greaterThanFifty);
        console.log("greaterThanSeventy: " + greaterThanSeventy);

As you can see the first condition is true because all of the elements in the array are greater than 50.  However, the second condition returns false because 69.50 is not greater than 70 even though the rest of the elements in the array are greater than 70.

Monday, May 28, 2018

The filter() method returns the elements of the array that satisfies the function that is passed into the method.  If the function returns true the element is added to the filtered array, else it is ignored.

Let's say we only want to buy oil when the prices drops below $72, so we will only return an array element where the prices below $72

        var oilPrices = [70.15, 69.50, 71.23, 74.32, 76.99];

        var lowPrices = oilPrices.filter(function (value) { return value < 72 });


Monday, May 21, 2018

The map() method is similar forEach() method which means that it performs a function, however it returns a new array with the returned values.  In this example we are going to perform the $1 discount of the oil prices using the map() method instead of the forEach() the difference here is that the map() method returns a new array instead of the original array, but the result will be the same.

        var oilPrices = [70.15, 69.50, 71.23, 74.32, 76.99];

        var discounted = (value) { return value -1; });


The code above calls the map() method on the oil prices and returns a discounted value of $1 for each array element

Thursday, May 17, 2018

R is a programming language that is a little different in syntax then your typical mainstream languages like Java or C#. In this post we will go over how to create variables in R.

Let's create some variables about a user:

To create a variable in we use the <- key for example if you want to assign a value to variable firstName, you would write firstName <-  "John" or "John" -> firstName

If you type in the firstName in the console you will "John" as the value

To get the type of the variable you can use the class(firstName)

Monday, May 14, 2018

The forEach() method loops through an array, and performs a function on each element of the array.  The forEach() method can take three arguments, the first argument is a current value that you want to perform an action on.  The second argument acts as the "this" value within the scope of the function.  The third argument is the array itself.  Most of the time only the first argument is passed.  The code below passes in only one argument which is an anonymous function being performed on each element of the array using the forEach() method to calculate the oil prices in the last five days and prints it out in the console.

        var oilPrices = [70.15, 69.50, 71.23, 74.32, 76.99];
        var total = 0;

        oilPrices.forEach(function (value) { total += value });


You should get the total of 362.19 as your total when you add up the last five days of oil prices.

Thursday, May 10, 2018

Now that we R installed in Visual Studio let's install some of the more useful packages that we will use in our R development.  Packages provides you  with the tools to perform tasks, functionalities and datasets for the those features.

To install R devtools package do the following:

In your R project, type the following command into the R Interactive window install.packages("devtools")

A list of installed packages will be installed

Now that we've installed the devtools package we need to run the library command to use them by typing library(devtools) in the R Interactive window

Monday, May 7, 2018

The JavaScript array splice() method allows you to delete and insert array elements in one method
Before we get to the examples let's see how we would use the splice() method on an array first.

The splice method takes 1....n method parameters.  The first parameter specify the position of the array that will be deleted.  The second parameter specify the number of elements to be deleted after the first element's index position, or splice out.  Any subsequent parameters will be the elements that will be added to the array.  If there's only one parameter then all the elements before the first parameter's position will be deleted

For example let say we have the following array

        var numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9,10];

In this example we deleted everything that is before the array index 2 by typing numbers.splice(2).  As you can since we only have 1 parameter passed in the elements after the index 2 is spliced out and the numbers array is changed to have just two elements 1,2.  The splice() method changes the original array.

Wednesday, May 2, 2018

In this post we are going to go over the steps to install R Tools For Visual Studio 2017.  RStudio has a development environment that is bare bones for the free version.  Visual Studio 2017 offers a more robust development environment if you download the R Tools feature.

Here are the steps to install R Tools for Visual Studio:

1. Click on Tools → Get Tools and Features

2.  This will launch the Visual Studio Installer, click on "Modify" on your installed version

Tuesday, May 1, 2018

In CSS you can group your selects into one declarations. For example you want to create a read alert text for your h2 HTML element tag.

You can define each property one at a time like so

        h2{font: bold 25px arial, verdana;}
        h2{color: red;}

When you type in <h2>Alert</h2> you will get this effect

You can achieve the same effect by grouping the selectors into one declaration like the following.

        h2 {
            font: bold 25px arial, verdana;
            color: red;
            background: black;

As you can see it is much cleaner and easier to read.

Monday, April 30, 2018

The Array.concat() method returns a array that is a concatenation of the original array and what what is being passed into the concat() method.  The concat() method can take either values or another array.

For example lets say you have an array of numbers from 1 to 3

var numbers = [1,2,3];

Now let's say you want to concatenate the numbers 4 and 5 into the array.  You would type in the following

numbers.concat(4, 5);

The resulting array would be 1,2,3,4,5

or you can concatenate two arrays together, for example lets say you already declared the numbers array with the values 1,2,3 and you want to concatenate another array call numbers2 with the values 4,5,6 you can call the concat() method like the following

var numbers2 = [4,5,6];

Monday, April 23, 2018

The Array.sort() methods sorts the array in alphabetical order by default, or you can pass in a custom sort function.

So let's say you have an array of names that's our of order that you want to sort.

        var names = ["zack", "jim", "bob", "adam", "jason"];

If we call the names.sort() method we would get resulting array in Alphabetical order

Monday, April 16, 2018

The Array.reverse() method reverses the order of the array elements.  The easiest way to demonstrate this is to have an array with the numbers 1 to 5.  If we call the Array.reverse() method we should get an array of 5 to 1.  The Array.reverse() does not create a new array, it simply rearranges the array into a new order.  Just keep that in mind when you are using this method.

So let's declare our array from 1 to 5

        var numbers = [1, 2, 3, 4, 5];

So if we call the numbers.reverse() method we should get an array of 5 to one in the reverse order

Monday, April 9, 2018

The Array.join() method converts all of the elements of an array into strings and concatenates the elements.  If no delimiter is defined it is separated by a comma.  The most common use for this is to convert an array into a comma separated list of strings.

For example let's say we want to convert an array of zip codes into a comma separated list.

        var zipCodes = [90210, 90211, 90212, 90213, 90214];

If we just call the zipCodes.join() method we will get a string of comma separated list

Thursday, April 5, 2018

Wednesday, April 4, 2018

R is a programming language used by data scientists to present and manipulate data.  In this blog post I will go over the steps you need to do to install R in your Windows machine.

Here are the steps to install R:

1. Type the following URL into the address bar

2. Once you are on the page click on the link that says "Download R for Windows"

Tuesday, April 3, 2018

In CSS you can define styles for HTML elements and apply the styles globally on the page where the HTML element is used.  For example you can define styles for the entire html element or the p element.  Like the following markup

        html {color:blue;}
        p {font-weight:bold;}
        h1 {color:red;}

This is a paragraph

This h1 tag

You can also group your selectors by using commas to define a style for more than one element. Like h2, h3 {color: blue;}

This is h2

This is h3

So far we have define one declaration at a time. But in CSS we can chain together more than one declaration for each element. Let's say we want to make our h4 element a little bit more fancy by combining multiple declarations together.
h4 {font: 12px Ariel; color: green; background: yellow;}

This is the h4 style

Monday, April 2, 2018

JavaScript itself does not have multidimensional arrays, instead you can use an arrays of arrays instead.  Multidimensional arrays are basically arrays that you can reference by rows and columns.  The most obvious real world use is to store rows and columns of a database record.  Imagine if you have a row of the database product from the database from the table "Products".  Instead of storing each value in an individual variable you can store them in an arrays of arrays.

Let's say you have the following database Products table

This is a perfect scenario to use an arrays of arrays in JavaScript.

Here is how you would store the records, let's ignore the column headers and just concentrate on the record rows and columns.

Friday, January 19, 2018

Since an array is a collection of elements of objects, values, etc.  The most common function performed on it is to iterate through each elements of the array.  The most frequent way to do that is with a for loop.

Let's say you have an array with the following:

var numbers = ["one","two","three","four","five"];

The numbers array above contains five string elements, which also has a indexes associated with the it.  There's also a length that is defined with each array that we will use for the for loop we are about to write.  So what do the you length of the numbers array will be?

If we output the array to the browser with the statement console.log(numbers.length) do you think we will get the length to be 5 or 4?

If you guess 5 you are correct because there are five elements in the array.  However, the arrays have zero based indexes therefore the index is always length -1

for(var i = 0; i < numbers.length; i++)

Friday, January 12, 2018

When you define an object as an Array in JavaScript you get the benefits of inheriting some useful methods with it.  Some of the common methods are those that allows you to add and delete elements from an array.  The .push() method adds an element at the end of the array, the unshift() method adds an element at the beginning of the array.  The delete keyword deletes an element at the specified index.

Let say you have an the following array:

var numbers = [3,4];

If you output the array in the browser console you will see that the array has two elements with the number 3 occupying index 0 and the number 4 occupying index 1.

Friday, January 5, 2018

In the previous post we created arrays of different types, in this post we are going to read the values from our arrays.

Let's work with the following arrays
  1. var numbers = [1,2,3,4];
  2. var stringArray = new Array("USA", "Canada","China");
  3. var objectArray = [{firstName: "Jane", lastName:"Johnson", weight:"115lbs"},{firstName: "Jack", lastName:"Johnson", weight:"200lbs"}];
Let's start with getting a value from an array:

To get the second value of an array you would write the following code by using the :