zhnpeng's
  • About
  • Tweet

cookies,会话和跨域

cookies,会话和跨域 Cookies (a) 用户第一次访问 Web 站点,Web 服务器对用户一无所知。 (b) Web 服务器希望这个用户下次访问该站点时,可以识别出它来。所以通过 Set-Cookie(或 Set-Cookie2)向客户端回送一个独有的 cookie。上图中,服务器会将一个表示 id="34294" 的 cookie 返回给用户。服务器可以用这个数字来查找服务器为其访问者累积的数据库信息。cookie 并不仅限于保存 ID 号。很多 Web 服务器都会将信息以名值对的形式直接保存在 cookie 中。 (c) 浏览器接收到 Web 服务器的响应,会将 Set-Cookie(或 Set-Cookie2)首部中的 cookie 内容保存在本地。将来用户再次访问同一站点时,浏览器会将 cookie 的内容取出,并通过 Cookie...

08 Jun 2017

Mongo sort ram limit

Mongo sort ram limit 概述 Mongo sort操作是在内存里sort数据,默认会有最大内存限制. find/query的sort默认是32MB,aggregate的$sort默认是100MB,当sort条目数据量超过之后就会报错. Error: error: { "waitedMS" : NumberLong(0), "ok" : 0, "errmsg" : "Executor error during find command: OperationFailed: Sort operation used more than the maximum 33554432 bytes of...

02 Jun 2017

Python Profile function

Python Profile function 概述 The Python Profiler 基于lsprof的用c语言实现的库,开销小,统计函数的调用时间和次数. Code import cProfile, pstats import re def fib(n): if n==1 or n==2: return 1 return fib(n-1)+fib(n-2) def profile(func): def wrapper(*args, **kwargs): pr = cProfile.Profile() try: pr.enable() return...

08 May 2017

restapi swagger

restapi swagger 概述 Swagger is a powerful open source framework backed by a large ecosystem of tools that helps you design, build, document, and consume your RESTful APIs. RestAPI 文档化 Swagger UI 以Django为例:django-rest-swagger 点进去参考安装和使用方法 django-rest-swagger配合django-rest-framework:...

06 May 2017

git hook

git hook 和其它版本控制系统一样,Git 能在特定的重要动作发生时触发自定义脚本。 有两组这样的钩子:客户端的和服务器端的。 客户端钩子由诸如提交和合并这样的操作所调用,而服务器端钩子作用于诸如接收被推送的提交这样的联网操作。 你可以随心所欲地运用这些钩子。 文档 钩子 在repo的.git/hooks下放钩子脚本: pre-commit pre-commit hook是在执行git commit之前执行的脚本, pre-commit阶段可以做lint和test,如果失败将提示并且不做commit操作. 如上图的pre-commit脚本内容: #!/bin/bash ./node_modules/pre-commit/hook RESULT=$? [ $RESULT -ne 0 ] && exit 1 exit 0 安装 pre-commit npm install pre-commit pre-commit包会根据package.json的配置执行对应的命令...

23 Mar 2017

xml加密解密

xml加密解密 使用python库xmlsec进行加密解密 流程 使用rsa cert将xml的特定element加密,加密后明文的element被EncryptData element代替, 解密的时候使用rsa cert对应的私钥进行解密. 代码 from os import path import xmlsec from lxml import etree # Generating a self signed rsa cert run: # openssl req -nodes -new -x509 -keyout rsa.key...

16 Mar 2017

DPDK 网卡接口

DPDK 网卡接口 DPDK DPDK is a set of libraries and drivers for fast packet processing. It was designed to run on any processors. The first supported CPU was Intel x86 and it is now extended...

08 Mar 2017

codemirror xml lint

codemirror xml lint About codemirror CodeMirror is a code-editor component that can be embedded in Web pages. The core library provides only the editor component, no accompanying buttons, auto-completion, or other IDE functionality. It does...

08 Mar 2017

vim插件使用经验

vim插件使用经验 vimrc plugins ‘VundleVim/Vundle.vim’ ‘Valloric/YouCompleteMe’ ‘SirVer/ultisnips’ ‘majutsushi/tagbar’ ‘terryma/vim-multiple-cursors’ ‘vim-airline/vim-airline’ ‘vim-airline/vim-airline-themes’ ‘kien/ctrlp.vim’ ‘uguu-org/vim-matrix-screensaver’ ‘scrooloose/nerdtree’ ‘mileszs/ack.vim’ Vundle vim 插件管理器,安装vundle: git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim’ 安装插件项目参考:vim配置和插件安装 YouCompleteMe 和ultisnips一起用来代码补全,代码跳转。 需要vim 7.4以上,最好安装完整版本。 apt-get install vim-nox vundle安装完之后,需要进入目录安装,例如: ./install.py –help ./install.py –clang-compiler 配置...

14 Jan 2017

Django Session And Auth Middleware

Django Session And Auth Middleware 前言: 一个Django App(app2)需要使用另外一个Django App(app1)的session和用户系统进行登录认证. app1使用Django自带的SessionMiddle和AuthenticationMiddle,下面我结合Django源码和需求, 分析从带session_key的请求,获得用户的过程. app1的settings如下: SECRET_KEY = '*(&^&&JSIIJIFEJIFJ' INSTALL_APPS = ( 'django.contrib.sessions' ) MIDDLEWARE_CLASSES = ( 'django.contrib.sessions.middleware.SessionMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', ) DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': DB_FILE_PATH...

27 Sep 2016
Previous