If someone come to visit me here, please let them know that I moved to a new place at WordPress.com. Please forward any letters/packages you may receive to my new home: https://thammegowda.wordpress.com/
Thanks and Good bye.
-
TG
mkdir my-project cd my-project mkdir -p src/main/java src/main/scala src/main/resources/ \ src/test/java src/test/scala/ src/test/resource emacs/edit pom.xml # and copy paste the below content to
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>test-project</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Test Project</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<scala.version>2.11.8</scala.version>
<exec.mainClass>JavaMain</exec.mainClass>
</properties>
<dependencies>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>${scala.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>3.2.1</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<executions>
<execution>
<id>scala-compile-first</id>
<phase>process-resources</phase>
<goals>
<goal>add-source</goal>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>scala-test-compile</id>
<phase>process-test-resources</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Let's put a sample Scala codeemacs src/main/scala/ScalaMain.scala # paste the below conents
object ScalaMain{
def hello(){
println("Hello there from scala")
}
}
Lets call scala code from java :emacs src/main/java/JavaMain.java # paste the below contents
public class JavaMain {
public static void main(String[] args){
System.out.println("Hello From Java");
ScalaMain.hello();
}
}
Lets Compile and runmvn compile exec:java # the class is already specified in pom.xml as exec.mainClass [INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building Test Project 1.0-SNAPSHOT [INFO] ------------------------------------------------------------------------ ......... [INFO] [INFO] --- exec-maven-plugin:1.4.0:java (default-cli) @ test-project --- Hello From Java Hello there from scala [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 2.239s [INFO] Finished at: Mon Apr 04 00:42:25 PDT 2016 [INFO] Final Memory: 14M/216M [INFO] ------------------------------------------------------------------------
import org.apache.spark.Partition;
import org.apache.spark.SparkConf;
import org.apache.spark.SparkContext;
import org.apache.spark.TaskContext;
import org.apache.spark.api.java.JavaPairRDD;
import org.apache.spark.api.java.JavaRDD;
import org.apache.spark.api.java.JavaSparkContext;
import org.apache.spark.mllib.linalg.distributed.CoordinateMatrix;
import org.apache.spark.mllib.linalg.distributed.MatrixEntry;
import org.apache.spark.rdd.RDD;
import scala.collection.AbstractIterator;
import scala.collection.Iterator;
import scala.collection.mutable.ArrayBuffer;
import scala.reflect.ClassManifestFactory$;
/**
* This class illustrates multiplication table on spark!
* @author Thamme Gowda N
*
*/
public class Main {
/**
* This RDD has numbers in it.
* This RDD can be used for illustrating math operations on Spark
*/
public static class SequenceRDD extends RDD<Long>{
private long start;
private long end;
private Partition[] partitions;
public SequenceRDD(SparkContext _sc, long start, long end) {
super(_sc, new ArrayBuffer<> (),
ClassManifestFactory$.MODULE$.fromClass(Long.class));
this.start = start;
this.end = end;
this.partitions = new Partition[]{
() -> 0 //just one part at index 0
};
}
@Override
public Iterator<Long> compute(Partition split, TaskContext ctx) {
//we have only one part, so this is it
return new SequenceIterator(start, end);
}
@Override
public Partition[] getPartitions() {
return partitions;
}
}
/**
* This iterator yields numbers so we can build an RDD on it
*/
private static class SequenceIterator
extends AbstractIterator<Long>
implements java.util.Iterator<Long> {
private long nextStart;
private long end;
/**
* Number generator for [start, end]
* @param start the start
* @param end the end, inclusive
*/
public SequenceIterator(long start, long end) {
this.nextStart = start;
this.end = end;
assert end >= start : "Invalid Args";
}
@Override
public boolean hasNext(){
return nextStart <= end;
}
@Override
public Long next() {
return nextStart++;
}
}
public static void main(String[] args) {
long n = 1_000;
String outpath = "multiplication-matrix";
long st = System.currentTimeMillis();
SparkConf conf = new SparkConf()
.setAppName("Large Matrix")
.setMaster("local[2]");
JavaSparkContext ctx = new JavaSparkContext(conf);
JavaRDD<Long> rdd = new SequenceRDD(ctx.sc(), 0, n)
.toJavaRDD()
.cache();
JavaPairRDD<Long, Long> pairs = rdd.cartesian(rdd);
JavaRDD<MatrixEntry> entries = pairs.map(tup ->
new MatrixEntry(tup._1(), tup._2(), tup._1() * tup._2()));
CoordinateMatrix matrix = new CoordinateMatrix(entries.rdd());
matrix.toIndexedRowMatrix()
.rows()
.saveAsTextFile(outpath);
System.out.printf("n=%d\t outpath=%s\nTime taken : %dms\n", n,
outpath, System.currentTimeMillis() - st);
ctx.stop();
}
}
int n = 2500;
int[] arr = new int[n];
System.out.println("Start");
long st = System.currentTimeMillis();
for (int i = 0; < n; i++) {
for (int j = 0; j < n; j++) {
for (int k = 0; k < n; k++) {
arr[k]++;
}
}
}
System.out.printf("%dms\nDone!", System.currentTimeMillis() - st);
Start
1827ms
Done!
int n = 2500;
int[] arr = new int[n];
System.out.println("Start");
long st = System.currentTimeMillis();
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
for (int k = 0; k < n; k++) {
for (int l = 0; l < n; l++) {
arr[l]++;
}
}
}
}
System.out.printf("%dms\nDone!", System.currentTimeMillis() - st);
Start
2863936ms
Done!
A lengthy day with 20 hours of daylightIf I draw a circle centered at Bangalore International Airport with the radius of 40miles, the area inside the circle covers everything including the place I born, schools and colleges I went to, offices I worked for, relatives and friends I have visited. I seriously wanted to travel to a different part of the world for the sake of experiencing the change in my mid-20s. The someday that I hoped in the past is here with me in the present.
Memorable is my first international flight
From a colony in the east
To a colony in the west
Via the capital of the kingdom
History in hand is ridding-off the boredom
When I was in college, I enjoyed tinkering with machines. It started when I tried whole night to make my computer dual bootable instead of playing video games. My enthusiasm reached a new height when I figured out free Ubuntu CD to break into any computer with a CD drive; later I figured out to create bootable USB stick. I enjoyed computer repairs, when my school teachers, my techie as well as non-techie friends asked me to fix their machines. I still get some requests, sadly I can't say them - "No, I don't repair your computer".
Smartphones are the other fun part of the story. I started my journey with Nokia series-40 handset back in 2008. Those days phones had supported an SDCard of capacity upto 2 giga bytes size. I loved listening to the romantic songs of south Indian language movies. Okay, 2 GB was not sufficient to load my favorite MP3 files along with my favorite videos accompanied with thousands of images which we used to call as wallpapers. With the help of a multimedia converter, I figured out optimal size-to-quality ratio for audio clips and video clips by adjusting the bit-rates, which let me load nearly 900+ songs in 2 GB Card. ( Believe me, the batch conversion took whole night and the tiny music player responded like a dead beast after seeing those many songs). Then came Symbian OS handsets (N Series, E Series) which allowed me to reply a message on IM, browse web on a browser and listen to music at the same time - that's why I needed a multi task capable phone. That was not enough, there was a next step, where I could 'hack' (the very first meaning for this word I encountered in my life was close to jailbreak/root in today's ios/android terminology) the OS to provide full privileges. That enabled me to do some crazy things like install DOSBOX emulator on my Nokia E52, using which I was able to operate windows 95 and Turbo C++.
I am sorry for your death, Symbian, I moved onto something I love even today - the Nokia N900. It had mobile debian linux OS called Maemo, and the best part was there was no need to hack/root as the OS offered it out of the box and it was legal. This is where I developed interest on Free and Open Source Softwares. Gone are those days, I had a mini laptop in my pocket! This story will become a new story if I start to give just a glimpse of what all I did on my N900, so lets move on to the next one. I joined the Android ride when it was at version 3.1. It was only a week after my purchase, my Galaxy Tab 10.1 was bricked while I was trying out something, but later I learned to root, flash, backup, recover the device without taking to repair shop. I don't remember me taking any device to service man for software repair even if device was within the warranty period. A few months later, I was virtually running ubuntu and fedora on my tablet as android was too kiddish for someone who lived with N900. Later I bought a Nexus device and an iPAD, which are way powerful, modern and capable than my previous gadgets (excluding N900, it will never be old for me ;-) ) but I don't remember having much fun with these compared to the previous gadgets.I think I found an answer for that question of my young friend, it is - 'I am busy with my work.' I have told this phrase to so many people at times, but this time it had a different connotation. This is the proof - we spend most of our time at work and it impacts our habits. On the other hand, I found my coolness in learning and solving harder problems at work so job is not the real culprit, it is change of interests.
A: do you use a spell checker?
B: Yes, I do.
A: why?
B: Because I don't like to sound ridiculous. I care for my language.
A: Shakespeare didn't use one, but I believe he still cared for language..., look at him, he invented so many new words. Can you imagine what would have happened if he had used a stringent spell checker like yours?
B: That's not my business, please spare my neurons.
A: It is your business, you said you care for your language.
B: Oh! did I say that?
A: Yes, you did.
B: Alright, I don't have the liberty of Shakespeare to use whatever the word I feel like using. For instance, I can't use "cutted" "putted", even tough I feel they're more appropriate and less confusing. You know, there are confusing rules.
A: Okay, I got it. World doesn't encourage creativity and abnormality.
![]() |
| Graph: Speed and Elevation |
![]() |
| #cycling Stats |