sed命令中的N

背景

想把下面一组的uid和wealth弄到同一行,有什么好的实现方式呢?

1
2
3
4
5
6
7
8
9
10
11
12
uid[1025472]
wealth[33600]
uid[1025472]
wealth[33600]
uid[1031052]
wealth[4800]
uid[1031052]
wealth[4800]
uid[1031697]
wealth[4800]
uid[1031697]
wealth[4800]

答案

1
sed 'N;s/\n//g' w.log

和awk类似,sed语句的基本结构也是 sed ‘模式{动作1;动作2}’ file 的执行方式。不过sed中有两个空间,一个叫pattern space(模式空间),一个叫hold buffer(缓冲区/缓冲空间),sed中的模式匹配的对象只是模式空间,和awk一样,sed也是一行一行的读入文本,不过sed在执行命令前,会将文本的行读到模式空间中,然后执行模式{动作}语句,而在执行命令完后,默认sed还是把模式空间的内容打印出来(通过-n 参数可以把最后默认打印模式空间的动作取消)。

实例1

1
2
3
4
seq 6 | sed -n 'N;P'
1
3
5

[解析]

这个命令就是输出的奇数行,怎么来实现的呢?首先N的作用是读取下一行内容,追加到模式空间里,那sed是逐行执行的,这时候读取1,N把下一行追加到模式空间,那模式空间里的内容就变成了 1\n2 虽然是2行,但是这时候sed把2行看做中间有个换行符的一个整体内容,在模式空间里面。然后继续执行命令P,打印第一行内容。那么1就输出到了屏幕上,接着读取3,N追加4,P输出3,这样一直按这个顺序执行,输出了所有奇数行。这个命令是不是很巧妙?

实例2

1
2
3
seq 5 | sed -n 'N;P'
1
3

[解析]

输出奇数行?5没有输出。是的,这是为什么呢?可以info sed看看N的解释“If there is no more input then ‘sed’ exits without processing any more commands.”,如果没有可以追加的内容,那么sed将不会处理后面的任何命令。当sed读到5的时候,已经没有下一行内容了,那么N将退出,也不再执行后面的P。所以5没有输出。怎么解决呢?

1
2
3
4
seq 5 | sed -n '$!N;P'
1
3
5

[解析]

$!N就是N对最后一行不起作用

Texas Holdem Poker Skills

Top Five Texas Holdem Poker Skills

When you play Texas Holdem poker there are definitely a few skills that you will want to have and others you will always want to work on.

Let’s look at each one of these and give you an idea of which ones are the most important.

1. Table Selection

There may not be anything more important than selecting the right table when it comes to playing Texas Holdem. You can play extremely good poker, but if excellent players surround you, your win rate is going to be less. Conversely, if inexperienced players surround you, your chances of making money are better, even if you make a few mistakes. You can make a great deal of money against bad poker players, but you can lose a lot against the great ones. Picking the softest table may sound gutless, but you would rather be smart in selecting a table you know you can beat.

2. Hand Selection

The biggest mistake most players make when playing poker is playing too many hands. If you have the discipline only to play strong hands, your chances of making money are much better. Patience is definitely a virtue in poker and waiting for strong hands is a good idea. When you do get the strong hand, make sure and raise accordingly.

3. Reading Opponent’s Hands

It is always important to try and put your opponent on a hand. You are not always going to be right, but if you really work at it, you might be surprised how often you are correct. Every action a player takes gives you information about the hand they hold. You make guesses based on the actions they take.

4. Pot Odds

Always be aware of pot odds. The professional poker player always knows if the odds are worth it. You can count the number of “outs” you have to estimate and decide if calling is a positive play. It is a calculation based on your outs, the money you have to lay out, and the money in the pot.

5. Analyzing Your Opponent

You want to be aware of what you opponent is likely to do. There are the maniacs, the calling station, the tight player, etc. You want to be aware of each of these tendencies in regards to your opponents. The more you can put your opponent on a particular type of player, the better chance you have to predict how they will play.

The Gap Concept

You need a better hand to call a raise with Than you do to make a raise with (For example, if I was first part, I will raise pairs with 9, or I would raise with it rather than call).

Position

See how opponents act before my turn to act.

Have the last opportunity to bluff.

Extract more money from opponents.

Five Reasons to Raise

  1. Get more money in pot.

  2. Limit the competition.

  3. Take control of betting.

  4. Make opponents define hands.

  5. Steal BLINDS and ANTES.

Odds and Outs

Step 1 Counting Outs.

Step 2 The Rule of 4 & 2.

1
2
3
4
5
6
7
8
9
10
11
12
13
56s for example

Flop: Qs3h7s

Rule of 4:

