🚙

💨 💨 💨

×

  • Categories

  • Archives

  • Tags

  • About

redis概要之数据类型

Posted on 07-11-2015 | In DB

Redis简介要义

  • Redis运行在内存中但是可以持久化到磁盘, 重启的时候可以再次加载进行使用

  • Redis的所有操作都是原子性的,同时Redis还支持对几个操作全并后的原子性执行

  • Redis支持二进制案例的 Strings, Lists, Hashes, Sets 及 Ordered Sets 数据类型操作

  • Redis支持数据的备份,即master-slave模式的数据备份

Redis数据类型

Redis的数据类型很重要, 这是他做很多事情的基础, 不理解的话很难用好

. . .

python和lua数据类型的比较

Posted on 07-11-2015 | In Misc

Python比较特殊的数据类型:

List []

例如 :

#!/usr/bin/python
# -*- coding: UTF-8 -*-

list = [ 'runoob', 786 , 2.23, 'john', 70.2 ]
tinylist = [123, 'john']

print list # 输出完整列表
print list[0] # 输出列表的第一个元素
print list[1:3] # 输出第二个至第三个的元素
print list[2:] # 输出从第三个开始至列表末尾的所有元素
print tinylist * 2 # 输出列表两次
print list + tinylist # 打印组合的列表

以上实例输出结果:

['runoob', 786, 2.23, 'john', 70.2]
runoob
[786, 2.23]
[2.23, 'john', 70.2]
[123, 'john', 123, 'john']
['runoob', 786, 2.23, 'john', 70.2, 123, 'john']

Tuple(元祖)(),相当于只读列表,不可以二次赋值

tuple = ( 'runoob', 786 , 2.23, 'john', 70.2 ), 除了元祖用()而list用[], 而且元祖只是可读的, 其他的跟list一毛一样

dictionary(字典){},key值对

#!/usr/bin/python
# -*- coding: UTF-8 -*-

dict = {}
dict['one'] = "This is one"
dict[2] = "This is two"

tinydict = {'name': 'john','code':6734, 'dept': 'sales'}


print dict['one'] # 输出键为'one' 的值
print dict[2] # 输出键为 2 的值
print tinydict # 输出完整的字典
print tinydict.keys() # 输出所有键
print tinydict.values() # 输出所有值

输出结果为:

This is one
This is two
{'dept': 'sales', 'code': 6734, 'name': 'john'}
['dept', 'code', 'name']
['sales', 6734, 'john']

lua比较特殊的数据类型

lua变量

变量在使用前,必须在代码中进行声明,即创建该变量。

编译程序执行代码之前编译器需要知道如何给语句变量开辟存储区,用于存储变量的值。

Lua 变量有三种类型:全局变量、局部变量、表中的域。

Lua 中的变量全是全局变量,那怕是语句块或是函数里,除非用 local 显式声明为局部变量。

局部变量的作用域为从声明位置开始到所在语句块结束。

变量的默认值均为 nil。

test.lua 文件脚本
a = 5               -- 全局变量
local b = 5 -- 局部变量

function joke()
c = 5 -- 全局变量
local d = 6 -- 局部变量
end

joke()
print(c,d) --> 5 nil

do
local a = 6 -- 局部变量
b = 6 -- 全局变量
print(a,b); --> 6 6
end

print(a,b) --> 5 6

执行以上实例输出结果为:

$ lua test.lua 
5 nil
6 6
5 6

lua的特有的东西table(表)

在 Lua 里,table 的创建是通过”构造表达式”来完成,

最简单构造表达式是{},用来创建一个空表。

也可以在表里添加一些数据,直接初始化表:

-- 创建一个空的 table
local tbl1 = {}

-- 直接初始表
local tbl2 = {"apple", "pear", "orange", "grape"}

Lua 中的表(table)其实是一个”关联数组”(associative arrays),数组的索引可以是数字或者是字符串。

-- table_test.lua 脚本文件
a = {}
a["key"] = "value"
key = 10
a[key] = 22
a[key] = a[key] + 11
for k, v in pairs(a) do
print(k .. " : " .. v)
end

脚本执行结果为:

$ lua table_test.lua 
key : value
10 : 33

不同于其他语言的数组把 0 作为数组的初始索引,在 Lua 里表的默认初始索引一般以 1 开始。

-- table_test2.lua 脚本文件
local tbl = {"apple", "pear", "orange", "grape"}
for key, val in pairs(tbl) do
print("Key", key)
end

脚本执行结果为:

$ lua table_test2.lua 
Key 1
Key 2
Key 3
Key 4

table 不会固定长度大小,有新数据添加时 table 长度会自动增长,没初始的 table 都是 nil。

