Peterfei

上主是我的牧者,我实在一无所缺


  • 首页

  • 归档

  • 标签

Mac下sublime3快捷键备忘

发表于 2014-09-27   |  

打开/前往

  • ⌘^A (对齐)
  • Alt鼠标单击 [多行选择]
  • ⌘T [前往文件]
  • ⌘⌃P | 前往项目 |
  • ⌘R | 前往 method |
  • ⌘⇧P | 命令提示 |
  • ⌃G | 前往行 |
  • ⌃ ` | python 控制台 |

    编辑

  • ⌘L | 选择行 (重复按下将下一行加入选择) |

  • ⌘D | 选择词 (重复按下时多重选择相同的词进行多重编辑) |
  • ⌃⇧M | 选择括号内的内容 |
  • ⌘⇧↩ | 在当前行前插入新行 |
  • ⌘↩ | 在当前行后插入新行 |
  • ⌃⇧K | 删除行 |
  • ⌘KK | 从光标处删除至行尾 |
  • ⌘K⌫ | 从光标处删除至行首 |
  • ⌘⇧D | 复制(多)行 |
  • ⌘J | 合并(多)行 |
  • ⌘KU | 改为大写 |
  • ⌘KL | 改为小写 |
  • ⌘ / | 注释 |
  • ⌘⌥ / | 块注释 |
  • ⌘Y | 恢复或重复 |
  • ⌘⇧V | 粘贴并自动缩进 |
  • ⌃ space | 自动完成(重复按下选择下一个提示) |
  • ⌃M | 跳转至对应的括号 |

查找/替换

  • ⌘F | 查找 |
  • ⌘⌥F | 替换 |
  • ⌘⌥G | 查找下一个符合当前所选的内容 |
  • ⌘⌃G | 查找所有符合当前所选的内容进行多重编辑 |
  • ⌘⇧F | 在所有打开的文件中进行查找 |

ruby api设计

发表于 2014-09-27   |  

#先看一段source code

1
2
3
4
5
6
7
8
9
10
11
f = File.open("myfile.txt", 'w')
f.write("Lorem ipsum dolor sit amet")
f.write("Lorem ipsum dolor sit amet")
f.close
||
\/
# using block
File.open("myfile.txt", 'w') do |f|
f.write("Lorem ipsum dolor sit amet")
f.write("Lorem ipsum dolor sit amet")
end

#如上,是使用block后的效果,再来一段

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# without code block
def send_message(msg)
socket = TCPSocket.new(@ip, @port) # Pre-
socket.puts(msg)
response = socket.gets
ensure
socket.close # Post-
end
end
||
\/
# with code block
def send_message(msg)
connection do |socket|
socket.puts("foobar")
socket.gets
end
end
def connection
socket = TCPSocket.new(@ip, @port) # Pre-
yield(socket)
ensure
socket.close # Post-
end
end

#Module 的使用

1
2
3
4
5
6
7
8
9
module Mixin
def foo
puts "foo"
end
end
class A
include Mixin
end
A.new.foo # foo

.使用extend(Mod)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
module Mixin
def foo
puts "foo"
end
class A
extend Mixin
end
end
A.extend(Mixin)
A.foo # class method
the same as
class << A
include Mixin
end

.obj.extend(Mod)
如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
module Mixin
def foo
puts "foo"
end
end
a = "test"
a.extend(Mixin)
a.foo # foo
the same as
class << a
include Mixin
end
b = "demo"
b.foo # NoMethodError

.Mixin with class methods

1
2
3
4
5
6
7
8
9
10
11
12
13
14
module Mixin
def foo
puts "foo"
end
module ClassMethods
def bar
puts "bar"
end
end
end
class MyClass
include Mixin
extend Mixin::ClassMethods
end

等同于如下代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
module Mixin
# self.included is a hook method
def self.included(base)
base.extend(ClassMethods)
end
def foo
puts "foo"
end
module ClassMethods
def bar
puts "bar"
end
end
end
class MyClass
include Mixin
end

等同于:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
module Mixin
def self.included(base)
base.extend(ClassMethods)
base.send(:include, InstanceMethods)
end
module InstanceMethods
def foo
puts "foo"
end
end
module ClassMethods
def bar
puts "bar"
end
end
end
class MyClass
include Mixin
end

Magento 该如何多语言翻译

发表于 2014-09-25   |  

一般的,登陆后台,e.g.选择[目录]->[管理产品]->[choose store view],如图示:
choose store view

就可以编辑中文内容,同理,选择[目录]->[管理产品]->[choose store view],选择英文,就可以编辑英文产品。
编辑’CMS’,如[页面],选择一静态页面,如[About Us],点编辑后,按”ctrl”健,在商店界面,点’英文’,界面会着色,之后选内容项,就可以编辑英文内容,同理,再新建一页面,复制’About Us’的页面信息,如标题,网址等,按”ctrl”健,在商店界面,点’中文’,界面会着色,之后选内容项,就可以编辑中文内容,前台就已经对应生成中英文双语的关于我们了,是不是很Cool。
choose store view

Rails中的子查询

发表于 2014-09-22   |  

###大致是这样子的

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
def favarate_post options={}
subselect = Favarate.send(
:construct_finder_sql,
:select =>"post_id",
:conditions=>{:blog_id=>self.id},
:order=>"published_at desc",
:limit => option[:limit]||10,:offset=>option[:offset]
)
Post.find(:all,:conditions =>'posts.id in #{subselect}',:order =>"published_at DESC")
end
```
construct_finder_sql 同下句SQL类似:
```sql
SELECT * FROM posts WHERE posts.id IN (
SELECT post_id FROM favorites WHERE blog_id = 42 ORDER BY published_at DESC LIMIT 10 OFFSET 10
) ORDER BY published_at DESC

圣经金句分享

发表于 2014-09-18   |  
  • 爱是含忍的,爱是慈祥的,爱不嫉妒,不夸张,不自大,不作无礼的事,不求己益,不动怒,不图谋恶事,不以不义为乐,却与真理同乐:凡事包容,凡事相信,凡事盼望,凡事忍耐。(格前13:4-7)
  • 你们的身体是圣神的宫殿。(格前6:19)
  • 天主为爱他的人所准备的,是眼所未见,耳所未闻,人心所未想到的。(格前2:9)
  • 我是葡萄树,你们是枝条,那住在我内,我也住在他内的,就结许多的果实,因为离了我,你们什么也不能作!
  • 那含泪播种的,必含笑获享收成。(咏126:5)
  • 凡高举自己的,必被贬抑;凡贬抑自己的,必被高举。(玛23:12)
  • 天主使太阳上升,光照恶人,也光照善人;降雨给义人,也给不义的人,你们若只爱那些爱你们的人,你们还有什么赏报呢?(玛5:45-46)
  • 凡是求的,就必得到;找的,就必找到;敲的,就必给他开。(玛7:8)
  • 人纵然赚得了全世界,却赔上了自己的灵魂,为他有什么益处?(玛16:26)
  • 不要论断人,以免被论断。(玛7:1)
  • 你用什么尺度量人,也要被什么尺度量。(玛7:2)
  • 你当机警如蛇,纯良似鸽。(玛10:16)
  • 你们白白得来的,也要白白分施。(玛10:8)
  • 天主是神,应当以心神以真理去朝拜祂。(若4:24)
  • 知识只会使人傲慢自大,爱德才能立人。(格前8:1)
  • 小量播种的,也要小量收获;大量播种的,也要大量收获。(格后9:6)
    主是我的牧者
1…141516
peterfei

peterfei

peterfei|技术|上主是我的牧者

79 日志
14 分类
62 标签
RSS
github
© 2025 peterfei
由 Hexo 强力驱动
主题 - NexT.Mist