Tuesday, October 2, 2018

Scala Basics


What is Scala?

Scala is a general-purpose programming language providing support for functional programming and a strong static type system.



Basic Understanding & Implementation - Scala on Mac

This is my step by step guide to installing Scala macOS Sierra.
Package Manager: Home Brew
Java: Verify that you have java instaled. Couple of ways to verify it:
1 - java -version
openjdk version "1.8.0-adoptopenjdk"
OpenJDK Runtime Environment (build 1.8.0-adoptopenjdk-jenkins_2018_05_19_02_01-b00)
OpenJDK 64-Bit Server VM (build 25.71-b00, mixed mode)
2 - which java
/usr/local/bin/java

Installation


$brew update
Updated Homebrew from bd09f934f to 9141b1509.
Updated 3 taps (homebrew/cask-versions, homebrew/core and homebrew/cask).
==> Updated Formulae
jenkins                   convox                      exploitdb                   git-secret                  grpc                        openconnect                 tcl-tk                      youtube-dl
azure-cli                   dartsim                     git-open                    gnatsd                      mackup                      squashfs                    terraform-docs
==> Deleted Formulae


hyper

$ brew install scala
Warning: scala 2.12.8 is already installed and up-to-date


To reinstall 2.12.8, run `brew reinstall scala`

$ brew reinstall scala
==> Reinstalling scala 
==> Downloading https://downloads.lightbend.com/scala/2.12.8/scala-2.12.8.tgz
Already downloaded: /Users/kinshukdutta/Library/Caches/Homebrew/downloads/4ffc2f15737ba9118ee6050ae3b7f1c997a2ff246a51edea3e4a662c85c4cc13--scala-2.12.8.tgz
==> Caveats
To use with IntelliJ, set the Scala home to:
  /usr/local/opt/scala/idea
==> Summary
🍺  /usr/local/Cellar/scala/2.12.8: 43 files, 20.8MB, built in 5 seconds

$ brew install sbt
==> Downloading https://github.com/sbt/sbt/releases/download/v1.2.8/sbt-1.2.8.tgz
==> Downloading from https://github-production-release-asset-2e65be.s3.amazonaws.com/279553/ae845a00-0be0-11e9-99d2-03a5afa9f1c7?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20190117%2Fus-east-1%2Fs3%2
######################################################################## 100.0%
==> Caveats
You can use $SBT_OPTS to pass additional JVM options to sbt.
Project specific options should be placed in .sbtopts in the root of your project.
Global settings should be placed in /usr/local/etc/sbtopts
==> Summary


🍺  /usr/local/Cellar/sbt/1.2.8: 521 files, 50MB, built in 12 seconds


echo '-J-XX:+CMSClassUnloadingEnabled' >> /usr/local/etc/sbtopts
echo '-J-Xmx4G' >> /usr/local/etc/sbtopts


Scala Plugin for Eclipse

Scala IDE for Eclipse is best installed (and updated) directly from within Eclipse.
This is done by using Help → Install New Software..., add the Add... button in the dialog.
Choose a name for the update site (Scala IDE). Then follow the instructions on screen.

Scala Basics!!


In order to learn the basics of Scala we will be using Scala REPL

The Scala REPL is a An informative tool that logs messages on how our code is interpreted and executed
The scala command will execute a source script by wrapping it in a template and then compiling and executing the resulting program.
In interactive mode, the REPL reads expressions at the prompt, wraps them in an executable template, and then compiles and executes the result.
Previous results are automatically imported into the scope of the current expression as required.
The REPL also provides some command facilities, described below.
An alternative REPL is available in the Ammonite project, which also provides a richer shell evironment.


Values & Variables



Kinshuk Dutta
New York

Monday, July 9, 2018

Implementation - HomeBridge - It's the answer to Impatient HomeKit Enthusiast

Enabling incompatible Accessories to HomeKit using Homebridge

