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
val fruits = List("Apple", "Banana", "Fig", "Wiki", "Pineapple", "Strawberry", "Watermelon") | |
val keyValues = sc.parallelize(fruits.map(fruit => (fruit, fruit.length))) | |
keyValues.sortByKey().foreach(print) | |
//output> (Apple,5)(Banana,6)(Fig,3)(Pineapple,9)(Strawberry,10)(Watermelon,10)(Wiki,4) | |
keyValues.sortBy(_._1).foreach(print) //as sortByKey() | |
//output> (Apple,5)(Banana,6)(Fig,3)(Pineapple,9)(Strawberry,10)(Watermelon,10)(Wiki,4) | |
keyValues.sortBy(_._2).foreach(print) //as sortByValue() |
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
val list = List(1, 2, 3) //> list : List[Int] = List(1, 2, 3) | |
list.map(_.toString).mkString(", ") //> res0: String = 1, 2, 3 | |
val map = Map(1 -> "A", 2 -> "B", 3 -> "C") //> map : scala.collection.immutable.Map[Int,String] = Map(1 -> A, 2 -> B, 3 -> C) | |
map.map(_ match { case (k, v) => k + ":" + v }).mkString(", ") | |
//> res1: String = 1:A, 2:B, 3:C |
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
def isPrime(i: Int) = | |
if (i <= 1) | |
false | |
else if (i == 2) | |
true | |
else | |
!(2 to i/2).exists(x => i % x == 0) //> isPrime: (i: Int)Boolean | |
isPrime(2) //> res0: Boolean = true | |
isPrime(3) //> res1: Boolean = true |
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 | |
name=$1 | |
version=$2 | |
scalaVersion=2.11.7 | |
mkdir -p src/{main,test}/{java,resources,scala} | |
mkdir lib project target | |
# create an initial build.sbt file |
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
add_dict = { (0.0,0.0):0.0, (0.0,1.0):1.0, (0.0,2.0):2.0, (0.0,3.0):3.0, (0.0,4.0):4.0, (0.0,5.0):5.0, (0.0,6.0):6.0, (0.0,7.0):7.0, (0.0,8.0):8.0, (0.0,9.0):9.0, (1.0,0.0):1.0, (1.0,1.0):2.0, (1.0,2.0):3.0, (1.0,3.0):4.0, (1.0,4.0):5.0, (1.0,5.0):6.0, (1.0,6.0):7.0, (1.0,7.0):8.0, (1.0,8.0):9.0, (1.0,9.0):10.0, (2.0,0.0):2.0, (2.0,1.0):3.0, (2.0,2.0):4.0, (2.0,3.0):5.0, (2.0,4.0):6.0, (2.0,5.0):7.0, (2.0,6.0):8.0, (2.0,7.0):9.0, (2.0,8.0):10.0, (2.0,9.0):11.0, (3.0,0.0):3.0, (3.0,1.0):4.0, (3.0,2.0):5.0, (3.0,3.0):6.0, (3.0,4.0):7.0, (3.0,5.0):8.0, (3.0,6.0):9.0, (3.0,7.0):10.0, (3.0,8.0):11.0, (3.0,9.0):12.0, (4.0,0.0):4.0, (4.0,1.0):5.0, (4.0,2.0):6.0, (4.0,3.0):7.0, (4.0,4.0):8.0, (4.0,5.0):9.0, (4.0,6.0):10.0, (4.0,7.0):11.0, (4.0,8.0):12.0, (4.0,9.0):13.0, (5.0,0.0):5.0, (5.0,1.0):6.0, (5.0,2.0):7.0, (5.0,3.0):8.0, (5.0,4.0):9.0, (5.0,5.0):10.0, (5.0,6.0):11.0, (5.0,7.0):12.0, (5.0,8.0):13.0, (5.0,9.0):14.0, (6.0,0.0):6.0, (6.0,1.0):7.0, (6.0,2.0):8.0, (6.0,3.0):9.0, (6.0,4.0):10.0, (6.0,5.0):11.0, (6.0 |
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
Python 3.4.2 (default, Oct 8 2014, 10:45:20) | |
[GCC 4.9.1] on linux | |
Type "help", "copyright", "credits" or "license" for more information. | |
16/12/14 12:27:20 WARN NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable | |
Welcome to | |
____ __ | |
/ __/__ ___ _____/ /__ | |
_\ \/ _ \/ _ `/ __/ '_/ | |
/__ / .__/\_,_/_/ /_/\_\ version 2.0.1 | |
/_/ |
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
#include <stdio.h> | |
#define MIN(A,B) ((A) < (B) ? (A) : (B)) | |
void hexdump(void *buf, int size) { | |
unsigned char *ptr; | |
int i, j, len = 0; | |
for (i = 0; i < size; i += len) { | |
ptr = buf + i; | |
len = MIN(16, size - i); | |
printf("%04x | ", 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
# init repository | |
rm -rf learn-git | |
mkdir learn-git | |
cd learn-git | |
git init | |
# commit changes | |
echo 1 >> file | |
git add . | |
git commit -m "1" |
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
# init repository | |
rm -rf learn-git | |
mkdir learn-git | |
cd learn-git | |
git init | |
# commit changes @master | |
echo 1 >> file | |
git add . | |
git commit -m "1" |
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
# init repository | |
mkdir learn-git | |
cd learn-git | |
git init | |
# commit changes | |
echo 1 >> file | |
git add . | |
git commit -m "1" |
OlderNewer