-- table_test3.lua 脚本文件
a3 = {}
for i = 1, 10 do
a3[i] = i
end
a3["key"] = "val"
print(a3["key"])
print(a3["none"])

脚本执行结果为:

$ lua table_test3.lua 
val
nil

epoll扼要总结

Posted on 06-22-2015 | In Linux

epoll 编程接口

epoll API是Linux系统专有的,在2.6版中新增。

epoll API的核心数据结构称作epoll实例,它和一个打开的文件描述符相关联。这个文件
描述符不是用来做I/O操作的,相反,它是内核数据结构的句柄,这些内核数据结构实现了两
个目的。

  • 记录了在进程中声明过的感兴趣的文件描述符列表-interest list(兴趣列表)。
  • 维护了处于I/O就绪态的文件描述符列表-ready list(就绪列表)。

ready list中的成员是interest list的子集。

对于由epoll检查的每一个文件描述符,我们可以指定一个位掩码来表示我们感兴趣的事
件。这些位掩码同poll()所使用的位掩码有着紧密的关联。

. . .

socket可读可写条件与非阻塞connect或accept浅析

Posted on 06-22-2015 | In NP

socket可读的条件:

  • socket的接收缓冲区中的数据字节大于等于该socket的接收缓冲区低水位标记的当前大小。对这样的socket的读操作将不阻塞并返回一个大于0的值(也就是返回准备好读入的数据)。我们可以用SO_RCVLOWAT这个socket选项来设置该socket的低水位标记。对于TCP和UDP的socket而言,其缺省值为1.
  • 该连接的读这一半关闭(也就是接收了FIN的TCP连接)。对这样的socket的读操作将不阻塞并返回0
  • 给监听套接字准备好新连接
  • 有一个socket有异常错误条件待处理.对于这样的socket的读操作将不会阻塞,并且返回一个错误(-1),errno则设置成明确的错误条件.这些待处理的错误也可通过指定socket选项SO_ERROR调用getsockopt来取得并清除;

. . .

Top 500 English sentences for daily life

Posted on 06-21-2015 | In English

问候与寒暄

  1. How are you doing? 你最近怎么样?
  2. I’m so glad to meet you. 我很高兴见到你。
  3. How are you doing today? 你今天过得咋样?
  4. How’s it going? 最近过得怎么样?

提供与寻求帮助

  1. How can I help you? 我能帮你什么吗?(接到陌生电话第一句可以说这个)
  2. Could you help me, please? 你能帮我一下吗?
  3. Could you help me with this? 你能帮我一下这个吗?
  4. Do you need any help? 你需要帮助吗?
  5. Can I help you? 我能帮你吗?
  6. Is there anything I can do for you? 我能为你做点什么吗?

表达观点与回应

  1. What do you think? 你觉得怎么样?
  2. What do you think about it? 你咋看这件事?
  3. I totally agree with you. 我完全同意你。
  4. I couldn’t agree more. 我完全同意。
  5. I don’t think so. 我不这么认为。
  6. That’s exactly what I was thinking. 这正是我所想的。
  7. You’ve got a point. 你说得有道理。
  8. It doesn’t make sense. 这说不通。
  9. Does it make sense? 这个说得通有道理吗?
  10. I’m not sure about that. 我不太确定。
  11. I have no idea. 我完全不知道。
  12. I’m not in the mood. 我没心情。
  13. That sounds great. 听起来很棒。
  14. It’s not a big deal. 这没什么大不了的。
  15. It’s not my cup of tea. 那不是我的兴趣所在。
  16. It’s none of your business. 这不关你的事。
  17. Don’t take it personally. 别往心里去。
  18. Don’t take it seriously. 别太当真。
  19. Better late than never. 迟到总比不到好。

请求重复、解释与放慢语速

  1. Could you repeat that, please? 你能再重复一遍吗?
  2. Could you please repeat that? 你可以再说一遍吗?
  3. Could you please repeat that more slowly? 你能再慢点重复一遍吗?
  4. Sorry, I didn’t catch that. 抱歉,我没听清。
  5. I’m sorry, I didn’t catch your name. 很抱歉,我没听清你的名字。
  6. I’m afraid I don’t understand. 恐怕我不明白。
  7. Could you explain that to me? 你能跟我解释一下吗?
  8. Could you speak a bit slower, please? 你可以说慢一点吗?
  9. Could you speak more slowly? 你能说得慢一点吗?
  10. Could you speak a little slower? 你能说慢得一点吗?

询问个人信息

  1. Where are you from? 你来自哪里?
  2. What do you do in your free time? 你空闲时间做什么?
  3. Do you speak English? 你会说英语吗? (不说 can u speak eng)
  4. What’s your favorite food? 你最喜欢的食物是什么?
  5. What’s your favorite movie? 你最喜欢的电影是什么?
  6. Do you have any hobbies? 你有什么爱好吗?
  7. How long have you been living here? 你在这里住了多久了?
  8. What’s your favorite type of music? 你最喜欢哪种类型的音乐?
  9. Do you have any dietary restrictions? 你有什么饮食限制吗?