Odds: (9 + 3) * 4 = 48%


Turn: 8c

Rule of 2:
(9 + 3 + 3) * 2 = 30%

Step 3 Calculating Pot Odds

1
2
3
Pots: 400
Bet: 100
Odds: 100/(400 + 100) = 20%

Step 4 Make Winning Decisions

1
2
3
4
5
6
5 Outs 

5 * 4 = 20%


Implied Odds

Take Time to Think

  1. Opponents playing conservatively or aggressively ?
  2. What hands are my opponents likely to hold ?
  3. What do my opponents think I have ?
  4. Am I in good position or bad position ?
  5. Should I bet or raise ?
1
2
3
4
5
6
7
8
9
10
11
Best hand?
Bet or Raise

Force weak
opponents out?


Should I check or fold?

Worst hand ?
check or fold

Take Time Out After Significant Changes

  • How has my image changed?
  • Who may be on tilt?
  • should I change gears?

Common Mistakes

Bad players make the same mistakes over and over.

Poker players who exploit bad players and their mistakes will win.

Common Mistakes

  • They don’t bluff enough.
  • They over-value top pair.
  • They don’t bet enough.
  • They call too much instead of folding or raising.
  • They play too timidly.
  • They telegraph the strength of their hand with tells.
  • They go on tilt.

Steal the Blinds

  • No bad beats.
  • No big suck outs.
  • No big desisions.

strategy

  • Target the Average Stacks.
    • Average Stacks can afford to fold.
    • Big Stacks are likely to call because they can afford to take risk.
    • Small Stacks are likely to call because they’re desperate.

Bluffs

  • My opponent believes I’m playing tight.
  • My opponent hasn’t witnessed a bluff from me recently.
  • My opponent isn’t likely to have a great hand or a great draw.
  • My hand can’t win without a bet.
  • My oppenent isn’t anywhere near pot committed.
  • My oppenent is likely to think the last card helped me.
  • Bluffing effectively is a part of Selective Aggression.
  • Pick your spots carefully then play them aggressively.

Make the Big Laydown

Code Complete笔记

软件构建 What is software construction

  • 定义问题 (Problem Definition)
  • 需求分析 (Requiremnets Development)
  • 规划构建 (Construction Planning)
  • 软件架构 (Software Architecture),或高层设计(High-Level Design)
  • 详细设计 (Detailed Design)
  • 编码与调试 (Coding and Debugging)
  • 单元测试 (Unit Testing)
  • 集成测试 (Integration Testing)
  • 集成 (Integration)
  • 系统测试 (System Testing)
  • 保障维护 (Corrective Maintenance)

学习使用nginx

##nginx启动、重启、关闭

###启动

1
2
cd usr/local/nginx/sbin
./nginx

###重启

更改配置重启nginx

1
2
3
4
5
6
7
8
9
10
11
kill -HUP 主进程号或进程号文件路径

cd /usr/local/nginx/sbin
./nginx -s reload

# 判断配置文件是否正确 

nginx -t -c /usr/local/nginx/conf/nginx.conf

cd /usr/local/nginx/sbin
./nginx -t

###关闭

  • 查询nginx主进程号 ps -ef | grep nginx
  • 从容停止 kill -QUIT 主进程号
  • 快速停止 kill -TERM 主进程号
  • 强制停止 kill -9 nginx
  • 若nginx.conf配置了pid文件路径,如果没有,则在logs目录下
1
kill -信号类型 '/usr/local/nginx/logs/nginx.pid'

###升级

  1. 先用新程序替换旧程序文件
  2. kill -USR2 旧版程序的主进程号或者进程文件名
    • 此时旧的nginx主进程会把自己的进程文件改名为.oldbin,然后执行新版nginx,此时新旧版本同时运行
  3. kill -WINCH 旧版本主进程号
  4. 不重载配置启动新/旧工作进程 kill -HUP 旧/新版本主进程号
  5. 从容关闭旧/新进程 kill -QUIT 旧/新进程号
  6. 快速关闭旧/新进程 kill -TERM 旧/新进程号

Web性能优化概述

“合格的开发者知道怎么做,而优秀的开发者知道为什么那么做。”

钻研基础知识与紧跟最新动向本身是一对矛盾,很难平衡。可是没有基础,那只能是“墙上芦苇,头重脚轻根底浅”。光知道表面上的那点东西可不行。需要解决难题的时,发生异常状况时,理解基础知识的人会脱颖而出。

SQL中Group By的常见场景

“Group By”从字面意义上理解就是根据“By”指定的规则对数据进行分组,所谓的分组就是将一个“数据集”划分成若干个“小区域”,然后针对若干个“小区域”进行数据处理。
,