Skip to content

Instantly share code, notes, and snippets.

View SriramKeerthi's full-sized avatar
🐵
Code Monkeying

Sriram Kunjathur SriramKeerthi

🐵
Code Monkeying
View GitHub Profile
@SriramKeerthi
SriramKeerthi / Test.java
Created June 9, 2016 12:00
Typed JSON with Jackson example
package com.caffinc.learning.json;
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.ArrayList;
import java.util.List;
public class Test {
@SriramKeerthi
SriramKeerthi / Load.java
Last active September 27, 2022 09:25
Simple CPU Load Generator in Java
package com.caffinc.grex.core;
/**
* SPDX-License-Identifier: MIT
*
* Generates Load on the CPU by keeping it busy for the given load percentage
* @author Sriram
*/
public class Load {
/**
@SriramKeerthi
SriramKeerthi / WordCountStorm.java
Created January 12, 2016 13:34
Word Count using Storm
import backtype.storm.Config;
import backtype.storm.LocalCluster;
import backtype.storm.spout.SpoutOutputCollector;
import backtype.storm.task.OutputCollector;
import backtype.storm.task.TopologyContext;
import backtype.storm.topology.OutputFieldsDeclarer;
import backtype.storm.topology.TopologyBuilder;
import backtype.storm.topology.base.BaseRichBolt;
import backtype.storm.topology.base.BaseRichSpout;
import backtype.storm.tuple.Fields;
@SriramKeerthi
SriramKeerthi / WordCount.scala
Created January 11, 2016 15:31
Word count using Scala
import org.apache.spark.{SparkConf, SparkContext}
object WordCount extends App {
val conf = new SparkConf().setAppName("WordCount").setMaster("local[*]")
val sc = new SparkContext(conf)
val rdd = sc.textFile(args(0))
val counts = rdd
.flatMap(line => line.split("[ _\\-'\",<>\\.]"))
.filter(_.length > 0)
.map(word => (word.toLowerCase(), 1))
@SriramKeerthi
SriramKeerthi / WordCountMultiThread.java
Last active March 24, 2022 00:08
Counts words in a file using multiple threads
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.*;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
@SriramKeerthi
SriramKeerthi / WordCountSingleThread.java
Created January 3, 2016 10:53
Counts words in a file in a single thread
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.*;
/**
* Reads a file from the command line parameter and counts the number of words in it
@SriramKeerthi
SriramKeerthi / FileLineCount2.java
Created January 3, 2016 05:01
FileLineCount broken up into blocks
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.Iterator;
import java.util.concurrent.atomic.AtomicInteger;
/**
@SriramKeerthi
SriramKeerthi / FileLineCount.java
Created January 2, 2016 15:37
Counts the number of lines in a text file in Java
import java.io.BufferedReader;
import java.io.FileReader;
/**
* Reads a file from the command line parameter and counts the number of lines in it
* @author Sriram
*/
public class FileLineCount
{
@SriramKeerthi
SriramKeerthi / IPUtil.java
Created November 9, 2015 10:54
Fetches the public IP of the machine
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
public class IPUtil
{
/**
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
/**
* Fetches the IP address of the machine from http://caffinc.com/myip
* @author Sriram
*/