Skip to content

Instantly share code, notes, and snippets.

View victor-ferrer's full-sized avatar

Victor Ferrer victor-ferrer

View GitHub Profile
package com.ericsson.edosdp.pmgateway.service;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
@victor-ferrer
victor-ferrer / test.txt
Created May 22, 2019 07:40
Test file for the Code Task
Republican nomination
Eisenhower presidential campaign, Baltimore, Maryland, September 1952
Dwight D. Eisenhower and Senator Robert A. Taft from Ohio were the two front-runners for the Republican Party presidential nomination going into the 1952 Republican presidential primaries. Also contending for the nomination were Governor Earl Warren of California, and former Governor Harold Stassen of Minnesota.[3] Taft led the conservative wing of the party, centered in the Midwest, that rejected many of the New Deal social welfare programs created in the 1930s, and generally held a non-interventionist foreign policy stance, believing that America should avoid alliances with foreign powers. Taft had been a candidate for the Republican nomination in 1940 and 1948, but had been defeated both times by moderate Republicans from New York: Wendell Willkie in 1940, and Thomas E. Dewey in 1948. Taft blamed these successive loses on the New York GOP's undue influence over the national party.[4]
Dewey, the party's presidentia
public class Exercise {
public static void main(String[] args) {
// TODO Read all lines/all content of the file provided in args[0]
// TODO Separate it into a list of words (just separate by white space, no need to remove other characters)
// TODO Create a map containing:
// - As key: Each of the Word in the file
{
[
[
"ObjectId" : "E00707.L19447C",
"RecordDate" : "2019/02/10",
"DateInDays" : "10",
"DateInHours" : "00",
"DateInTicks": "0",
"Source" : "source",
"Target" : "target",
@victor-ferrer
victor-ferrer / StatisticsUtils.scala
Created August 13, 2018 19:15
Statistical Utilities
package example
/**
* Created by Victor on 8/13/2018.
* Utility methods for the 10 days of statistics in Hackerrank
*/
object StatisticsUtils
{
/**
* Calculates the standard deviation of an Array of Integers
val df = sqlContext.read.parquet("/victor/testimport")
.select($"date",$"close",$"volume",$"year_p")
.filter("year_p = 1962")
df.show()
/*
+----------+--------+---------+------+
| date| close| volume|year_p|
+----------+--------+---------+------+
|1962-08-01| 0.6875|1372800.0| 1962|
@victor-ferrer
victor-ferrer / script.sh
Last active August 5, 2018 15:40
Script to split a date column in a CSV and generate three new columns with day, month and year values
# Original CSV is generated as follows:
# Date,Open,High,Low,Close,Adj Close,Volume
# 1962-01-02,0.781250,0.794271,0.773438,0.778646,0.002326,2073600
# 1962-01-03,0.774740,0.774740,0.768229,0.770833,0.002303,1420800
# Ignore the header, extract the year and month from the first column,
# create two additional columns at the end of the file and add quotes to the
# first colum:
@victor-ferrer
victor-ferrer / script.sh
Last active August 3, 2018 16:18
Use Kite SDK partition-config for generating the partition definition file
# Create the partitions from the "date" column
kite-dataset partition-config date:year date:month date:day -s my_schema.txt \
-o partitions.txt
@victor-ferrer
victor-ferrer / partitions.txt
Last active August 5, 2018 16:27
Text file defining the partition strategy
[ {
"name" : "year_p",
"source" : "year",
"type" : "identity"
}, {
"name" : "month_p",
"source" : "month",
"type" : "identity"
} ]
@victor-ferrer
victor-ferrer / my_schema.txt
Last active August 5, 2018 14:52
Schema definition for the Parquet file
{
"type" : "record",
"name" : "ge_stock_data",
"namespace" : "victor.ferrer.stock.data",
"doc" : "GE",
"fields" : [
{ "name" : "date", "type" : "string" },
{ "name" : "open", "type" : "float"},
{ "name" : "high", "type" : "float" },
{ "name" : "low", "type" : "float" },