Skip to main content

Posts

Add Environment variables and aliases to Bash on Mac OSX

Refrences: 1. http://www.cyberciti.biz/tips/howto-linux-unix-bash-shell-setup-prompt.html 2. http://www.cyberciti.biz/faq/bash-shell-change-the-color-of-my-shell-prompt-under-linux-or-unix/ Add following in ~/.profile (or ~/.bash_profile, or ~/.bashrc, or /etc/profile if you have access): export JAVA_VERSION=1.8 export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_40.jdk/Contents/Home export PATH=$PATH:$JAVA_HOME/bin alias ll='ls -al' # This alias recursively destroys all .DS_Store files in the folder I am currently in alias killDS='find . -name *.DS_Store -type f -delete' # This alias reloads this file alias reload_profile='. ~/.profile' # Mac get stuck very often and are extremely slow and unstable on shutdowns. This forces a shutdown. alias poweroff='sudo /sbin/shutdown -h now' # To ignore space changes while doing git diff alias gitdf='git diff --ignore-space-change' # Show Git branch in prompt parse_git_branch() { git bra...

mongoDB

MongoDB A cross-platform open-source document-oriented NoSQL database with an Enterprise level distribution that includes additional security and management features. MongoDB is supported and steered by the company MongoDB . What do we mean by NoSQL? The NoSQL database category loosely incorporates all databases which do not have a rigid schema and are not queryable via a structured query language. They are normally designed specifically to scale easily to support very large datasets. What is a document based database? Instead of storing information as a table with a series of records or rows, MongoDB stores data as searchable documents. A document is analogous to the object model in object orientated programming languages. How does MongoDB represent documents? MongoDB uses JSON to represent its documents. JSON is a simple key-value pair textual serialization of an object, for example, a bunch of grapes could be represented as the following JSON string: { Name: "Bunch of...

Spark Tutorial and Cheatsheet

Main resources: Scala Cheat Sheet Reactive Cheat Sheet Spark Cheat sheet Spark Quick start Spark programming guide Spark Streaming : processing real-time data streams Spark SQL and DataFrames : support for structured data and relational queries MLlib : built-in machine learning library GraphX : Spark’s new API for graph processing Scala programming examples: Define a object with main function -- Helloworld. object HelloWorld { def main(args: Array[String]) { println("Hello, world!") } } Execute main function: scala> HelloWorld.main(null) Hello, world! Creating RDDs Parallelized Collections: val data = Array(1, 2, 3, 4, 5) val distData = sc.parallelize(data) External Datasets: val distFile = sc.textFile("data.txt") Above command returns the content of the file: scala> distFile.collect() res16: Array[String] = Array(1,2,3, 4,5,6) SparkContext.wholeTextFiles can return (filename, content). val distFile = sc.wholeTextFiles("/tmp/t...

Making Spray based ReST API publicly / remotely accessible

Recently I developed a demo Spray based ReST API and ran it on Windows. While I was able to access it locally using http://localhost:port/service link, but remotely I was not. I made following two changes to fix the issue: 1. In your application's application.conf file make hostname as 0.0.0.0 - 127.0.0.1 or localhost is foe listening only on the loopback interface. - 0.0.0.0 for listening on all available network interfaces. This works in Java 7 and 8 fine. In Java 6, only IPv4 address works. My application.conf looks like: akka { loglevel = DEBUG event-handlers = ["akka.event.slf4j.Slf4jEventHandler"] } spray.can.server { request-timeout = 10s } service { host = 0.0.0.0 port = 8090 } 2. Open 8090 (or whatever you want to use) port in Windows Firewall: http://windows.microsoft.com/en-gb/windows/open-port-windows-firewall#1TC=windows-7

SecurityException with Bouncy Castle

I am using BouncyCastle library to encrypt the data transfer with Kakfa. While my program run fine from IntelliJ, but when I package a fat JAR and run, it throws following exception: java.lang.SecurityException: JCE cannot authenticate the provider BC at javax.crypto.Cipher.getInstance(Cipher.java:657) at javax.crypto.Cipher.getInstance(Cipher.java:596) at com.xyz.abc.fusioncell.utils.CryptoService$class.decrypt(CryptoService.scala:63) at com.xyz.abc.fusioncell.Boot$.decrypt(Boot.scala:13) at com.xyz.abc.fusioncell.conf.Config$$anonfun$userId$1.apply(Config.scala:28) at com.xyz.abc.fusioncell.conf.Config$$anonfun$userId$1.apply(Config.scala:28) at scala.util.Try$.apply(Try.scala:192) at com.xyz.abc.fusioncell.conf.Config$class.userId(Config.scala:28) at com.xyz.abc.fusioncell.Boot$.userId$lzycompute(Boot.scala:13) at com.xyz.abc.fusioncell.Boot$.userId(Boot.scala:13) at com.xyz.abc.fusioncell.Boot$.main(Boot.scala:24) at com.xyz.abc.fu...

Akka: Printing list of actors

To print the list of actors that are running in the actor system, you can add following scheduler that will print actor path every 10 seconds: import akka.actor.{Actor, ActorIdentity, ActorLogging, ActorRef, Cancellable, Props} class TestActor extends Actor with ActorLogging { private var scheduler: Cancellable = _ @scala.throws[Exception](classOf[Exception]) override def preStart(): Unit = { import scala.concurrent.duration._ scheduler = context.system.scheduler.schedule( initialDelay = 0 seconds, interval = 10 seconds, receiver = self, message = ActorIdentity("", Some(self)) ) } @scala.throws[IOException](classOf[IOException]) override def postStop() = { scheduler.cancel } override def receive = { case ActorIdentity(_, Some(ref)) => log.info(ref.path.toString) } }