问路与询问地点相关信息

  1. Excuse me, where is the restroom? 请问洗手间在哪里?
  2. Could you tell me where the restroom is? 你能告诉我卫生间在哪里吗?
  3. Can you tell me where the nearest station is? 你能告诉我最近的车站在哪里吗?
  4. Could you tell me the way to the airport? 你能告诉我去机场的路吗?
  5. How do I get to the airport? 我怎么去机场?
  6. How do I get to the train station? 我怎么去火车站?
  7. How do I get to the main square? 怎么去主广场?
  8. How can I get to the nearest subway station? 最近的地铁站怎么走?
  9. Where is the nearest ATM? 最近的取款机在哪里?
  10. Where is the nearest train station? 最近的火车站在哪里?
  11. Where is the nearest subway station? 最近的地铁站在哪里?
  12. Is there a hospital nearby? 附近有医院吗?
  13. Is there a supermarket nearby? 这里附近有超市吗?
  14. Is there a place to park nearby? 附近有停车的地方吗?
  15. Is there a place to exchange money nearby? 附近有兑换货币的地方吗?
  16. Are there any beaches nearby? 附近有沙滩吗?
  17. Are there any vegetarian restaurants around? 附近有素食餐厅吗?
  18. Is there a good place for hiking nearby? 附近有适合徒步的地方吗?
  19. Is there a good place for shopping? 你知道购物的好地方吗?
  20. Where can I find a pharmacy? 你知道哪里可以找到药店吗?
  21. Where can I find a good coffee shop? 哪里可以找到不错的咖啡馆?
  22. Where can I find a public restroom? 哪里有公共厕所?
  23. Where can I rent a car? 哪里可以租车?
  24. Where can I buy a SIM card for my phone? 哪里可以买到手机的SIM卡?
  25. I’m looking for a coffee shop. 我在找一家咖啡店。
  26. I’m lost. 我迷路了。
  27. I’m trying to find… 我在试图找…… (可根据情境补充具体地点)

时间相关询问

  1. What time is it now? 现在几点了?
  2. What time is it? 现在几点?
  3. What time does the meeting start? 会议几点开始?
  4. What time does the store close? 这家店几点关门?
  5. What time do we need to leave? 我们需要几点离开?
  6. What time do you usually have dinner? 你通常什么时候吃晚饭?
  7. What time is check - out? 退房时间是几点?
  8. What time does the last bus leave? 最后一班公交车几点发车?
  9. How long will it take? 需要多久?
  10. How long will it take to get there? 到那里需要多长时间?

购物、餐饮与消费相关

  1. How much is this? 这个多少钱?
  2. How much does it cost? 这个多少钱?
  3. How much does it cost for one night? 一晚多少钱?
  4. How much does it cost to get in? 入场费是多少?
  5. Could I get the bill, please? 我可以结账了吗?
  6. Can I have the check, please? 可以请给我账单吗?
  7. I’d like to have this, please. 我想要这个。
  8. I’d like a table for two, please. 我想要一张两人桌,谢谢。
  9. I’d like to book a table for two. 我想订一个两个人的桌子。
  10. I’d like to book a room for two nights. 我想订一个房间住两晚。
  11. Do you take credit cards? 你们接受信用卡吗?
  12. Do you accept credit cards here? 这里接受信用卡吗?
  13. Can I pay in cash? 我可以用现金支付吗?
  14. Can I pay by credit card? 我可以刷卡吗?
  15. Can I pay in installments? 我可以分期付款吗?
  16. Do you have any special discounts? 你们有特别折扣吗?
  17. Is it possible to get a discount? 可以打折吗?
  18. What would you like to drink? 你想喝点啥?
  19. Can I have a cup of coffee, please? 我可以来杯咖啡吗?
  20. Can I have a glass of water, please? 请给我一杯水好吗?
  21. Do you have any vegetarian options? 你们有素食选择吗?
  22. What’s the best thing on the menu? 菜单上最好的菜是什么?
  23. Could you recommend a good restaurant? 你能推荐一家好的餐厅吗?
  24. Could you recommend a good restaurant around here? 你能推荐一个附近不错的餐厅吗?
  25. Could you recommend a good hotel around here? 你能推荐一家附近不错的酒店吗?
  26. Could you recommend a good book for me? 你能给我推荐一本好书吗?
  27. Could you recommend something? 你能推荐点什么吗?
  28. What do you recommend? 你推荐什么?
  29. Could you recommend some local dishes? 你能推荐些当地的菜吗?
  30. Could you recommend a local dish to try? 你能推荐一个当地菜品吗?
  31. I’d love to try the local food. 我很想尝试当地的食物。
  32. Can I get this to - go? 我可以打包这个吗?
  33. Can you pack this to go? 你能把这个打包吗?
  34. I’ll have the same thing as them. 我点跟他们一样的。
  35. I’m just browsing, thanks. 我只是随便看看,谢谢。
  36. I’m just looking, thanks. 我只是随便看看,谢谢。
  37. Do you have this in a different color? 你们有其他颜色的吗?
  38. Can I try this on? 我可以试穿一下吗?
  39. Can I have a copy of the receipt? 我可以要一份收据吗?
  40. Can you give me a receipt for this? 你可以给我这个的收据吗?
  41. That’s a rip - off. 这简直是抢钱。
  42. That’s too expensive. 太贵了。

