11 Jul 2014
Converting between tabs and spaces
Delete blank lines
Close all other windows
Move windows
ctrl-w r " rotate all windows
ctrl-w R " reversely rotate
ctrl-w x " extrange current window with its neighbour
ctrl-w [HJKL]
Command-T auto flush
Pathogen + Git submodules
git submodule init
git submodule update
Changelist
g; " jump back
g, " jump forwards
:changes
Jumplist
ctrl-o " back
ctrl-i " forward
ctrl-] " follow link in help
Visual Block
ctrl-v " like visual mode but select a block
:s/\%V_/ /g " match only on the selected block
Modal Editing
Implicit motion command |
Longhand equivalent |
c{motion} |
d{motion}i |
C |
d$a |
s |
xi |
S |
^C |
I |
^i |
File Explorer
lazy |
open file explorer |
:e. |
at current working directory |
:E |
at directory of current file |
Manipulating the filesystem
command |
action |
% |
create a new file |
d |
create a new directory |
R |
rename the file/directory |
D |
delete the file/directory |
Spell Checking
:set spell
to toggle it on and off
]s
to proceed to the next error
[s
previous error
z=
get a list of suggested corrections
zg
add a word to the spellfile
zw
remove a word from the spelling dictionary
29 Jun 2014
Use Hash#fetch
. It will raise a KeyError, making the problem obvious
Object#to_s
method is invoked automatically when it’s interpolated object.
eg: message = "This is the #{object}."
Use String#<<
, it mutates the original string and is faster
String#+
will create a new string
Create a symbol with spaces in it :"some string"
####Questions
What’s the meaning that Ruby 1.9 hashes are ordered
17 Jun 2014
To some degree, when we are adding behavior to the system, we are also changing behavior(load time, UI, etc)
10 Jun 2014
####Basic atomic classes of objects
- character
- numeric
- integer
- complex
- logical
####Vector vs List
Vector: objects of the same class
vector(<class>, <length>)
List: can contain objects of different classes
####Numbers
- default double precision real number
- 1L-> explicitly integer 1
-
Inf
1 / 0 = Inf
1 / Inf = 0
-
NaN: not a number
0 / 0 = NaN
####Attributes
- names, dimnames
- dimensions
- class
- length
- other user-defined attributes/metadata
- attributes()
####Assignment
<-
####Integer sequence
1:20
####Creating vectors
- c(0.5, 0.6)
- vector(“numeric”, length = 10)
####Explicit coercion
- as.class function
- Nonsensical coercion results in NAs
####Matrices
####Factors
####Missing values
- NA
- NaN
- is.na()
- is.nan()
- NA values have a class too.
- NaN is NA
- NA is not NaN
####Data frames
- row.names
- read.table() or read.csv()
- data.matrix()
####Names
R objects can have names
names()
List elements can also have names
dimnames()
###Subsetting
####Subsetting a Matrix
drop = FALSE
will result in a matrix
otherwise will result in a vector(in most case)
####Partial matching
x<-list(aardvark=1:5)
x$a #aardvark
x[["a", exact = FALSE]]
####Reading and writing data
- dput: single object
- dump: multiple objects
09 Jun 2014
####Modifier vs Matcher
Modifier eg: should, should_not
Matcher eg: <, ==, >
####Predicate matcher
class Zombie
def hungry?
true
end
end
Zombie.new.should be_hungry
####Pending
it "nothing"
xit "something" do
# ...
end
it "something" do
pending
# ...
end