是否可以在IntelliJ IDEA中更改控制台字体大小?
我在"设置">"编辑器">"字体 " 下更改了实际文本大小,但"控制台/终端"字体太小.
我正在使用Community Edition 15
由于我喜欢在Scala中编程,在我的Google采访中,我让他们给我一个Scala /函数式编程风格的问题.我得到的Scala功能样式问题如下:
您有两个由字母字符组成的字符串以及一个表示退格符号的特殊字符.我们将这个退格字符称为"/".当您到达键盘时,键入此字符序列,包括退格/删除字符.要实现的解决方案必须检查两个字符序列是否产生相同的输出.例如,"abc","aa/bc"."abb/c","abcc /","/ abc"和"// abc"都产生相同的输出"abc".因为这是一个Scala /函数编程问题,所以必须以惯用的Scala风格实现您的解决方案.
我写了下面的代码(可能不是我写的,我只是关闭内存).基本上我只是线性地通过字符串,将字符前置到列表,然后我比较列表.
def processString(string: String): List[Char] = {
string.foldLeft(List[Char]()){ case(accumulator: List[Char], char: Char) =>
accumulator match {
case head :: tail => if(char != '/') { char :: head :: tail } else { tail }
case emptyList => if(char != '/') { char :: emptyList } else { emptyList }
}
}
}
def solution(string1: String, string2: String): Boolean = {
processString(string1) == processString(string2)
}
Run Code Online (Sandbox Code Playgroud)
到现在为止还挺好?然后他询问时间复杂度,我回答线性时间(因为你必须处理每个字符一次)和线性空间(因为你必须将每个元素复制到一个列表中).然后他让我在线性时间内做,但是有恒定的空间.我想不出一种纯粹功能性的方法.他说尝试在Scala集合库中使用一个函数,如"zip"或"map"(我明确地记得他说过"zip"这个词).
这就是事情.我认为在没有任何可变状态或副作用的情况下,在恒定空间内进行它是不可能的.就像我认为他弄乱了这个问题.你怎么看?
你可以在线性时间内解决它,但是空间恒定吗?
functional-programming scala purely-functional scala-collections
我想在Scala中实现我自己的for-comprehension兼容的monad和functor.
我们以两个愚蠢的monad为例.一个monad是一个状态monad,包含一个可以映射或平面映射的"Int".
val maybe = IntMonad(5)
maybe flatMap( a => 3 * ( a map ( () => 2 * a ) ) )
// returns IntMonad(30)
Run Code Online (Sandbox Code Playgroud)
另一个monad采取像这样的功能组成......
val func = FunctionMonad( () => println("foo") )
val fooBar = func map ( () => println("bar") )
fooBar()
// foo
// bar
// returns Unit
Run Code Online (Sandbox Code Playgroud)
这个例子可能有一些错误,但你明白了.
我希望能够在Scala中使用这两种不同类型的Monad组成的for-understanding.像这样:
val myMonad = IntMonad(5)
for {
a <- myMonad
b <- a*2
c <- IntMonad(b*2)
} yield c
// returns IntMonad(20)
Run Code Online (Sandbox Code Playgroud)
我不是斯卡拉大师,但你明白了
我有一个Linux程序分为两部分.
一部分执行NAT遍历以获得UDP套接字(UDP打孔)或TCP套接字(TCP打孔).第一部分用C语言编写,以允许本地功能,这些功能可以促进或增强NAT遍历过程.第二部分实际上使用通过第一部分中执行的NAT遍历获得的连接套接字.
现在这是问题所在.我希望第一部分,即获得套接字的部分,独立于第二部分,即使用套接字的部分用于特定应用目的.例如,我希望第一部分可以重用于各种不同的应用程序,这些应用程序都需要在对等体之间建立的UDP和TCP连接.
现在,我希望第二部分(应用程序部分)用Java而不是C或C++编写.我希望第二部分使用由负责NAT遍历的C代码获得的套接字连接.假设第一部分建立了一个连接,然后返回一个结构:
// Represents a TCP or UDP connection that was obtained in part one.
struct ConnectionObtained {
int socket_file_descriptor;
int source_port;
int destination_port;
int source_address; // 4 byte ipv4 address
int destination_address;
int is_UDP; // 1 for UDP client socket, 0 for TCP client socket
};
Run Code Online (Sandbox Code Playgroud)
第一部分中的C代码可以通过JNI(Java Native Interface)或通过进程间通信将此POD /结构提供给第二部分中的Java代码.
我希望Java代码使用该信息来构造一个声明类型为java.net.DatagramSocket或java.net.Socket的对象,然后在需要DatagramSocket或Socket的任何地方使用该对象.
作为起点,请考虑以下示例代码......
/**
* Determines the Unix file descriptor number of the given {@link ServerSocket}.
*/
private int getUnixFileDescriptor(ServerSocket ss) throws NoSuchFieldException, IllegalAccessException, NoSuchMethodException, InvocationTargetException {
Field …Run Code Online (Sandbox Code Playgroud) 以下是使用IO Monad的一些Scala猫代码:
import java.util.concurrent.{ExecutorService, Executors}
import cats.effect.IO
import scala.concurrent.{ExecutionContext, ExecutionContextExecutor}
import scala.util.control.NonFatal
object Program extends App {
type CallbackType = (Either[Throwable, Unit]) => Unit
// IO.async[Unit] is like a Future that returns Unit on completion.
// Unlike a regular Future, it doesn't start to run until unsafeRunSync is called.
def forkAsync(toRun: () => Unit)(executor: ExecutorService): IO[Unit] = IO.async[Unit] { callback: CallbackType =>
// "callback" is a function that either takes a throwable (Left) or whatever toRun returns (Right). …Run Code Online (Sandbox Code Playgroud) 当我尝试从 Mac 通过 SSH 连接到远程桌面时,收到以下错误消息:
$ ssh -vvvv john@dev-dsk-john.com
OpenSSH_7.4p1, LibreSSL 2.5.0
debug1: Reading configuration data /Users/john/.ssh/config
debug1: /Users/john/.ssh/config line 26: Applying options for *
debug1: /Users/john/.ssh/config line 40: Applying options for dev-dsk*.amazon.com
debug1: /Users/john/.ssh/config line 165: Applying options for *.us-east-*.amazon.com
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: auto-mux: Trying existing master
debug1: Control socket "/tmp/ssh_mux_dev-dsk-john.com_22_john" does not exist
debug2: resolving "dev-dsk-john.com" port 22
debug2: ssh_connect_direct: needpriv 0
debug1: Connecting to dev-dsk-john.com [10.1.133.160] port 22.
debug1: connect to address 10.1.1.1 port …Run Code Online (Sandbox Code Playgroud) 我有一种情况,我需要一个可以采用类型的方法:
Array[Int]
Array[Array[Int]]
Array[Array[Array[Int]]]
Array[Array[Array[Array[Int]]]]
etc...
Run Code Online (Sandbox Code Playgroud)
让我们称这种类型的RAI为"递归的整数数组"
def make(rai: RAI): ArrayPrinter = { ArrayPrinter(rai) }
Run Code Online (Sandbox Code Playgroud)
其中ArrayPrinter是一个用RAI初始化并迭代整个rai的类(假设它打印了这个数组中的所有值[Array [Int]])
val arrayOfArray: Array[Array[Int]] = Array(Array(1, 2), Array(3, 4))
val printer: ArrayPrinter[Array[Array[Int]]] = make(arrayOfArray)
printer.print_! // prints "1, 2, 3, 4"
Run Code Online (Sandbox Code Playgroud)
它还可以返回原始Array [Array [Int]]而不会丢失任何类型信息.
val arr: Array[Array[Int]] = printer.getNestedArray()
Run Code Online (Sandbox Code Playgroud)
你如何在Scala中实现这一点?
我有一个用于调试的 Java 打印堆栈跟踪功能。
private static void printError(String message, Significance severityLevel, int stackTraceStart) {
final String thread_name = Thread.currentThread().getName();
final String location_of_print_statement = Thread.currentThread().getStackTrace()[stackTraceStart].toString();
Package_Private.printLineToReadout("\n" + "Thread \"" + thread_name + "\": "
+ location_of_print_statement + "\n" + message, ReadoutCondition.BAD, severityLevel);
}
Run Code Online (Sandbox Code Playgroud)
问题是它只打印“modules.ShopModule.configure(ShopModule.scala:8)”
我希望它打印该文件的整个路径,而不是相对路径。
当我通过右键单击"Debug"在IntelliJ中运行我的sbt项目时,我收到此错误消息.
/home/johnreed/Applications/jdk1.8.0_73/bin/java -agentlib:jdwp=transport=dt_socket,address=127.0.0.1:34395,suspend=y,server=n -Dfile.encoding=UTF-8 -classpath /home/johnreed/Applications/jdk1.8.0_73/jre/lib/charsets.jar:/home/johnreed/Applications/jdk1.8.0_73/jre/lib/deploy.jar:/home/johnreed/Applications/jdk1.8.0_73/jre/lib/ext/cldrdata.jar:/home/johnreed/Applications/jdk1.8.0_73/jre/lib/ext/dnsns.jar:/home/johnreed/Applications/jdk1.8.0_73/jre/lib/ext/jaccess.jar:/home/johnreed/Applications/jdk1.8.0_73/jre/lib/ext/jfxrt.jar:/home/johnreed/Applications/jdk1.8.0_73/jre/lib/ext/localedata.jar:/home/johnreed/Applications/jdk1.8.0_73/jre/lib/ext/nashorn.jar:/home/johnreed/Applications/jdk1.8.0_73/jre/lib/ext/sunec.jar:/home/johnreed/Applications/jdk1.8.0_73/jre/lib/ext/sunjce_provider.jar:/home/johnreed/Applications/jdk1.8.0_73/jre/lib/ext/sunpkcs11.jar:/home/johnreed/Applications/jdk1.8.0_73/jre/lib/ext/zipfs.jar:/home/johnreed/Applications/jdk1.8.0_73/jre/lib/javaws.jar:/home/johnreed/Applications/jdk1.8.0_73/jre/lib/jce.jar:/home/johnreed/Applications/jdk1.8.0_73/jre/lib/jfr.jar:/home/johnreed/Applications/jdk1.8.0_73/jre/lib/jfxswt.jar:/home/johnreed/Applications/jdk1.8.0_73/jre/lib/jsse.jar:/home/johnreed/Applications/jdk1.8.0_73/jre/lib/management-agent.jar:/home/johnreed/Applications/jdk1.8.0_73/jre/lib/plugin.jar:/home/johnreed/Applications/jdk1.8.0_73/jre/lib/resources.jar:/home/johnreed/Applications/jdk1.8.0_73/jre/lib/rt.jar:/home/johnreed/sbtProjects/UnderstandingScala/target/scala-2.11/classes:/home/johnreed/.ivy2/cache/com.chuusai/shapeless_2.11/bundles/shapeless_2.11-2.3.1.jar:/home/johnreed/.ivy2/cache/org.scala-lang/scala-library/jars/scala-library-2.11.8.jar:/home/johnreed/.ivy2/cache/com.google.code.findbugs/jsr305/jars/jsr305-2.0.1.jar:/home/johnreed/.ivy2/cache/com.google.guava/guava/bundles/guava-16.0.1.jar:/home/johnreed/.ivy2/cache/com.twitter/jsr166e/jars/jsr166e-1.0.0.jar:/home/johnreed/.ivy2/cache/com.twitter/util-collection_2.11/jars/util-collection_2.11-6.34.0.jar:/home/johnreed/.ivy2/cache/com.twitter/util-core_2.11/jars/util-core_2.11-6.34.0.jar:/home/johnreed/.ivy2/cache/com.twitter/util-function_2.11/jars/util-function_2.11-6.34.0.jar:/home/johnreed/.ivy2/cache/commons-collections/commons-collections/jars/commons-collections-3.2.2.jar:/home/johnreed/.ivy2/cache/javax.inject/javax.inject/jars/javax.inject-1.jar:/home/johnreed/.ivy2/cache/org.scala-lang.modules/scala-parser-combinators_2.11/bundles/scala-parser-combinators_2.11-1.0.4.jar:/home/johnreed/.ivy2/cache/org.typelevel/macro-compat_2.11/jars/macro-compat_2.11-1.1.1.jar:/home/johnreed/.ivy2/cache/scala.trace/scala-trace-debug_2.11/jars/scala-trace-debug_2.11-2.2.14.jar:/home/johnreed/Applications/idea-IC-145.258.11/lib/idea_rt.jar pkg.Main
Connected to the target VM, address: '127.0.0.1:34395', transport: 'socket'
Disconnected from the target VM, address: '127.0.0.1:34395', transport: 'socket'
Exception in thread "main" java.lang.NoClassDefFoundError: scala/reflect/api/TypeCreator
at pkg.Main.main(Main.scala)
Caused by: java.lang.ClassNotFoundException: scala.reflect.api.TypeCreator
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 1 more
Process finished with exit code 1
Run Code Online (Sandbox Code Playgroud)
我从IntelliJ运行时只收到此错误.当我从SBT运行它时sbt run,它工作正常.sbt compile工作文件也是.我如何解决这个问题,以便我的项目作为应用程序运行?
*解决方案*
手动添加scala-reflect-2.11.8.jar
reflection scala intellij-idea classnotfoundexception intellij-scala
在Scala中,我需要分析同一文件的几个不同版本的编译时间,在运行时将产生相同的输出.
例:
time scalac foo1.scala
Run Code Online (Sandbox Code Playgroud)
time scalac foo2.scala
Run Code Online (Sandbox Code Playgroud)
time scalac foo3.scala
Run Code Online (Sandbox Code Playgroud)
这个项目似乎只是这样做,但我以前从未做过这样的事情,而且说明似乎不是很初学者友好.如果我不能让它工作,我可能会使用它,但我认为宏编译基准测试只测量解析和类型检查所需的时间,而不是编译整个文件的时间.
理想情况下,我想知道从第一个编译阶段(解析器)到最后阶段(生成JVM字节码)需要多少次,不一定包括jvm"预热"时间.
scala ×6
java ×2
monads ×2
c ×1
debugging ×1
font-size ×1
intellij-15 ×1
io-monad ×1
performance ×1
profiler ×1
reflection ×1
scala-cats ×1
sockets ×1
ssh ×1
stdout ×1
tcp ×1
udp ×1