旅游与活动相关

  1. Can you recommend a good place to visit? 你能推荐个好玩的地方吗?
  2. Could you suggest some places to visit? 你可以推荐一些值得去的地方吗?
  3. What are the main attractions in this area? 这一带的主要景点是什么?
  4. Do you have any brochures or maps? 你们有宣传册或地图吗?
  5. Do you have any brochures about local attractions? 你有关于当地景点的宣传册吗?
  6. Are there any events happening this week? 这周有活动吗?
  7. Do you offer guided tours? 你们提供导游服务吗?
  8. Can I take photos here? 我能在这里拍照吗?
  9. Is it safe to walk around at night? 晚上在这里走安全吗?
  10. What’s the temperature like today? 今天的温度怎么样?
  11. What’s the weather like today? 今天天气怎么样?
  12. What’s the weather forecast for tomorrow? 明天的天气预报是什么?
  13. I’m interested in learning more about your culture. 我对了解你的文化很感兴趣。
  14. Could you tell me more about your culture? 你能多告诉我一些关于你们文化的事情吗?
  15. Can I make an international call here? 我可以在这里打国际电话吗?
  16. Do you have Wi - Fi here? 这里有无线网络吗?
  17. What’s your Wi - Fi password? 你们的Wi - Fi密码是什么?
  18. How do I connect to the Wi - Fi here? 我该如何连接这里的Wi - Fi?
  19. Can I leave my luggage here? 我可以把行李寄存在这里吗?
  20. What are the opening hours? 营业时间是几点到几点?

日常交流其他表达

