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
scala> case class A(a: Int, b: Int) | |
defined class A | |
scala> val as = Seq(A(1, 100), A(2, 100), A(3, 101)) | |
as: Seq[A] = List(A(1,100), A(2,100), A(3,101)) | |
scala> as.groupBy(_.b) | |
res3: scala.collection.immutable.Map[Int,Seq[A]] = Map(101 -> List(A(3,101)), 100 -> List(A(1,100), A(2,100))) | |
scala> res3.map{case (b, as) => b -> as.map(_.a)} |
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
/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home/bin/java -Xincgc -Xmx1024M -Xms1024M -Didea.launcher.port=7532 "-Didea.launcher.bin.path=/Applications/IntelliJ IDEA 14.app/Contents/bin" -Dfile.encoding=UTF-8 -classpath "/System/Library/Frameworks/JavaVM.framework/Versions/A/Resources/Deploy.bundle/Contents/Resources/Java/deploy.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Classes/dt.jar:/System/Library/Frameworks/JavaVM.framework/Versions/A/Resources/Deploy.bundle/Contents/Resources/Java/javaws.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Classes/jce.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Classes/management-agent.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Home/lib/sa-jdi.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Classes/alt-rt.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Classes/charsets.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Classes/classes.jar:/System/L |
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
class SharpSnowballArray { | |
@SubscribeEvent | |
def replaceSnowballWithArrow(event: EntityJoinWorldEvent) { | |
val entity = event.entity | |
val world = entity.worldObj | |
entity match { | |
case snowball: EntitySnowball if ! world.isRemote => | |
-2 to 2 foreach(xOff => { | |
-2 to 2 foreach (yOff => { |
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 combinations: Seq[Seq[Int]] = numDice match { | |
case 1 => for (a <- 1 to numSides) yield Seq(a) | |
case 2 => for (a <- 1 to numSides; b <- 1 to numSides) yield Seq(a, b) | |
case 3 => for (a <- 1 to numSides; b <- 1 to numSides; c <- 1 to numSides) yield Seq(a, b, 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
/* Display the numbers from 1 to 100 that are not divisible by both | |
4 and 7, but for those numbers divisible by 4, show ÷4 instead, and | |
for those divisible by 7, show ÷7 instead. */ | |
object Solution1 extends App { | |
println( | |
(1 to 100 map(n => { | |
def divBy(div: Int) = n % div == 0 | |
(divBy(4), divBy(7)) match { | |
case (false, false) => Some(n) |
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
import math | |
import numpy | |
from timeit import timeit | |
HIGHEST = 100000 | |
ARRAY_LEN = HIGHEST + 1 # For 0 | |
def make_sieve(): | |
sieve = numpy.ones(ARRAY_LEN) | |
mark_composites(sieve) | |
return sieve |
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
case class NameAndScreenName(val name: String, val screenName: String) extends Ordered[NameAndScreenName] { | |
override def toString = name + " (" + screenName + ")" | |
def compare(other: NameAndScreenName) = screenName compareToIgnoreCase other.screenName | |
def matches(search: String) = { | |
val slc = search.toLowerCase | |
search.length == 0 || name.toLowerCase.contains(slc) || screenName.toLowerCase.contains(slc) | |
} | |
} | |
title = "Send Message" |
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 isMentions = tweetsProvider.isInstanceOf[MentionsProvider] // TODO do without this test | |
val model = if (isMentions) | |
new StatusTableModel(sto, tweetsProvider, usersTableModel, fs, service, user.user, tagUsers) with Mentions | |
else | |
new StatusTableModel(sto, tweetsProvider, usersTableModel, fs, service, user.user, tagUsers) |
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
import javax.swing.SwingWorker | |
class A { | |
def loadAll(f:(Int) => List[String]): List[String] = List("a") | |
def getFriendsIds(page: Int): List[String] = List("a") | |
def getFollowersIds(page: Int): List[String] = List("a") | |
} | |
class B { | |
def setFollowers(followers: List[String]) {} |
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
case class Word(val word: String, val count: Long) { | |
override def toString = word + ": " + count | |
} | |
private def showWordCloud { | |
val counts = LinkedHashMap[String,Long]() | |
statusTableModel.filteredStatuses.map(status => { | |
List.fromArray(status.text.split("\\s")).foreach(word => { | |
counts.put(word, counts.getOrElse(word, 0L) + 1L) | |
}) |
OlderNewer