Skip to content

Instantly share code, notes, and snippets.

View seenimohamed's full-sized avatar
🎯
Focusing

Seeni Mohamed seenimohamed

🎯
Focusing
View GitHub Profile
JavaRDD<String> uniqueRDD = SparkUtils.getInstance().getSparkContext()
.parallelize(Arrays.asList(Preprocessor.getInstance().getVocabulary()));
Map<Long, String> vocabMap = uniqueRDD.zipWithIndex().mapToPair(f -> f.swap()).collectAsMap();
JavaPairRDD<Long, Integer> dataPair = tfidf.select("tf").toJavaRDD().flatMapToPair( r -> {
SparseVector vec = r.getAs(0);
List<Tuple2<Long, Integer>> results = new ArrayList<>();
for(int i : vec.indices()) {
results.add(new Tuple2<Long, Integer>((long)i, (int) vec.apply(i)));
public static void main(String[] args) {
int i = 10;
while(--i > 0) {
System.out.println(i);
i = i%4;
}
while(i>0) {
System.out.println(i);
i--;
@seenimohamed
seenimohamed / install_java_ubuntu.txt
Created January 3, 2018 09:40
Links that are useful while development
Installing java in ubuntu
Commands :
sudo apt-get update
sudo apt-get install default-jre
sudo apt-get install default-jdk
https://www.digitalocean.com/community/tutorials/how-to-install-java-with-apt-get-on-ubuntu-16-04
@seenimohamed
seenimohamed / lscommand.txt
Created January 3, 2018 09:46
List of important options in ls command
ls <options>
-l -> detailed view
S -> sort in decending order
r -> reverse
ls -lS -> decending order
ls -lSr -> ascending order
@seenimohamed
seenimohamed / java_commands.txt
Created January 4, 2018 04:52
Java command line commands
//to compile a java class
javac
//to include jars in classpath
java -cp
//to run jar
java -jar jarfile.jar
//to give args
@seenimohamed
seenimohamed / java8_groupbyValue.java
Last active June 18, 2019 10:17
GroupBy functionalities
private String getPredictedModule(List<Result> result) {
Collector<Result, ?, Map<String, Double>> summarizeByModules =
Collectors.groupingBy(Result::getModule, Collectors.summingDouble(Result::getConfidence));
Map<String, Double> finalMap = new LinkedHashMap<>();
result.stream().collect(summarizeByModules)
.entrySet().stream().sorted(Map.Entry.<String, Double>comparingByValue()
.reversed()).forEachOrdered(e -> finalMap.put(e.getKey(), e.getValue()));
return finalMap.keySet().stream().findFirst().get();
}
@seenimohamed
seenimohamed / GetHighestValueFromMap.java
Created January 24, 2018 13:56
get the highest value from map in java8
//to get key for single max value from map
Integer max=mapGroup.entrySet().stream().max(Map.Entry.comparingByValue()).get().getKey();
//to get keys for for getting all equivalent maximums
private List<Integer> testStreamMap(Map<Integer, Long> mapGroup) {
if(mapGroup.isEmpty())
return Collections.emptyList();
long max = mapGroup.values().stream().max(Comparator.naturalOrder()).get();
return mapGroup.entrySet().stream()
.filter(e -> e.getValue() == max)
public static CSVRecord convertToCSVRecord(String query, char delimiter) {
try {
Reader in = new StringReader(query);
CSVParser parser = CSVFormat.newFormat(delimiter).parse(in);
List<CSVRecord> recorder = parser.getRecords();
return recorder.get(0); //returning first element
} catch (IOException e) {
e.printStackTrace();
}
return null;
@seenimohamed
seenimohamed / url_check.py
Created May 25, 2018 10:48
To check whether a given url is up or not
from six.moves import urllib
import requests
def url_is_alive(url):
"""
Checks that a given URL is reachable.
:param url: A URL
:rtype: bool
"""
request = urllib.request.Request(url)
@seenimohamed
seenimohamed / move_rename_all.sh
Created June 12, 2019 07:27
Power of find command in terminal
#!/bin/sh
# Usage : move all mp4 files with removing extension
# Command to run :
# ./move_all_files_with_diff_name.sh <source_folder> <destination_folder>
# Command structure
# find . -name "*.mp4"
# normal find command