注: 都很重要, 就不加粗了

  1. Let me think about it. 让我想一想。
  2. Let’s take a break. 我们休息一下吧。
  3. Let’s keep in touch. 我们保持联系吧。
  4. I’m running late. 我快要迟到了。
  5. I’m on my way. 我正在路上。
  6. I’ll be back in a minute. 我马上回来。
  7. I’ll be right back. 我马上回来。
  8. I’ll take care of it. 我会处理的。
  9. I’ll get back to you. 我会回复你的。
  10. I’ll give it a shot. 我试试看。
  11. I’ll cross that bridge when I come to it. 到时候再说。
  12. I’ll keep that in mind. 我会记住的。
  13. I’m looking forward to it. 我很期待。
  14. I’m looking forward to meeting you. 我很期待见到你。
  15. I’m looking forward to working with you. 我很期待和你合作。
  16. I’m proud of you. 我为你感到骄傲。
  17. Congratulations! 恭喜!
  18. You did a great job! 你干得很好!
  19. You’re a lifesaver. 你真是我的救星。
  20. That’s very kind of you. 你真是太好了。
  21. Thank you for your help! 感谢你的帮助!
  22. Thanks for your help, I really appreciate it. 谢谢你的帮助,我真的很感激。
  23. You’re welcome. 不客气。
  24. Don’t mention it. 别客气。
  25. It’s my pleasure. 这是我的荣幸。
  26. Sorry, I’m late. 很抱歉我迟到了。
  27. I’m sorry to bother you. 很抱歉打扰你。
  28. I’m sorry to interrupt. 很抱歉打断了。
  29. Sorry for the inconvenience. 抱歉造成不便。
  30. Sorry for the trouble. 抱歉添麻烦了。
  31. I’m sorry, I didn’t mean to. 抱歉,我不是故意的。
  32. It doesn’t matter. 没关系。
  33. That’s not a problem. 那不是问题。
  34. Don’t worry about it. 别担心。
  35. Please don’t worry about it. 不要担心这件事。
  36. Take it easy. 别紧张,放轻松。
  37. Relax. 放松。
  38. Don’t lose your temper. 别发脾气。
  39. Don’t make a scene. 别闹了。
  40. Don’t push me. 别逼我。
  41. Don’t beat around the bush. 别拐弯抹角。
  42. Don’t jump to conclusions. 别急着下结论。
  43. Don’t judge a book by its cover. 别以貌取人。
  44. Don’t judge too quickly. 别太快下结论。
  45. Don’t cry over spilled milk. 覆水难收。
  46. Don’t put all your eggs in one basket. 别把所有鸡蛋放在一个篮子里。
  47. Don’t put the cart before the horse. 本末倒置。
  48. Don’t bite off more than you can chew. 不要贪多嚼不烂。
  49. Don’t burn bridges. 不要断了后路。
  50. Don’t cry wolf. 别发假警报。
  51. Let’s call it a day. 今天就到这里吧。
  52. Let’s get started. 我们开始吧。
  53. Let’s make a move. 我们行动吧。
  54. Let’s grab some coffee. 我们去喝杯咖啡吧。
  55. Let’s grab a bite. 一起吃点东西吧。
  56. Let’s split the bill. 我们分摊账单吧,我们AA吧。
  57. Let’s go the extra mile. 我们再加把劲。
  58. Let me sleep on it. 让我再想想。
  59. Let me explain. 让我解释一下。
  60. Time flies! 时光飞逝。
  61. Time heals all wounds. 时间会治愈一切。
  62. Time will tell. 时间会证明一切。
  63. Actions speak louder than words. 行动胜于言语。
  64. Practice makes perfect. 熟能生巧。
  65. Better safe than sorry. 宁可小心也不要后悔。
  66. It’s better to be safe than sorry. 小心为上。
  67. You can’t have your cake and eat it too. 鱼与熊掌不可兼得。
  68. It’s not rocket science. 这没那么复杂。
  69. It’s a piece of cake. 小菜一碟。
  70. It’s a long story. 说来话长。
  71. It’s a storm in a teacup. 小题大做。
  72. It’s the tip of the iceberg. 这是冰山一角。
  73. It’s a win-win situation. 双赢的局面。
  74. It’s a blessing in disguise. 因祸得福。
  75. It’s not the end of the world. 这不是世界末日。
  76. It’s water under the bridge. 过去的事就算了。
  77. It’s now or never. 机不可失。
  78. You’ve gone too far. 你太过分了。
  79. You nailed it! 你搞定了。
  80. You’ve made my day. 你让我今天非常开心。
  81. You’re as cool as a cucumber. 你真沉着冷静。
  82. I’m all ears. 我洗耳恭听。
  83. I’m all set. 我都准备好了。
  84. I’m good at multitasking. 我擅长同时处理多项任务。
  85. I’m over the moon. 我开心极了。
  86. I’m feeling blue. 我有点忧郁。
  87. I’m feeling under the weather. 我感觉不太舒服。
  88. I’m sick and tired of it. 我厌倦了。
  89. I’m broke. 我没钱了。
  90. I’m in a hurry. 我赶时间。
  91. I’m in hot water. 我有麻烦了。
  92. I’m behind schedule. 我进度落后了。
  93. I’m on the fence. 我还没决定。
  94. I’m starving. 我快饿死了。
  95. That’s ridiculous. 那太荒谬了。
  96. That’s a no-brainer. 这还用想吗。
  97. That’s the last straw. 这是最后一根稻草。
  98. That’s food for thought. 值得深思。
  99. Count me in. 算我一个。
  100. Cross your fingers. 祝你好运。
  101. Keep your fingers crossed. 祝你好运。
  102. Keep up the good work. 继续保持好表现。
  103. Keep your chin up. 打起精神。
  104. Break a leg! 祝你好运。
  105. Don’t blow it. 别搞砸了。
  106. Don’t hold your breath. 别抱太大希望。
  107. Don’t put off till tomorrow what you can do today. 今日事今日毕。
  108. I’ll take your word for it. 我相信你说的。
  109. I can manage it. 我能应付。
  110. I can’t wait! 我等不及了!
  111. I can’t hear you clearly. 我听不清楚你说的。
  112. I forgot to bring my wallet. 我忘了带钱包。
  113. I’m afraid I can’t make it. 我恐怕做不到。
  114. I’m afraid I can’t help you. 我恐怕帮不了你。
  115. Can I borrow your pen? 我能借你的笔吗?
  116. Could you lend me a pen? 你能借我一支笔吗?
  117. Can I have an extra blanket, please? 我可以要一条额外的毯子吗?
  118. Can I have extra towels, please? 我可以要多一些毛巾吗?
  119. Do you offer laundry services here? 这里提供洗衣服务吗?
  120. Could you pass me the salt, please? 你能递给我盐吗?
  121. How do you spell that? 这个怎么拼写?
  122. What’s the emergency contact number here? 这里的紧急联系电话是多少?
  123. What’s the emergency number here? 这里的紧急联系电话是多少?
  124. Do you have any plans for the weekend? 你周末有什么计划吗?
  125. Let’s catch up later. 我们稍后聊。
  126. Are you kidding me? 你在开玩笑吧。
  127. You’ve got to be kidding me. 你一定是在开玩笑。
  128. Can I get a refund? 我可以退款吗?
  129. Could I have a refill, please? 我可以再加点吗?
  130. Is tipping customary here? 在这里小费是习惯吗?
  131. Where can I exchange currency? 我在哪里可以兑换货币?
  132. What’s the exchange rate today? 今天的汇率是多少?
  133. I’d like to exchange some currency. 我想兑换一些货币。
  134. Do I need a reservation? 我需要预订吗?
  135. Can I reserve a table for tonight? 我可以预定今晚的餐桌吗?
  136. Do I need a ticket to enter this place? 进入这个地方需要票吗?
  137. Can I use your phone to make a local call? 我可以用你的电话打个本地电话吗?
  138. Can I get a guide to explain the history here? 我可以找一个导游来讲解这里的历史吗?
  139. Could you take a picture for me? 你可以帮我拍张照片吗?
  140. Could you write it down for me? 你能帮我写下来吗?
  141. Could you write that down for me? 你能帮我写下来吗?
  142. Please feel free to contact me. 请随时联系我。
  143. Do you mind if I join you? 你介意我加入吗?
  144. Do you mind if I sit here? 你介意我坐在这吗?
  145. This is not what I expected. 这不是我期待的。
  146. Let me know if you need anything. 如果你需要什么,请告诉我。
  147. I have nothing to do with it. 这与我无关。
  148. It’s my turn. 轮到我了。
  149. What’s the plan? 计划是什么?
  150. What’s the next step? 下一步是什么?
  151. It’s up to you. 这由你决定,这取决于你。
  152. That’s up to you. 这取决于你。
  153. The ball is in your court. 轮到你行动了。
  154. It’s up in the air. 还不确定。
  155. Stay tuned. 敬请关注。
  156. I’m just joking. 我只是开玩笑。
  157. Don’t judge a person by appearance. 不要以貌取人。

