- encourage /ɪn'kʌrɪdʒ; en-/ vt. 鼓励,怂恿;激励;支持
- interpreter /ɪn'tɜːprɪtə/ n. 解释者;口译者;注释器
- compiler /kəm'paɪlə/ n. 编译器;[计] 编译程序;编辑者,汇编者
- interactive /ɪntər'æktɪv/ adj. 交互式的;相互作用的
- evaluate /ɪ'væljʊeɪt/ vt. 评价;估价;求…的值; vi. 评价;估价
- colon /'kəʊlən/ n. [解剖] 结肠;冒号(用于引语、说明、例证等之前);科郎(哥斯达黎加货币单位)
- comma /'kɒmə/ n. 逗号;停顿
- parenthesis /pə'renθɪsɪs/ n. 插入语,插入成分; n. 圆括号; n. 间歇,插曲
- brace /breɪs/ n. 支柱;[语] 大括号;曲柄; vt. 支撑;振作起来;激励;撑牢; vi. 支持;打起精神; adj. 曲柄的; n. (Brace)人名;(英)布雷斯;(法)布拉斯
- curly /'kɜːlɪ/ adj. 卷曲的;卷毛的;(木材)有皱状纹理的;蜷缩的
- curly brace 花括号
- bracket /'brækɪt/ n. 支架;括号;墙上凸出的托架; vt. 括在一起;把…归入同一类;排除
- square bracket 方括号
Chapter3:Next Steps in Scala
Parameterize arrays with types
Note that when you parameterize an instance with both a type and a value, the type comes first in its square brackets, followed by the value in parentheses.
val greetStrings = new Array[String](3) |
val greetStrings: Array[String] = new Array[String](3) |
Note that the type parameterization portion (the type names in square brackets) forms part of the type of the instance, the value parameterization part (the values in parentheses) does not
Note that arrays in Scala are accessed by placing the index inside parentheses, not square brackets as in Java.
Scala concerning the meaning of val
When you define a variable with val, the variable can’t be reassigned, but the object to which it refers could potentially still be changed.
- you couldn’t reassign greetStrings to a different array; greetStrings will always point to the same Array[String] instance with which it was initialized.
- you can change the elements of that Array[String] over time
So the array itself is mutable.
Scala operation
general rule of Scala:
-
if a method takes only one parameter, you can call it without a dot or parentheses.
for (i <- 0 to 2)
print(greetStrings(i))The
to
in this example is actually a method that takes oneInt
argument. The code0 to 2
is transformed into the method call(0).to(2)
Note that this syntax only works if you explicitly specify the receiver of the method call. You cannot write “println 10”, but you canwrite “Console println 10”. -
When you apply parentheses surrounding one or more values to a variable, Scala will transform the code into an invocation of a method named apply on that variable.
So greetStrings(i) gets transformed into greetStrings.apply(i) Thus accessing an element of an array in Scala is simply a method call like any other. This principle is not restricted to arrays: any application of an object to some arguments in parentheses will be transformed to an apply method call. Of course this will compile only if that type of object actually defines an apply method. -
when an assignment is made to a variable to which parentheses and one or more arguments have been applied, the compiler will transform that into an invocation of an update method that takes the arguments in parentheses as well as the object to the right of the equals sign.
greetStrings(0) = "Hello"
will be transformed into:greetStrings.update(0, "Hello")
Scala doesn’t technically have operator overloading
Scala achieves a conceptual simplicity by treating everything, from arrays to expressions, as objects with methods. You don’t have to remember special cases, such as the differences in Java between primitive and their corresponding wrapper types, or between arrays and regular objects. Moreover,this uniformity does not incur a significant performance cost. The Scala compiler uses Java arrays, primitive types, and native arithmetic where possible in the compiled code.
Scala获得了一个概念上的简单性,通过把一切(无论是数组还是表达式),都当作objects whih methods来对待。
Scala doesn’t technically have operator overloading, because it doesn’t actually have operators in the traditional sense. Instead, characters such as +, -, *, and / can be used in method names. Thus, when you typed 1 + 2 into the Scala interpreter in Step 1, you were actually invoking a method named + on the Int object 1, passing in 2 as a parameter. As illustrated in Figure 3.1, you could alternatively have written 1 + 2 using traditional method invocation syntax, (1).+(2).
examples
val numNames = Array("zero", "one", "two") |
Use lists
One of the big ideas of the functional style of programming is that methods should not have side effects. A method’s only act should be to compute and return a value. Some benefits gained when you take this approach are that methods become less entangled, and therefore more reliable and reusable. Another benefit (in a statically typed language) is that everything that goes into and out of a method is checked by a type checker, so logic errors are more likely to manifest themselves as type errors. Applying this functional philosophy to the world of objects means making objects immutable.
- arrays are mutable objects
- Scala Lists are always immutable (whereas Java Lists can be mutable). Scala’s List is designed to enable a functional style of programming
// List has a method named ‘:::’ for list concatenation |
#List(1, 2) and List(3, 4) were not mutated. |
//Cons(::) prepends a new element to the beginning of an existing list, |
NOTE:
In the expression “1 :: twoThree”, :: is a method of its right operand, the list, twoThree. You might suspect there’s something amiss with the associativity of the :: method, but it is actually a simple rule to remember: If a method is used in operator notation, such as a * b, the method is invoked on the left operand, as in a.*(b)—unless the method name ends in a colon. If the method name ends in a colon, the method is invoked on the right operand. Therefore, in 1 :: twoThree, the :: method is invoked on twoThree, passing in 1, like this: twoThree.::(1)
//Nil is a empty List(or List()) |
Why not append to lists?
Class List does offer an “append” operation —it’s written :+ and isexplained in Chapter 24— but this operation is rarely used, becausethe time it takes to append to a list grows linearly with the size of thelist, whereas prepending with :: takes constant time. Your options ifyou want to build a list efficiently by appending elements is to prependthem, then when you’re done call reverse; or use a ListBuffer, amutable list that does offer an append operation, and when you’re donecall toList. ListBuffer will be described in Section 22.2.
What it is | What it does |
---|---|
List() or Nil | The empty List |
List("Cool", "tools", "rule") | Creates a new List[String] with the three values "Cool", "tools", and "rule" |
val thrill = "Will" :: "fill" :: "until" :: Nil | Creates a new List[String] with the three values "Will", "fill", and "until" |
List("a", "b") ::: List("c", "d") | Concatenates two lists (returns a new List[String] with values "a", "b", "c", and "d") |
thrill(2) | Returns the element at index 2 (zero based) of the thrill list (returns "until") |
thrill.count(s => s.length == 4) | Counts the number of string elements in thrill that have length 4 (returns 2) thrill.drop(2) Returns the thrill list without its first 2 elements (returns List("until")) |
thrill.dropRight(2) | Returns the thrill list without its rightmost 2 elements (returns List("Will")) |
thrill.exists(s => s == "until") | Determines whether a string element exists in thrill that has the value "until" (returns true) |
thrill.filter(s => s.length == 4) | Returns a list of all elements, in order, of the thrill list that have length 4 (returns List("Will", "fill")) |
thrill.forall(s => s.endsWith("l")) | Indicates whether all elements in the thrill list end with the letter "l" (returns true) |
thrill.foreach(s => print(s)) | Executes the print statement on each of the strings in the thrill list (prints "Willfilluntil") |
thrill.foreach(print) | Same as the previous, but more concise (also prints "Willfilluntil") |
thrill.head | Returns the first element in the thrill list (returns "Will") |
thrill.init | Returns a list of all but the last element in the thrill list (returns List("Will", "fill")) |
thrill.isEmpty | Indicates whether the thrill list is empty (returns false) |
thrill.last | Returns the last element in the thrill list (returns "until") |
thrill.length | Returns the number of elements in the thrill list (returns 3) |
thrill.map(s => s + "y") | Returns a list resulting from adding a "y" to each string element in the thrill list (returns List("Willy", "filly", "untily")) |
thrill.mkString(", ") | Makes a string with the elements of the list (returns "Will, fill, until") |
thrill.remove(s => s.length == 4) | Returns a list of all elements, in order, of the thrill list except those that have length 4 (returns List("until")) |
thrill.reverse | Returns a list containing all elements of the thrill list in reverse order (returns List("until", "fill", "Will")) |
thrill.sort((s, t) => s.charAt(0).toLower < t.charAt(0).toLower) | Returns a list containing all elements of the thrill list in alphabetical order of the first character lowercased (returns List("fill", "until", "Will")) |
thrill.tail | Returns the thrill list minus its first element (returns List("fill", "until")) |
Use tuples
Chapter2:First Step in Scala
Define some variable
val
is similar to a final in Javavar
is not final
Define some functions
- style-1
def max(x: Int, y: Int): Int = { |
- style-2
//infer result type |
- style-3
//function body is single line,leave off the curly braces |
- style-4
//only side effect(return Unit),leave off the result type and the equals sign, and enclose the body of the method in curly braces. |
Unit
:A result type of Unit indicates the function returns no interesting value. Scala’s Unit type is similar to Java’s void type, and in fact every void-returning method in Java is mapped to a Unit-returning method in Scala.
scala> def greet() = println("Hello, world!") |
**NOTE:**One puzzler to watch out for is that whenever you leave off the equals sign before the body of a function, its result type will definitely be Unit.This is true no matter what the body contains, because the Scala compiler can convert any type to Unit.
scala> def f(): Unit = "this String gets lost" |
crc
wiki:循環冗餘校驗
wiki:Category:Cyclic_redundancy_checks
循环冗余检验 (CRC) 算法原理
循环冗余校验(CRC)算法入门引导
CRC32算法详细推导(1)
循环冗余校验码
CRC 算法原理及 C 语言实现
CRC算法原理及C语言实现
矛与盾的较量(2)——CRC原理篇
CRC32算法学习笔记以及如何用java实现
A PAINLESS GUIDE TO CRC ERROR DETECTION ALGORITHMS
java Binary Literals
binary-literals.html
stackoverflow:binary-literals-in-java
wikibooks:Java-Literals
byte b = 0b01111111; |
byte,short的Binary Literal的首位是1时,需要转型。
IdentityHashMap
IdentityHashMap.html
http://www.28im.com/java/a757966.html
bitops
URL_URI_URN
load factor = 2 / 3
max = capacity * $(load factor)
table[2i] = key
table[2i+1] = value
linear probing
private static int hash(Object x, int length) { |
public V put(K key, V value) { |
linux-cpuinfo
cpu
- processor 逻辑处理器的唯一标识符。
- physical id 每个物理封装的唯一标识符。
- siblings 相同物理封装中的逻辑处理器的数量。
- cpu cores 相同物理封装中的内核数量。
- core id 每个内核的唯一标识符。
- 拥有相同 physical id 的所有逻辑处理器共享同一个物理插座。每个 physical id 代表一个唯一的物理封装。
- Siblings 表示位于这一物理封装上的逻辑处理器的数量。它们可能支持也可能不支持超线程(HT)技术。
- 每个 core id 均代表一个唯一的处理器内核。所有带有相同 core id 的逻辑处理器均位于同一个处理器内核上。
- 如果有一个以上逻辑处理器拥有相同的 core id 和 physical id,则说明系统支持超线程(HT)技术。
- 如果有两个或两个以上的逻辑处理器拥有相同的 physical id,但是 core id 不同,则说明这是一个多内核处理器。cpu cores 条目也可以表示是否支持多内核。
echo "logical CPU number:" |
判断CPU是否64位,检查cpuinfo中的flags区段,看是否有lm标识。
Are the processors 64-bit?
A 64-bit processor will have lm ("long mode") in the flags section of cpuinfo. A 32-bit processor will not.
or
lscpu
disk
df -h --total
查看硬盘和分区分布:lsblk
硬盘和分区的详细信息:fdisk -l
mem
cat /proc/meminfo
free -m
modify hostname
modify hostname
- uname -a 查看hostname
- hostname xxxxx 修改下,让hostname立刻生效。
- vi /etc/hosts 修改原hostname为 xxxxx
- vi /etc/sysconfig/network 修改原hostname为 xxxxx,这样可以让reboot重启后也生效
- reboot重启,uname -a 重新检查下。收工
reverse mapping checking getaddrinfo POSSIBLE BREAK-IN ATTEMPT
- Setup a Reverse DNS Record (aka PTR Record) for the SSH client
- Ensure UseDNS no and GSSAPIAuthentication no are set in /etc/ssh/sshd_config on the SSH server, then restart the sshd
- Confirm that /etc/hosts on the SSH server has an entry for the SSH client IP address and hostname
汇编语言程序设计-读书笔记-1
概述:
- 使用处理器指令代码进行程序设计.
- 不同的汇编器使用不同的语法编写.
处理器指令
二进制代码:
- 制造厂商预置在处理器内部.
- 处理器使用它来操作数据.
指令码处理
each instruction code set can contain one or more bytes of information thast instruct the processor to perform a specific task.
Instruction Pointer is used to help the processor keep track of which instruction codes have already been processed and what code is next in line to be processed.
Data Pointer is used to help the processor keep track of where the data area in memory starts.
This area is called the stack. As new data elements are placed in the stack, the pointer moves “down” in memory. As data is read from the stack, the pointer moves “up” in memory.
名词
- 指令码 instruction code
eclipse modify tab ui
problems
-
editor的title太大
在eclipse-mars/plugins/org.eclipse.ui.themes_1.1.0.v20150511-0913/css
中修改e4_default_gtk.css.MPartStack {
font-size: 9;
font-family: Liberation Sans;
swt-tab-renderer: null;
swt-tab-height: 22px;
swt-selected-tabs-background: #FFFFFF #ECE9D8 100%;
swt-simple: false;
swt-mru-visible: false;
} -
修改gtk样式
kate ~/.gtkrc-2.0style "gtkcompact" {
GtkButton::default_border={0,0,0,0}
GtkButton::default_outside_border={0,0,0,0}
GtkButtonBox::child_min_width=0
GtkButtonBox::child_min_heigth=0
GtkButtonBox::child_internal_pad_x=0
GtkButtonBox::child_internal_pad_y=0
GtkMenu::vertical-padding=1
GtkMenuBar::internal_padding=0
GtkMenuItem::horizontal_padding=4
GtkToolbar::internal-padding=0
GtkToolbar::space-size=0
GtkOptionMenu::indicator_size=0
GtkOptionMenu::indicator_spacing=0
GtkPaned::handle_size=4
GtkRange::trough_border=0
GtkRange::stepper_spacing=0
GtkScale::value_spacing=0
GtkScrolledWindow::scrollbar_spacing=0
GtkTreeView::vertical-separator=0
GtkTreeView::horizontal-separator=0
GtkTreeView::fixed-height-mode=TRUE
GtkWidget::focus_padding=0
}
class "GtkWidget" style "gtkcompact" -
插件编辑样式
eclipse-themes -
use gtk2
export SWT_GTK3=0
link
http://stackoverflow.com/questions/11805784/very-large-tabs-in-eclipse-panes-on-ubuntu
http://unix.stackexchange.com/questions/25964/reduce-eclipse-tab-size-with-gtk-theming
http://stackoverflow.com/questions/3124629/how-can-i-configure-the-font-size-for-the-tree-item-in-the-package-explorer-in-e/3970100
use gtk2