Skip to content

Instantly share code, notes, and snippets.

View 0xNacho's full-sized avatar

Nacho García Fernández 0xNacho

View GitHub Profile
city,pop,state
AGAWAM,15338,MA
CUSHMAN,36963,MA
BARRE,4546,MA
BELCHERTOWN,10579,MA
BLANDFORD,1240,MA
BRIMFIELD,3706,MA
CHESTER,1688,MA
CHESTERFIELD,177,MA
CHICOPEE,23396,MA
val words = Array("one", "two", "two", "three", "three", "three")
val wordPairsRDD = sc.parallelize(words).map(word => (word, 1))
val wordCountsWithGroup = wordPairsRDD
.groupByKey()
.map(t => (t._1, t._2.sum))
.collect()
Ejercicio 3
scala> Seq(0,1,3,6,5,4,-1,2,1).sorted.reverse
scala> Seq(0,1,3,6,5,4,-1,2,1).sortBy(_>_)
Ejercicio 4
scala> Seq("a","a","v","v","b").groupBy(identity).mapValues(_.size)
scala> Seq("a","a","v","v","b").groupBy( t=> t).mapValues(_.size)
scala> Seq("a","a","v","v","b").groupBy(l => l).map(t => (t._1, t._2.length))
@0xNacho
0xNacho / scala - filter by params
Created June 25, 2018 11:43
scala - filter by params
def isPar(x: Int) = if(x % 2 == 0 ) true else false
def positive(x: Int) = if(x > 0) true else false
def ejercicio(size: Int, fn: Int => Boolean ) = {
val list = genera(size)
list.filter(fn)
}
def genera(size: Int) = {
import { Observable } from 'rxjs/Observable';
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import 'rxjs/add/operator/map';
import { Film } from '../../model/Film';
/*
Generated class for the NetflixProvider provider.
See https://angular.io/guide/dependency-injection for more info on providers
wget https://services.gradle.org/distributions/gradle-3.4.1-bin.zip
sudo mkdir /opt/gradle
sudo unzip -d /opt/gradle gradle-3.4.1-bin.zip
export PATH=$PATH:/opt/gradle/gradle-3.4.1/bin
gradle -v
@0xNacho
0xNacho / sh
Created November 27, 2017 16:43
Migrate tables from on hive cluster to other
#!/bin/bash
hiveDBName=testdbname;
showcreate="show create table "
showpartitions="show partitions "
terminate=";"
tables=`hive -e "use $hiveDBName;show tables;"`
tab_list=`echo "${tables}"`
@0xNacho
0xNacho / Netflix.ts
Created March 23, 2017 19:17
Netflix roulette Angular2 provider
import { Observable } from 'rxjs/Observable';
import { Film } from './../model/film';
import { Injectable } from '@angular/core';
import { Http, Response } from '@angular/http';
import 'rxjs/add/operator/map';
/*
Generated class for the Netflix provider.
See https://angular.io/docs/ts/latest/guide/dependency-injection.html
@0xNacho
0xNacho / Picture.java
Created December 20, 2016 22:53
Flink Course - Picture POJO
package org.apache.flink.quickstart;
public class Picture {
private String name;
private String year;
private String nominations;
private String rating;
private String duration;
private String genre1, genre2;