英语俗语谚语

注: 都很重要, 就不加粗了

  1. All roads lead to Rome. 条条大路通罗马。
  2. An apple a day keeps the doctor away. 一天一苹果,医生远离我。
  3. Out of sight, out of mind. 眼不见,心不烦。
  4. Don’t put all your eggs in one basket. 别把所有的鸡蛋放在一个篮子里(不要孤注一掷)。
  5. Easy come, easy go. 来得容易去得快。
  6. Knowledge is power. 知识就是力量。

2. Don’t let the cat out of the bag

意思:别泄露秘密。
比喻用法:指不小心提前说出本该保密的事情。
由来:

  • 起源于中世纪欧洲市场,有个说法是有人用装在袋子里的猫来冒充猪,买家若提前看袋子就识破了骗局,“猫就从袋子里出来了”。

3. Let’s play it by ear

意思:我们到时候看情况再决定。
比喻用法:不提前计划,临场应对。
由来:

  • 原指音乐中“凭耳朵弹奏”,即不看乐谱、即兴发挥。
  • 引申为处理事情时不设定严格计划,根据实际情况灵活应对。

4. Let’s turn over a new leaf

意思:让我们重新开始 / 改过自新。
比喻用法:做出积极改变,开始新生活或改正错误。
由来:

  • “Leaf” 原指书页,“翻一页”意味着翻过旧的、开始新的篇章。

5. Let’s cut to the chase

意思:我们直接进入重点吧。
比喻用法:不要废话,直接讲最重要的部分。
由来:

  • 源自早期电影术语,特别是西部片中,观众最期待的是“追车场景”(chase scenes),所以跳过无聊对话直接进入高潮场面。

6. You’re barking up the wrong tree

意思:你搞错对象了 / 找错地方了。
比喻用法:在错误的方向上努力或责怪了错的人。
由来:

  • 来源于狩猎场景,狗对着没有猎物的树狂吠,误以为猎物藏在那里。

7. You’re pulling my leg

意思:你在逗我 / 开我玩笑吧。
比喻用法:用于质疑对方说的话太离谱,可能是在开玩笑。
由来:

  • 有多种说法,其中一种认为它起源于街头小偷作案时拉拽他人腿部以转移注意力。

8. I’m on cloud nine

意思:我高兴极了 / 我欣喜若狂。
比喻用法:描述极度开心或满足的情绪。
由来:

  • “Cloud nine” 代表最顶层的云,比喻达到最高层次的快乐。其来源可能与气象分级有关(如气象局曾用第九类云指高积云)。

9. That’s the icing on the cake

意思:这真是锦上添花。
比喻用法:事情本已很好,又额外加上一点更好的结果。
由来:

  • 原指蛋糕上本已好吃的糖霜(icing),比喻已有好事上的“附加好处”。