Before we start we must all bear in mind that Apple is known for its robustness of security. Hence a handful of products are HomeKit enabled as it has to go through those rigorous rounds of testing. The process shown in this blog will help you in making a device HomeKit enabled but it might not have that security feature hence you will always be at risk. Again, Homebridge and its accessory plugins are created and maintained by a community of developers and it's not a commercial company hence don't expect it to be up to date and provide support as it would have been in the case of a company. So, yes, lots of risk factors involved. But an impatient HomeKit enthusiast or an apple fanboy won't care.

If you are not the geeky type then refrain from this blog as you will have to get your hands dirty by working on the terminal and changing codes.

Homebridge on Mac

For this exercise, I will be using:
My usual:
MacBook Pro





After you have installed XCode and Node.js you will have to set up a Node.js server. This is your HomeBridge server:


Open terminal and type:
sudo npm install -g --unsafe-perm homebridge
Homebridge will be installed using the NPM package manager. Wait until the process is complete.

Last login: Sat Jul  7 23:47:24 on console
~ kinshukdutta$ sudo npm install -g --unsafe-perm homebridge
Password:
/usr/local/bin/homebridge -> /usr/local/lib/node_modules/homebridge/bin/homebridge

> curve25519-n@1.4.0 install /usr/local/lib/node_modules/homebridge/node_modules/curve25519-n
> node-gyp rebuild

  CXX(target) Release/obj.target/curve/node_curve.o
  SOLINK_MODULE(target) Release/curve.node
clang: warning: libstdc++ is deprecated; move to libc++ with a minimum deployment target of OS X 10.9 [-Wdeprecated]

> ed25519-hap@0.0.5 install /usr/local/lib/node_modules/homebridge/node_modules/ed25519-hap
> node-gyp rebuild

  CC(target) Release/obj.target/ed25519/src/ed25519/keypair.o
  CC(target) Release/obj.target/ed25519/src/ed25519/sign.o
  CC(target) Release/obj.target/ed25519/src/ed25519/open.o
  CC(target) Release/obj.target/ed25519/src/ed25519/crypto_verify_32.o
  CC(target) Release/obj.target/ed25519/src/ed25519/ge_double_scalarmult.o
  CC(target) Release/obj.target/ed25519/src/ed25519/ge_frombytes.o
  CC(target) Release/obj.target/ed25519/src/ed25519/ge_scalarmult_base.o
  CC(target) Release/obj.target/ed25519/src/ed25519/ge_precomp_0.o
  CC(target) Release/obj.target/ed25519/src/ed25519/ge_p2_0.o
  CC(target) Release/obj.target/ed25519/src/ed25519/ge_p2_dbl.o
  CC(target) Release/obj.target/ed25519/src/ed25519/ge_p3_0.o
  CC(target) Release/obj.target/ed25519/src/ed25519/ge_p3_dbl.o
  CC(target) Release/obj.target/ed25519/src/ed25519/ge_p3_to_p2.o
  CC(target) Release/obj.target/ed25519/src/ed25519/ge_p3_to_cached.o
  CC(target) Release/obj.target/ed25519/src/ed25519/ge_p3_tobytes.o
  CC(target) Release/obj.target/ed25519/src/ed25519/ge_madd.o
  CC(target) Release/obj.target/ed25519/src/ed25519/ge_add.o
  CC(target) Release/obj.target/ed25519/src/ed25519/ge_msub.o
  CC(target) Release/obj.target/ed25519/src/ed25519/ge_sub.o
  CC(target) Release/obj.target/ed25519/src/ed25519/ge_p1p1_to_p3.o
  CC(target) Release/obj.target/ed25519/src/ed25519/ge_p1p1_to_p2.o
  CC(target) Release/obj.target/ed25519/src/ed25519/ge_tobytes.o
  CC(target) Release/obj.target/ed25519/src/ed25519/fe_0.o
  CC(target) Release/obj.target/ed25519/src/ed25519/fe_1.o
  CC(target) Release/obj.target/ed25519/src/ed25519/fe_cmov.o
  CC(target) Release/obj.target/ed25519/src/ed25519/fe_copy.o
  CC(target) Release/obj.target/ed25519/src/ed25519/fe_neg.o
  CC(target) Release/obj.target/ed25519/src/ed25519/fe_add.o
  CC(target) Release/obj.target/ed25519/src/ed25519/fe_sub.o
  CC(target) Release/obj.target/ed25519/src/ed25519/fe_mul.o
  CC(target) Release/obj.target/ed25519/src/ed25519/fe_sq.o
  CC(target) Release/obj.target/ed25519/src/ed25519/fe_sq2.o
  CC(target) Release/obj.target/ed25519/src/ed25519/fe_invert.o
  CC(target) Release/obj.target/ed25519/src/ed25519/fe_tobytes.o
  CC(target) Release/obj.target/ed25519/src/ed25519/fe_isnegative.o
  CC(target) Release/obj.target/ed25519/src/ed25519/fe_isnonzero.o
  CC(target) Release/obj.target/ed25519/src/ed25519/fe_frombytes.o
  CC(target) Release/obj.target/ed25519/src/ed25519/fe_pow22523.o
  CC(target) Release/obj.target/ed25519/src/ed25519/sc_reduce.o
  CC(target) Release/obj.target/ed25519/src/ed25519/sc_muladd.o
  CXX(target) Release/obj.target/ed25519/src/ed25519.o
  SOLINK_MODULE(target) Release/ed25519.node
