Skip to content

Instantly share code, notes, and snippets.

View notsobad's full-sized avatar

notsobad notsobad

View GitHub Profile

shell里的按行计数

统计某一列的计数,常用awk,也可以用uniq来做

# 用awk
wang@xxx ~ $ cat /etc/passwd|awk -F':' '{print $7}'|sort |uniq -c
     25 /bin/bash
      9 /bin/false
      1 /bin/sync
      2 /bin/zsh
 1 /sbin/halt

nginx默认会合并url中的'/', '//'会合并为一个,比如请求'/abc//', 日志中看到的虽然是'/abc/xx//',但是rewrite,或者proxy_pss取到的只有'/abc/xx/'。

    location ~ ^/abc/(.*) {
        set $path $1;
    }

访问'/abc/xx//', 这里的$path,只能取到'xx/'。

@notsobad
notsobad / client.py
Created March 16, 2017 06:19
websocket demo
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from tornado.ioloop import IOLoop, PeriodicCallback
from tornado import gen
from tornado.websocket import websocket_connect
class Client(object):
def __init__(self, url, timeout):
self.url = url
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1" />
<meta name="robots" content="noindex, nofollow" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
<title>Just a moment...</title>
<style type="text/css">
@notsobad
notsobad / Dockerfile
Created September 8, 2016 06:41
Dockerfile
FROM ubuntu:14.04
RUN sed -i 's/archive.ubuntu.com/mirrors.aliyun.com/g' /etc/apt/sources.list
RUN apt-get update && apt-get install -y wget

使用curl, 对于sni形式的ssl配置,host是在ssl协商阶段传送的,所以不能用 -H 'Host: xxxx.com'的形式来指定域名,而要使用--resolve参数

curl -vv --resolve www.yunaq.com.cn:443:1.2.3.4 https://www.yunaq.com.cn

使用openssl, 注意如果服务器是sni方式,需要加-servername参数来指定host

openssl s_client -showcerts -servername www.yunaq.com -connect 1.2.3.4:443

可以使用 nbformat 来动态创建'.ipynb'文件,然后用jupyter nbconvert执行

import nbformat as nbf
nb = nbf.v4.new_notebook()

text = "This is an auto-generated notebook."
code = "1+2"

nb['cells'] = [nbf.v4.new_markdown_cell(text),
@notsobad
notsobad / 50x.sh
Created August 4, 2016 03:04
count 50x error in nginx error log
#!/bin/bash
# By notsobad
f=$1
if [ "$f" = "" ]; then
echo "Usage: $0 LOG_FILE" 1>&2
echo "like: $0 /var/log/nginx/www.xxx.com_log-20160313"
echo "or: $0 /var/log/nginx/www.xxx.com_log-20160313.gz"
exit 1