开发中使用的一些小知识

 
 
Git

Git是目前世界上最先进的分布式版本控制系统(没有之一)
 
 
Git如何存储版本差异?
 
 
 
 
SHA-1算法的安全性
16核i5处理器、64块Geforce 970显卡、256G内存,破解时间为10天
微软在2013年的Windows 8系统里就改用了SHA-2,Google、Mozilla则宣布2017年1月1日起放弃SHA-1
非防窃取,但防篡改
 
 
 
.gitignore文件                                                                                              
  1. # 忽略掉所有文件名是 foo.txt的文件
  1. foo.txt
  1. # 忽略掉所有名称为foo的目录
  1. foo
  1. # 忽略跟目录下名称为foo的目录
  1. /foo
  1. # 忽略所有生成的 html文件
  1. *.html
  1. # foo.html不忽略
  1. !foo.html
  1. # 忽略所有.o和 .a文件
  1. *.[oa]
 
  1. /*
  1. !/foo
  1. /foo/*
  1. !/foo/bar
 
  1. $ git add App.class
  1. The following paths are ignored by one of your .gitignore files:App.class
  1. Use -f if you really want to add them.
 
  1. $ git check-ignore -v App.class
  1. .gitignore:3:*.class    App.class
 
 
 
git 回滚
  1. # 没有提交到缓存区的内容
  1. git checkout -- <file>...    
 
  1. # 已提交到缓存区
  1. git reset HEAD <file>...
  1. --soft – 缓存区和工作目录都不会被改变
  1. --mixed – 默认选项。缓存区和你指定的提交同步,但工作目录不受影响
  1. --hard – 缓存区和工作目录都同步到你指定的提交
 
  1. # 已经提交到本地仓库,适合对远程仓库的回滚
  1. git revert HEAD^1
 
 
git rebase
  1. git rebase [branch_name] # 基于某个分支合并
  1. git rebase --continue  # 解决冲突后,继续合并
  1. git rebase --abort  # 放弃合并
 
 
 
git statsh
回滚版本时,本地有已修改的但未提交的内容;
正在开发需求时,如何修复紧急bug (储藏);
  1. git stash # 储藏
  1. git stash pop  (等同于git stash apply && git stash drop) # 还原
  1. git stash list # 查看储藏列表
 
 
git 对比历史
  1. git diff # 显示工作目录与上次提交或缓存区之间的差异
  1. git diff --cached  # 显示缓存与上次提交之间的差异
  1. git diff HEAD # 显示工作目录与上次提交的差异
  1. git diff [branch_name] # 显示工作目录与某个branch之间的差异
  1. git diff master [branch_name] # 显示主干与某个branch之间的差异
 
 
git log
  1. git log  # 查看提交历史
  1. git log -n # 查看最近n次的提交历史
  1. git log --pretty=oneline # 每次提交历史显示到一行
  1. git log --graph --pretty=oneline --abbrev-commit # 显示提交历史树图
 
 
 
Nginx配置

Nginx是一款轻量级Web 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器。
 
 
Nginx编译
  1. nginx编译时./configure --help--without开头的都默认安装。
 
  1. --prefix=PATH : 指定nginx的安装目录。默认 /usr/local/nginx
  1. --conf-path=PATH : 设置nginx.conf配置文件的路径。nginx允许使用不同的配置文件启动,通过命令行中的-c选项。默认为prefix/conf/nginx.conf
  1. --user=name: 设置nginx工作进程的用户。安装完成后,可以随时在nginx.conf配置文件更改user指令。默认的用户名是nobody。--group=name类似
  1. --with-pcre : 设置PCRE库的源码路径,如果已通过yum方式安装,使用--with-pcre自动找到库文件。使用--with-pcre=PATH时,需要从PCRE网站下载pcre库的源码(版本4.4 - 8.30)并解压,剩下的就交给Nginx的./configuremake来完成。perl正则表达式使用在location指令和 ngx_http_rewrite_module模块中。
  1. --with-zlib=PATH : 指定 zlib(版本1.1.3 - 1.2.5)的源码解压目录。在默认就启用的网络传输压缩模块ngx_http_gzip_module时需要使用zlib 。
  1. --with-http_ssl_module : 使用https协议模块。默认情况下,该模块没有被构建。前提是openssl与openssl-devel已安装
  1. --with-http_stub_status_module : 用来监控 Nginx 的当前状态
  1. --with-http_realip_module : 通过这个模块允许我们改变客户端请求头中客户端IP地址值(例如X-Real-IP 或 X-Forwarded-For),意义在于能够使得后台服务器记录原始客户端的IP地址
  1. --add-module=PATH : 添加第三方外部模块,如nginx-sticky-module-ng或缓存模块。每次添加新的模块都要重新编译(Tengine可以在新加入module时无需重新编译)
 
Nginx操作
  1. # /usr/local/nginx-1.6/sbin/nginx -t # 检查配置文件是否正确
  1. # ./sbin/nginx -V     # 可以看到编译选项
 
  1. # ./sbin/nginx  # 启动nginx
 
  1. #./sbin/nginx -s stop # 停止nginx 
  1. 或 pkill nginx
 
  1. #./sbin/nginx -s reload # 重启nginx
  1. 或 kill -HUP `cat /usr/local/nginx-1.6/logs/nginx.pid`
 
Nginx 基础参数
  1. worker_processes  4; #启动进程,通常设置成和cpu的数量相等
  1. events {
  1.     #epoll是多路复用IO(I/O Multiplexing)中的一种方式,
  1.     #仅用于linux2.6以上内核,可以大大提高nginx的性能
  1.     use   epoll; 
 
  1.     #单个后台worker process进程的最大并发链接数    
  1.     # 即 max_clients = worker_processes * worker_connections
  1.     # 在设置了反向代理的情况下,max_clients = worker_processes * worker_connections / 4 
  1.     # max_clients不能超过可打开的文件句柄数
  1.     # Linux下文件句柄设置参考文章 http://ityunwei2017.blog.51cto.com/7662323/1558092
  1.     worker_connections  1024;
  1.  }
 
 
Nginx Web服务器参数
  1. http {
  1.   keepalive_timeout  65; # 连接超时
  1.   gzip  on; # 开启gzip压缩
  1.   #设定请求缓冲
  1.   client_header_buffer_size    128k;
  1.   large_client_header_buffers  4 128k;
  1.   #设定虚拟主机配置
  1.   server {
  1.         #侦听80端口
  1.         listen    80;
  1.         #定义使用 www.nginx.cn访问
  1.         server_name  www.nginx.cn;
 
  1.         #定义服务器的默认网站根目录位置
  1.         root html;
 
  1.         #设定本虚拟主机的访问日志
  1.         access_log  logs/nginx.access.log  main;
 
  1.         #默认请求
  1.         location / {
  1.             #定义首页索引文件的名称
  1.             index index index.html index.htm;  
  1.             proxy_next_upstream http_502 http_504 error timeout invalid_header;
  1.             proxy_set_header Host  $host;
  1.             proxy_set_header X-Real-IP $remote_addr;
  1.             proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  1.             proxy_pass http://it.zeju.com;
  1.             expires -1;
  1.         }
 
  1.         # 定义错误提示页面
  1.         error_page   500 502 503 504 /50x.html;
  1.         location = /50x.html {
  1.         }
 
  1.         #静态文件,nginx自己处理
  1.         location ~ ^/(images|javascript|js|css|flash|media|static)/     {           
  1.             #过期30天,静态文件不怎么更新,过期可以设大一点,
  1.             #如果频繁更新,则可以设置得小一点。
  1.             expires 30d;
  1.         }
 
  1.         #禁止访问 .htxxx 文件
  1.             location ~ /.ht {
  1.             deny all;
  1.         }
 
  1.     }
  1. }
 
Nginx负载参数
  1. upstream  it.zeju.com   {
  1.     server x.x.x.x1:8998 weight=6 max_fails=2 fail_timeout=10s;
  1.     server x.x.x.x2:8997 weight=3 max_fails=2 fail_timeout=10s;
  1.     server x.x.x.x3:8997 weight=1 max_fails=2 fail_timeout=10s;
  1. }
 
 
Nginx 日志参数
  1. $remote_addr 
  1. $remote_user 
  1. [$time_iso8601] 
  1. $http_host 
  1. "$request" 
  1. "$request_body"
  1. $status 
  1. $upstream_status 
  1. "$http_referer"
  1. "$http_user_agent"
  1. "$http_x_forwarded_for"
  1. $ssl_protocol 
  1. $ssl_cipher 
  1. $upstream_addr 
  1. $request_time 
  1. $upstream_response_time
  1. "$http_cookie" 
  1. "$upstream_http_content_type" 
  1. $server_addr 
  1. $server_name 
  1. $server_port 
  1. $server_protocol
  1. $request_length 
  1. $content_length 
  1. $bytes_sent 
  1. $body_bytes_sent 
  1. $content_type 
  1. $request_method 
  1. $scheme 
  1. $request_uri 
  1. $request_filename 
  1. $query_string
  1. $msec 
  1. $cookie__session_id 
  1. $cookie_im_adviser_id 
  1. $cookie_im_customer_id 
  1. $cookie_zjfrom
日志字段设计参考:https://shimo.im/doc/aKGZL5fCWdkGNBg7/
 
 
跨域设置

Nginx设置
  1.   location / {
  1.     if ($http_origin ~ 'domain1.com|domain2.com$') {
  1.         add_header Access-Control-Allow-Origin "$http_origin";
  1.         add_header Access-Control-Allow-Methods "POST, GET, OPTIONS";
  1.         add_header Content-Type application/json;
  1.         add_header Access-Control-Allow-Headers "x-requested-with";
  1.     }
  1.   }
Ruby设置
  1. class XxxxxController < ApplicationController
 
  1.   before_action :access_control_headers
 
  1.   def access_control_headers
  1.     headers['Access-Control-Allow-Origin'] = "*" # or your web site like http://m.zeju.com
  1.     headers['Access-Control-Request-Method'] = %w{GET POST OPTIONS}.join(",")
  1.     headers['Access-Control-Allow-Headers'] = "x-requested-with"
  1.   end
  1. end
 
 
 
分享到微信时,没有展示图片的问题

在紧挨<body>标签开始的位置,放一张300*300以上的png图片,并隐藏展示
例如:
<div style="display:none"><img src="xxx.png"/></div>
 
 
 
任务清单记录工具

滴答清单

 

原文地址:https://www.cnblogs.com/jessical626/p/7137755.html