严重批判 phone 和 password 自成一家

手上有这么一个项目, user 表里只有 phone 和 password 这个两个字段(除了 id, create_time, update_time 这些字段), 其他信息(比如 name, gender 等字段)保存在 user_profile 表里, 为什么要这样做呢? 放在一个表里不就ok了吗? 经过强烈讨论看文章和思考后, 就写了这篇文章, 欢迎指正和交流 这涉及到 分表分库 解决 支持高并发, 数据量大 的问题了, 什么是分表分库? 参考这篇文章: https://juejin.im/entry/5b5eb7f2e51d4519700f7d3c 其中垂直拆分的意思,就是把一个有很多字段的表给拆分成多个表,或者是多个库上去。每个库表的结构都不一样,每个库表都包含部分字段。一般来说,会将 较少的访问频率很高的字段 放到一个表里去,然后将 较多的访问频率很低的字段 放到另外一个表里去。因为数据库是有缓存的,你访问频率高的行字段越少,就可以在缓存里缓存更多的行,性能就越好。这个一般在表层面做的较多一些。 就目前这个情况, user 表目的在于登录业务上(该项目只支持手机号登录), user_profile 表目的在于用户数据分析, 内容推送等, 该表的访问频率对于 user 表是更高的, 所以 phone 和 password 自成一家 想想也是可以的耶。

September 2, 2019 · 1 min · K8sCat

如何将网页中的 table 导出成 excel

如何将目标网页中的 table 导出成 excel? <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>table2excel</title> </head> <body> <input type="button" id="btn" value="导出"/> <table id="example"> 省略内容 </table> <script src="jquery.min.js"></script> <script src="jquery.table2excel.min.js"></script> <script> $(function() { $('#btn').click(function() { $('#example').table2excel({ // 不被导出的表格行的CSS class类 exclude: '.excludeThisClass', // 导出的Excel文档的名称,(没看到作用) name: 'Worksheet Name', // Excel文件的名称 filename: 'SomeFile.xls' }) }) }) </script> </body> </html> 案例地址: https://github.com/hsowan/table2excel

August 30, 2019 · 1 min · K8sCat

使用 scp 下载远程服务器的文件

# 将远程服务器上的 a.txt 文件下载到本地 /data/ 下 # -P 指定远程服务器的端口 scp -P 22 root@remote_host:/a.txt /data/

August 23, 2019 · 1 min · K8sCat

使用 rsync 迁移数据

# 在 A 主机上执行下面的命令 # 将 A 主机上的 /data/ 下的所有文件迁移到 B 主机上 /data/ 下 # ssh -p 22 可以指定 B 主机的端口 # --progress 显示迁移进度 rsync -av --progress /data/ -e 'ssh -p 22' username@hostname:/data/

August 22, 2019 · 1 min · K8sCat

Django 接入 GitHub OAuth 的正确姿势

Django 如何正确接入 GitHub OAuth? 项目地址: https://github.com/hsowan/CSDNBot/tree/web 首先, 创建 GitHub OAuth Apps {% img /images/new-github-oauth-app.png %} 其中值得注意的有: Authorization callback URL (认证后的回调地址), 比如: http://localhost:8000/api/login/oauth/code/github/, 在认证之后将跳转到这个地址并带上一个 code 参数, 这个参数会用来请求 access_token Client ID 和 Client Secret 也是用户请求 access_token 的参数 然后, 在 Django 项目中添加路由 from django.urls import re_path from . import apis urlpatterns = [ re_path(r'^api/login/oauth/code/github/?$', apis.github_oauth_callback), ] 实现 github_oauth_callback: import requests from django.conf import settings import json from django.shortcuts import redirect # https://github.com/login/oauth/authorize?client_id=bd4692513cb71ba05c22&scope=user def github_oauth_callback(request): code = request....

August 21, 2019 · 1 min · K8sCat

shell 写单行或多行内容至文件

如何使用 shell 将单行或多行内容写至文件? 单行内容 echo 'content' > file 多行内容 cat > file << EOF hello world !!! EOF tee file <<-'EOF' a b c EOF

August 21, 2019 · 1 min · K8sCat

生成及使用 requirements.txt

平时使用的是 pipenv, 但是在 docker 构建镜像时, 其本身就是一个隔离的环境, 就没必要再去安装 pipenv, 这时如何安装需要的依赖呢? # 生成 requirements.txt pip freeze > requirements.txt # 使用 requirements.txt 安装所需的依赖 pip install -r requirements.txt CSDNBot web版的 Dockerfile: FROM python:3.7 LABEL maintainer="hsowan<hsowan.me@gmail.com>" WORKDIR /CSDNBot COPY . . RUN pip install -i https://pypi.tuna.tsinghua.edu.cn/simple/ -r requirements.txt && \ # 更新apt源 wget -O /etc/apt/sources.list https://gitee.com/hsowan/linux-run/raw/master/debian/buster/tsinghua/sources.list && \ apt update && \ apt install -y cron EXPOSE 8000

August 21, 2019 · 1 min · K8sCat

SpringBoot 接口异常统一处理

当接口出现未知异常时, 如何返回统一的信息? Response.java: package com.ncucoder.collector.vo; import lombok.Data; import lombok.NoArgsConstructor; /** * @author <a href="https://hsowan.me">hsowan</a> **/ @Data @NoArgsConstructor public class Response { private Integer code; private Object body; public Response(Integer code, Object body) { this.code = code; this.body = body; } } GlobalExceptionHandler.java: package com.ncucoder.collector.advice; import com.ncucoder.collector.vo.Response; import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.ResponseBody; import javax.servlet.http.HttpServletResponse; /** * @author <a href="https://hsowan.me">hsowan</a> */ @ControllerAdvice public class GlobalExceptionHandler { @ExceptionHandler(Exception.class) @ResponseBody public Response handler(Exception e) { return new Response(HttpServletResponse....

August 13, 2019 · 1 min · K8sCat