Skip to content

Instantly share code, notes, and snippets.

@cipri7329
cipri7329 / most-common-character-spark-scala.scala
Created December 12, 2016 16:00
determine what is the most frequent CHARACTER in the file, and how many times was it used
//In the cell below, determine what is the most frequent CHARACTER in the README, and how many times was it used?
//spark and scala
var charCounts2 = readme.flatMap(line => line.toList).
filter( a => !a.equals("\n") && !a.equals(" ") && !a.equals("") ).
filter( _ != ' ').
map(character => (character, 1)).
reduceByKey((a,b) => a + b).
reduce((a, b) => if (a._2 > b._2) a else b)
//take(55).
@virasak
virasak / AuthenService.java
Created September 28, 2012 06:09
Simple Guice & JUnit4 Integration: Use the unit test itself as a module to provide member injection. Use @provides methods to build a module from unit test object.
import com.google.inject.Inject;
public class AuthenService {
private final UserDAO userDAO;
@Inject
public AuthenService(UserDAO userDAO) {
this.userDAO = userDAO;