const和volatile和mutable讲解

Posted on 05-24-2015 | In Misc

const关键字

const 是比较常见的关键字, 也是非常好的预防错误的手段.

const 修饰普通变量和指针

const 修饰变量,一般有两种写法:

const TYPE value;

TYPE const value;

这两种写法在本质上是一样的。它的含义是:const 修饰的类型为 TYPE 的变量 value 是不可变的。对于一个非指针的类型 TYPE,无论怎么写,都是一个含义,即 value 值不可变。 例如:

const int nValue;    //nValue 是 const

int const nValue;    //nValue 是 const

. . .

关系型数据库与NoSQL的爱恨情仇

Posted on 05-20-2015 | In DB

NoSQL因关系数据库的不足而生

随着互联网的不断发展,各种类型的应用层出不穷,所以导致在这个云计算的时代,

对技术提出了更多的需求,主要体现在下面这四个方面:

  • 低延迟的读写速度:应用快速地反应能极大地提升用户的满意度;
  • 支撑海量的数据和流量:对于搜索这样大型应用而言,需要利用PB级别的数据和能应对百万级的流量;
  • 大规模集群的管理:系统管理员希望分布式应用能更简单的部署和管理;

庞大运营成本的考量:IT经理们希望在硬件成本、软件成本和人力成本能够有大幅度地降低;

目前世界上主流的存储系统大部分还是采用了关系型数据库,其主要有一下优点:

  • 事务处理—保持数据的一致性;
  • 由于以标准化为前提,数据更新的开销很小(相同的字段基本上只有一处);
  • 可以进行Join等复杂查询。

虽然关系型数据库已经在业界的数据存储方面占据不可动摇的地位,但是由于其天生的几个限制,

使其很难满足上面这几个需求:

  • 扩展困难:由于存在类似Join这样多表查询机制,使得数据库在扩展方面很艰难;
  • 读写慢:这种情况主要发生在数据量达到一定规模时由于关系型数据库的系统逻辑非常复杂,使得其非常容易发生死锁等的并发问题,所以导致其读写速度下滑非常严重;
  • 成本高:企业级数据库的License价格很惊人,并且随着系统的规模,而不断上升;
  • 有限的支撑容量:现有关系型解决方案还无法支撑Google这样海量的数据存储;

业界为了解决上面提到的几个需求,推出了多款新类型的数据库,并且由于它们在设计上和传统的NoSQL数据库相比有很大的不同,
所以被统称为“NoSQL”系列数据库。

总的来说,在设计上,它们非常关注对数据高并发地读写和对海量数据的存储等,与关系型数据库相比,它们在架构和数据模型方量面做了“减法”,

而在扩展和并发等方面做了“加法”。

现在主流的NoSQL数据库有MongoDB和Redis以及BigTable、Hbase、Cassandra、SimpleDB、CouchDB、等。

接下来,将关注NoSQL数据库到底存在哪些优缺点。

NoSQL的优缺点

在优势方面,主要体现在下面这三点:

  • 简单的扩展:典型例子是Cassandra,由于其架构是类似于经典的P2P,所以能通过轻松地添加新的节点来扩展这个集群;
  • 快速的读写:主要例子有redis,由于其逻辑简单,而且纯内存操作,使得其性能非常出色,单节点每秒可以处理超过10万次读写操作;
  • 低廉的成本:这是大多数分布式数据库共有的特点,因为主要都是开源软件,没有昂贵的License成本;

但瑕不掩瑜,NoSQL数据库还存在着很多的不足,常见主要有下面这几个:

  • 不提供对SQL的支持:如果不支持SQL这样的工业标准,将会对用户产生一定的学习和应用迁移成本;
  • 支持的特性不够丰富:现有产品所提供的功能都比较有限,大多数NoSQL数据库都不支持事务,也不像MS SQL Server和Oracle那样能提供各种附加功能,比如BI和报表等;
  • 现有产品的不够成熟:大多数产品都还处于初创期,和关系型数据库几十年的完善不可同日而语;

上面NoSQL产品的优缺点都是些比较共通的,在实际情况下,每个产品都会根据自己所遵从的数据模型和CAP理念而有所不同.

编译过程

Posted on 05-07-2015 | In Misc


通常我们使用gcc来生成可执行程序,命令为:gcc hello.c,默认生成可执行文件a.out



其实编译(包括链接)的命令:gcc hello.c 可分解为如下4个大的步骤:




    • 预处理(Preprocessing)
    • 编译(Compilation)
    • 汇编(Assembly)
    • 链接(Linking)




gcc_compilation


预处理




1.       预处理(Preproceessing)