clang: warning: libstdc++ is deprecated; move to libc++ with a minimum deployment target of OS X 10.9 [-Wdeprecated]
/usr/local/lib
└─┬ homebridge@0.4.44 
  ├─┬ chalk@1.1.3 
  │ ├── ansi-styles@2.2.1 
  │ ├── escape-string-regexp@1.0.5 
  │ ├─┬ has-ansi@2.0.0 
  │ │ └── ansi-regex@2.1.1 
  │ ├── strip-ansi@3.0.1 
  │ └── supports-color@2.0.0 
  ├─┬ commander@2.8.1 
  │ └── graceful-readlink@1.0.1 
  ├─┬ hap-nodejs@0.4.47 
  │ ├─┬ bonjour-hap@3.5.1 
  │ │ ├── array-flatten@2.1.1 
  │ │ ├── deep-equal@1.0.1 
  │ │ ├── dns-equal@1.0.0 
  │ │ ├─┬ dns-txt@2.0.2 
  │ │ │ └── buffer-indexof@1.1.1 
  │ │ ├─┬ multicast-dns@6.2.3 
  │ │ │ ├─┬ dns-packet@1.3.1 
  │ │ │ │ └── safe-buffer@5.1.2 
  │ │ │ └── thunky@1.0.2 
  │ │ └── multicast-dns-service-types@1.1.0 
  │ ├── buffer-shims@1.0.0 
  │ ├─┬ curve25519-n@1.4.0 
  │ │ ├── bindings@1.3.0 
  │ │ └── nan@2.10.0 
  │ ├─┬ debug@2.6.9 
  │ │ └── ms@2.0.0 
  │ ├── decimal.js@7.5.1 
  │ ├── ed25519-hap@0.0.5 
  │ ├── fast-srp-hap@1.0.1 
  │ ├── ip@1.1.5 
  │ └─┬ node-persist@0.0.11 
  │   └─┬ mkdirp@0.5.1 
  │     └── minimist@0.0.8 
  ├─┬ node-persist@0.0.8 
  │ ├── mkdirp@0.3.5 
  │ └── q@1.1.2 
  ├── qrcode-terminal@0.11.0 
  └── semver@5.0.3 


Type homebridge into Terminal to launch it.


kinshukdutta$ homebridge



You should see the following message:
[7/9/2018, 9:57:53 AM] config.json (/Users/kinshukdutta/.homebridge/config.json) not found.

[7/9/2018, 9:57:53 AM] No plugins found. See the README for information on installing plugins.

Add Homebridge to HomeKit




Kinshuk Dutta
New York

Scala & Spark for Managing & Analyzing Big Data (Using Machine Learning)

Managing & Analyzing Big Data using Apache Scala & Apache Spark In this blog we will see how to use Scala and Spark to analyze Big D...