This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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))); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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--; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ls <options> | |
-l -> detailed view | |
S -> sort in decending order | |
r -> reverse | |
ls -lS -> decending order | |
ls -lSr -> ascending order |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//to compile a java class | |
javac | |
//to include jars in classpath | |
java -cp | |
//to run jar | |
java -jar jarfile.jar | |
//to give args |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
OlderNewer