预处理的过程主要处理包括以下过程:



  • 将所有的#define删除,并且展开所有的宏定义
  • 处理所有的条件预编译指令,比如#if #ifdef #elif #else #endif等
  • 处理#include 预编译指令,将被包含的文件插入到该预编译指令的位置。
  • 删除所有注释 “//”和”/ /”.
  • 添加行号和文件标识,以便编译时产生调试用的行号及编译错误警告行号。
  • 保留所有的#pragma编译器指令,因为编译器需要使用它们


 



通常使用以下命令来进行预处理:



gcc -E hello.c -o hello.i



参数-E表示只进行预处理 或者也可以使用以下指令完成预处理过程



cpp hello.c > hello.i      /  cpp – The C Preprocessor  /



直接cat hello.i 你就可以看到预处理后的代码



 

编译


2.       编译(Compilation)



编译过程就是把预处理完的文件进行一系列的词法分析,语法分析,语义分析及优化后生成相应的汇编代码。



$gcc –S hello.i –o hello.s



或者



$ /usr/lib/gcc/i486-linux-gnu/4.4/cc1 hello.c



注:现在版本的GCC把预处理和编译两个步骤合成一个步骤,用cc1工具来完成。gcc其实是后台程序的一些包装,根据不同参数去调用其他的实际处理程序,比如:预编译编译程序cc1、汇编器as、连接器ld



可以看到编译后的汇编代码(hello.s)如下:

 .file   "hello.c"
.section .rodata
.LC0:
.string "Hello, world."
.text
.globl main
.type main, @function
main:
pushl %ebp
movl %esp, %ebp
andl $-16, %esp
subl $16, %esp
movl $.LC0, (%esp)
call puts
movl $0, %eax
leave
ret
.size main, .-main
.ident "GCC: (Ubuntu 4.4.3-4ubuntu5) 4.4.3"
.section .note.GNU-stack,"",@progbits


 

汇编


3.       汇编(Assembly)



汇编器是将汇编代码转变成机器可以执行的命令,每一个汇编语句几乎都对应一条机器指令。汇编相对于编译过程比较简单,根据汇编指令和机器指令的对照表一一翻译即可。



$ gcc –c hello.c –o hello.o



或者



$ as hello.s –o hello.co



由于hello.o的内容为机器码,不能以普通文本形式的查看(vi 打开看到的是乱码)。



 

链接

4.       链接(Linking)



通过调用链接器ld来链接程序运行需要的一大堆目标文件,以及所依赖的其它库文件,最后生成可执行文件。



ld -static crt1.o crti.o crtbeginT.o hello.o -start-group -lgcc -lgcc_eh -lc-end-group crtend.o crtn.o (省略了文件的路径名)。



 

编译器和链接器具体做了什么


helloworld的大体编译和链接过程就是这样了,那么编译器和链接器到底做了什么呢?



 



编译过程可分为6步:

  • 词法分析:扫描器(Scanner)将源代的字符序列分割成一系列的记号(Token)。lex工具可实现词法扫描。
  • 语法分析:语法分析器将记号(Token)产生语法树(Syntax Tree)。yacc工具可实现语法分析(yacc: Yet Another Compiler Compiler)。
  • 语义分析:静态语义(在编译器可以确定的语义)、动态语义(只能在运行期才能确定的语义)。
  • 源代码优化:源代码优化器(Source Code Optimizer),将整个语法书转化为中间代码(Intermediate Code)(中间代码是与目标机器和运行环境无关的)。中间代码使得编译器被分为前端和后端。编译器前端负责产生机器无关的中间代码;编译器后端将中间代码转化为目标机器代码。
  • 目标代码生成:代码生成器(Code Generator).
  • 目标代码优化:目标代码优化器(Target Code Optimizer)。


 



链接的主要内容是把各个模块之间相互引用的部分处理好,使得各个模块之间能够正确地衔接。



链接的主要过程包括:地址和空间分配(Address and Storage Allocation),符号决议(Symbol Resolution),重定位(Relocation)等。

链接分为静态链接和动态链接

  1. 静态链接是指在编译阶段直接把静态库加入到可执行文件中去,这样可执行文件会比较大。

  2. 动态链接则是指链接阶段仅仅只加入一些描述信息,而程序执行时再从系统中把相应动态库加载到内存中去。


静态链接的大致过程如下图所示:

static_linking

1…2122232425262728293031323334353637
Mike

Mike

🚙 🚗 💨 💨 If you want to create a blog like this, just follow my open-source project, "hexo-theme-neo", click the GitHub button below and check it out ^_^ . It is recommended to use Chrome, Safari, or Edge to read this blog since this blog was developed on Edge (Chromium kernel version) and tested on Safari.

11 categories
296 posts
111 tags
about
GitHub Spotify
© 2013 - 2025 Mike