Skip to content

Instantly share code, notes, and snippets.

View aes.py
import os
import sys
import base64
import json
from Crypto import Random
from Crypto.Cipher import AES
class AESCrypt:
@shau-lok
shau-lok / nginx.conf
Created Jun 27, 2018
【nginx 错误】Upstream prematurely closed connection while reading upstream
View nginx.conf
Had a similar problem with my reverse proxy.
This is the configuration that finally did it for me:
location / {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forward-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forward-Proto http;
@shau-lok
shau-lok / flask_before_after_request.py
Created Jun 4, 2018
flask hook 请求和返回, 为了输出日志
View flask_before_after_request.py
import json
from json import JSONDecodeError
from logging.config import dictConfig
import requests
from flask import Flask, jsonify, request
from apps.forms import EventForm
from apps.tasks import collection_event_task
from apps.utils import (config_app, logger, cast_to_form_data,
@shau-lok
shau-lok / axios_download.js
Last active May 30, 2018
axios 获取文件流并下载
View axios_download.js
let path = "http://localhost:5000/api/export";
axios
.get(path, { params: this.searchForm , responseType: 'blob'})
.then(response => {
let data = response.data;
let fileName = res.headers['content-disposition'].match(/fushun(\S*)xls/)[0];
@shau-lok
shau-lok / fix.md
Created May 24, 2018
Docker Error : standard_init_linux.go:178: exec user process caused "exec format error"
View fix.md

docker-compose 启动服务,需要用到脚本启动的情况

脚本的头部必须加上 #!/bin/bash

eg:

docker-compose

@shau-lok
shau-lok / Dockerfile
Created May 23, 2018
Dockerfile - django
View Dockerfile
FROM python:3.6.5-slim
MAINTAINER shau-lok
RUN apt-get update \
&& apt-get -yq install python-dev libmysqlclient-dev \
libicu-dev apt-utils gcc curl wget vim \
&& apt-get clean all
WORKDIR /app
@shau-lok
shau-lok / Dockerfile
Last active May 23, 2018
Dockerfile - flask
View Dockerfile
FROM python:3.6.5-slim
MAINTAINER shau-lok
RUN sed -i 's#http://archive.ubuntu.com#http://mirrors.163.com#g' /etc/apt/sources.list
RUN sed -i 's#http://deb.debian.org#http://mirrors.163.com#g' /etc/apt/sources.list
RUN sed -i 's#http://security-cdn.debian.org#http://mirrors.163.com#g' /etc/apt/sources.list
RUN sed -i 's#http://security.debian.org#http://mirrors.163.com#g' /etc/apt/sources.list
RUN apt-get update \
@shau-lok
shau-lok / requests_response_encoding.py
Created Apr 29, 2018
解决requests 返回的内容编码 (iso-8859-1) 问题
View requests_response_encoding.py
# Refers: https://github.com/requests/requests/issues/1604
# 方法1:
r = requests.get('http://irresponsible-server/')
r.encoding = 'utf-8'
# 方法2:
r = requests.get('http://irresponsible-server/')
r.encoding = r.apparent_encoding
@shau-lok
shau-lok / pillow.py
Last active Apr 18, 2018
python Pillow load image from bytes, Pillow 用法
View pillow.py
from PIL import Image
import io
def load_image_from_bytes(image_data):
""" 从图片流中读取一张照片 """
im = Image.open(io.BytesIO(image_data))
print(im)
# >>> <PIL.PngImagePlugin.PngImageFile image mode=RGBA size=300x240 at 0x102092B10>
@shau-lok
shau-lok / pagination.js
Last active Jan 15, 2018
后端返回所有数据, 前端做分页
View pagination.js
// 前端做数据分页
function pagination(pageNo, pageSize, array) {
var offset = (pageNo - 1) * pageSize;
return (offset + pageSize >= array.length) ? array.slice(offset, array.length) : array.slice(offset, offset + pageSize);
}
// 后端django做分页
from django.core.paginator import Paginator