*NIX & Hacking —— 第2期

做一本我感兴趣的杂志,就这么简单!

Debug

Introduction to Debuggers

Docker

DOCKER MACHINE 0.3.0 DEEP DIVE

Git

First aid git

Golang

go-lang-cheat-sheet

Kernel

Kernel and userspace tracing: with LTTng and his friends

Regular Expression

Five Invaluable Techniques to Improve Regex Performance

Rust

First Rust Program Pain (So you can avoid it…)

Scala

Various ways to run Scala code
Why does the same scala code work OK in command line while not in Intellij?

Unix

A little collection of cool unix terminal/console/curses tools
How big is the pipe buffer?
Stack Smashing On A Modern Linux System
Unix history repository

Easter egg

DMA (Direct Memory Access)
Get Unix Jobs
Here are 13 tech jobs that pay at least $130,000 across the country

如何运行scala脚本

搭建Scala开发环境一文中可以看到不加任何参数直接运行scala命令时,会启动REPL(Read,Eval,Print,Loop)环境,然后就可以在这个环境里交互地执行Scala代码。本文介绍如何运行Scala脚本(script)。

首先创建一个简单的Scala脚本(hello.scala):

print("Hello world!\n")

a)直接运行scala hello.scala

[root@Fedora scala]# scala hello.scala
Hello world!

b)在REPL环境用load命令运行hello.scala

[root@Fedora scala]# scala
Welcome to Scala version 2.10.4 (OpenJDK 64-Bit Server VM, Java 1.8.0_45).
Type in expressions to have them evaluated.
Type :help for more information.

scala> :load hello.scala
Loading hello.scala...
Hello world!

c)如果想把脚本编译成JVM byte code (一组*.class文件),可以使用scalac程序(命令行选项是-Xscript <object><object>是“main class”的名字,也即Java程序的入口):

[root@Fedora scala]# scalac -Xscript hello hello.scala
[root@Fedora scala]# ls
hello$$anon$1.class  hello.class  hello$.class  hello.scala
[root@Fedora scala]# scala hello
Hello world!

也可以用scalap这个逆向分析工具分析一下hello.class

[root@Fedora scala]# scalap -cp . hello
object hello extends scala.AnyRef {
  def this() = { /* compiled code */ }
  def main(argv : scala.Array[scala.Predef.String]) : scala.Unit = { /* compiled code */ }
}