Friday, May 27, 2016

What is the difference between factorial and lfactorial in R programming?

Factorial computes the factorial of a number. Given a number n it computes n! (n factorial). You can follow this after launching the R Gui. 5! is same as 5x4x3x2x1
---------------
> factorial(5)
[1] 120
---------------
factorial in R programming is also applicable to non-integers.
------
> factorial(5.5)
[1] 287.8853
-------------
How does R programming calculates factorial. It is calculated in the most efficient manner using the Gamma function.
factorial(x)=gamma(x+1)

In implementation to calculate factorial R calculates the gamma
factorial(5)=gamma(5+1)
------
> gamma(5+1)
[1] 120  - This is same as factorial(5)
----
What about lfactorial in R programming?

The definition of lfactorial (http://www.stata.com/manuals13/m-5factorial.pdf) is ;
lfactorial(n) is log(factorial(n))
-----
> lfactorial(5)
[1] 4.787492
> log(factorial(5))
[1] 4.787492
------------
Another interesting tip is you can use factorial function presenting it with a list like factorial(c(5,4,3)) and not a number. It would then compute the factorial for each of the numbers. For example:
----
> factorial(c(5,4,3))
[1] 120  24   6
> factorial(c(5,4.3,2))
[1] 120.00000  38.07798   2.00000
> lfactorial(c(5,4,3))
[1] 4.787492 3.178054 1.791759
----------

Wednesday, May 25, 2016

What is new in Microsoft Edge Windows Build 14342 for developers?

Recently updated the insider's version to 14342 from 14295.

Swipe Navigation is new in Microsoft Edge
Swipe anywhere on the web page left to right or right to left to navigate.

New Extensions in 14342
  • AdBlock
  • AdBlockPlus
  • Pinterest
  • Save to Pocket
Click Ellipsis button and Click Extensions


You need to get extensions from Windows Store


--Install from Windows Store
https://developer.microsoft.com/en-us/microsoft-edge/extensions/


I already had the Microsoft Translator on my previous version but I could not load it. Looks like I need to get the extension again.



In versions earlier to this you could do the following:

Pin/unpin tab. Right click tab to pin the tab. This is quite useful although browser displays some of regularly used pages when you click the + New tab.



You could pin a number of interesting tabs as shown.

Right click the pinned tab and pick Unpin to unpin it. Unpinning windows logo site.




Drag and drop folders to reorder in Favorites Bar.
Of course you can sort the Favorites.



View Source & Inspect Element contextual menu items

Click ellipsis at extreme right end of browser and choose F12 Developer Tools, the first time. Now if you right click on the page you can access View Source and Inspect Element. Of course you can hide it from other users.


The Context menu then shows the View Source and Inspect Element items. If you hide it  you just get Select and Print when the you right click on the web page.

Paste and Go

You could copy a hyperlink from anywhere (for example typed into Notepad or copied from a web page) and then in a new search box right click to get the context menu and pick,  Paste and go to navigate to that page.

These are great features but one of the problems that has not gone away is that the browser hangs when changing tabs. Sometimes you need to get the task manager to get rid of it.

Tuesday, May 24, 2016

How do you get the node.js project templates in Visual Studio 2015?

In a recent post I tried to install Node.js tools that is supposed to help create node.js project types in Visual Studio Community 2015. After installing, I realized that I could not access the node.js templates in Visual Studio. I noted however that the installer version was NTVS 1.1.1 VS2015.msi.

As an after thought I found an easier route to get the node.js support for Visual Studio 2015 Community. This post describes the steps.

After launching Visual Studio 2015 Community ( I have the Update 2, version 14.0.25123.00 Update 2) you can access Extensions and Updates menu item as shown.

NodeJsTools_07.png

Click on the menu item. The Extension and Updates window appears as shown. You need to search for node.js in Visual Studio Gallery. You will find both 1.1 and 1.2 versions.


NodeJSToolsPlug_inVS2015.png

Click Download button for version 2.

The related msi file gets downloaded. The version is


NodeJsTools1point2.png

You may double click the downloaded file to install the plug-in. But first take care of the Apache license.


NodeJsTools_001.png

The extension gets updated as the program installs.


NodeJsTools_001_2.jpg

Once the extension is installed, when you create a New Project... in Visual Studio 2015 Community you should be able to see all the node.js templates as shown in the next image.


NodeJsTools_05.jpg

Monday, May 23, 2016

How can you program IOT controllers using JavaScript?

Arduino boards can be programmed using Arduino software and Intel IOT boards can be programmed using Intel XDK IOT. Using JavaScript to program controllers would be very useful as most browsers are HTMl5 compliant. The Johnny-Five Robotics and IOT program is an interesting option.

Johnny-Five is the JavaScript Robotics & IOT platform released by the Bocoup group. Johnny-Five is maintained by a growing number of talented developers.

What is Bocoup?
Bocoup  is a group that championed the cause of Open tools and Work Flow. They really seems to have people with very varied and diverse talents to tackle web, data, and visualization.

How does Johnny-Five handle the Hello World (or Blink for that matter)?
It looks like 1-2-3 really.

1. Install Node.js(Prefer 4.2.1 LTS)
2. Setup your board
3. Run: npm install johnny-five

What else is needed?

You also need to run the Firmata protocol for the controller board to communicate with the computer.
Interestingly Johnny-Five can handle over 30 different arduino compatible boards from the likes of Raspberry, Intel, Arduino, Sparkfun and many more.

This is very impressive indeed as each of these boards are handled by their vendors like Arduino, Intel and others.

How about non-arduino boards?

There are platform specific IO Plugins (for example, Galileo-IO plugin) .These plugins can speak the language of the platform as they implement Firmata compatible interfaces.

You will be hearing more about Johnny-Five in my blogs, here and here, keep reading....

Thursday, May 19, 2016

How do you connect an Arduino 101 to your computer to check it out?

In this post I discuss a bit about Arduino 101 and describe how different is it from the Arduino UNO. It would be helpful if you would review some previous details here and here.

First of all Arduino 101 has the same kind of peripherals as the Arduino UNO. UNO had an ATmega328 which has been replaced by Intel's Curie(TM). The board has two cores running at 32 MHZ, a x86 (Quark) and an ARC (Argonaut RISC Core). In addition to having low-energy consumption, Arduino has on-board Bluetooth Low Energy and 6-axis accelerometer/gyroscope capability.


These are steps you need to take for checking it out:

Step 1:
Buy the board and it is not very expensive. It is small and looks very much like the Arduino UNO


Lots of places to buy from, http://store-usa.arduino.cc/. I bought mine from Amazon.com as they bring it to my door.

Step 2:
You need to get the Arduino software Arduino IDE 1.6.7.later to program this board.

Review this post to get the download link and some installation information:

http://hodentekhelp.blogspot.com/2016/05/is-there-arduino-program-to-use-with.html



3. After installing Arduino IDE as in 2. above, you should install the Intel Curie Boards using Arduino Boards Manager.

This is after launching the Arduino IDE


Go to the Board Manager. Many different boards work with software and you will be using Arduino 101 which is not present in the default installation of Arduino 1.6.8. That is why you require this step.


Click on the Board Manager... to open the next window. Scroll down to see the Intel boards. Choose the one displaying Arduino 101. Click on the Install button. It begins to download. Quite a big file and can be slow.


Halfway of the installation you will get this Windows Security message. Click install.


You do not get any other message. Click Close on the Board Manager screen. Now in the Board manager screen you should see the board at the very bottom of the drop-down.



Attach the Arduino 101 board using the USB connector as shown. The green light at bottom left shows that the board is powered and ready.


Now you make sure that the Arduino 101 is chosen in the board.

From File choose the Blink example as shown. This Arduino Program (also known as a sketch) will make a LED on the board to blink on and off.

When you choose this the following Sketch will appear in the Arduino IDE as shown (review the title of the next window).


Form the menu Sketch choose Verify and Compile. If there are no errors it should compile.

Now click on Sketch | Upload. The program now goes to the board and get executed. After a slight delay, you will see the LED blinking as shown in the video.


video


Saturday, May 14, 2016

How do you fix this argument label error in the SWIFT program?

While trying to compile and run the following (see link at the bottom of post) program using SwiftFor Windows,
---
func sayHello(personName: String) -> String {
        let greeting = "Hello, " + personName + "!"
        return greeting
    }

print(sayHello("Jay"))

--------
The SwiftForWindows compiler spit out this error:

SwiftError_00

The compiler did indicate the location and the missing label.  The change was made in the print statement by providing the missing label (personName)

The program was modified as shown:
-------------------
func sayHello(personName: String) -> String {
        let greeting = "Hello, " + personName + "!"
        return greeting
    }

print(sayHello(personName:"Jay"))

---
With this the compiler produced no errors.


SwiftError_01

Now after hiting the Run button, the program produced the following response:


SwiftError_02
This sample was taken from SWIFT ver2.2 documentation:

https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Functions.html#//apple_ref/doc/uid/TP40014097-CH10-ID158Is the error due to differences in the SWIFT compiler version?

Thursday, May 12, 2016

How do you compile and run SWIFT programs on Windows 10?

Presently it is possible to compile and run programs written in SWIFT language on Windows 10. You need to download the program as described in this post.

Programs written in SWIFT has the extension .swift. You can use any text editor and here is a simple program written using Notepad and saved to your hard drive. Note that it has to be in the following directory, C:\SwiftForWindows\Swift

//--Function definition
func sayHello(personName: String) -> String {
        let greeting = "Hello, " + personName + "!"
        return greeting
    }
//Function Call
print(sayHello(personName:"Jay"))
//--

Once you download run the Straightforwards.msi (please see the post at the top) file by double clicking it. There may be warnings from the computer not to run it, but ignore and install it.

This leaves a shortcut on your desktop.

When you click on this shortcut the Swift For Windows window opens as shown.


Swift_02

It is simple to use. Select the file and then hit Compile after choosing your platform. A command-line window opens which you can close if there are no compilation errors.

Swift_03

Close the window and have a look at the Logs. Then hit Run. That's it. Again the comand-line window opens displaying the results of your program.

Swift_04

In summary:
1. Create the Swift program file on a text editor and save it with the extension .swift to a specific directory.
2. Choose the platform you are using
Swift_05

3. Hit Run

That's it.