Skip to content

Instantly share code, notes, and snippets.

Avatar

Kunal sethi kunals201

View GitHub Profile
@kunals201
kunals201 / wordcount.java
Created Oct 3, 2019
Computes a word count
View wordcount.java
package com.journaldev.sparkdemo;
...imports...
public class WordCounter {
private static void wordCount(String fileName) {
...
}
@kunals201
kunals201 / DestroyProcess.java
Created May 16, 2019
Destroy running Process by taking process id
View DestroyProcess.java
package com.knoldus;
import java.util.Optional;
public class DestroyProcess {
public static void main(String[] args) {
final Optional<ProcessHandle> processHandle = ProcessHandle.of(9767);
if(processHandle.isPresent())
@kunals201
kunals201 / CurrentAllProcess.java
Last active May 16, 2019
Get all the current process and print out id of each
View CurrentAllProcess.java
package com.knoldus;
import java.util.stream.Stream;
public class CurrentAllProcess {
public static void main(String[] args) throws Exception {
final Stream<ProcessHandle> currentProcesses = ProcessHandle.allProcesses();
currentProcesses.filter(ProcessHandle::isAlive).forEach(processHandle ->
@kunals201
kunals201 / ObjectUtilsEx.java
Last active Apr 29, 2019
Remove null pointer by using ObjectUtils
View ObjectUtilsEx.java
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.ObjectUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
public class ObjectUtilsEx {
public static void main(String[] args) {
@kunals201
kunals201 / LambdaEx.java
Created Apr 29, 2019
NullPointerException when any list element is null
View LambdaEx.java
package com.knoldus;
import org.apache.commons.collections4.CollectionUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
public class LambdaEx {
public static void main(String[] args) {
@kunals201
kunals201 / CollectionUtils.java
Last active May 1, 2019
Use case of collectionUtils
View CollectionUtils.java
package com.knoldus;
import org.apache.commons.collections4.CollectionUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
public class LambdaEx {
@kunals201
kunals201 / CollectionsWithoutNullCheck.java
Last active May 1, 2019
Need of apache commons for collections
View CollectionsWithoutNullCheck.java
package com.knoldus;
import java.util.ArrayList;
import java.util.stream.Collectors;
public class LambdaEx {
public static void main(String[] args) {
ArrayList<String> list1 = null;
list1.stream().map(elem -> elem + "Knoldus").collect(Collectors.toList());
@kunals201
kunals201 / Tweet.scala
Last active Aug 21, 2018
tiny types with value classes
View Tweet.scala
case class UserId(id: Int) extends AnyVal
case class Username(name: String) extends AnyVal
case class TweetId(id: Int) extends AnyVal
case class TweetContent(content: String) extends AnyVal
case class User(id: UserId, name: Username)
@kunals201
kunals201 / User.scala
Last active Aug 21, 2018
Tiny types without value class
View User.scala
case class UserId(id: Int)
case class Username(name: String)
case class TweetId(id: Int)
case class TweetContent(content: String)
case class User(id: UserId, name: Username)
@kunals201
kunals201 / Test.scala
Created Aug 21, 2018
Example of Without using value class
View Test.scala
case class User(id: Int, name: String)
case class Tweet(id: Int, content: String)
object Test extends App{
val user = User(1, "Kunal")
val tweet = Tweet(11, "Scala Rocks")
println(s"User ID :- ${user.id}")