Skip to content

Instantly share code, notes, and snippets.

@hjzheng
hjzheng / ssh2mysql.js
Created September 7, 2019 06:12
ssh 端口转发到 mysql
const mysql = require('mysql2')
const tunnel = require('tunnel-ssh')
const ssh2mysql = {
_conn: null,
_mysql_pool: null,
/**
* @param obj sshConfig SSH Configuration as defined by ssh2 package
import * as mysql from 'mysql2'
const Client = require('ssh2').Client
const ssh2mysql = {
_conn: null,
_mysql_conn: null,
/**
* @param obj sshConfig SSH Configuration as defined by ssh2 package
@hjzheng
hjzheng / download-file.js
Created September 3, 2019 03:23 — forked from javilobo8/download-file.js
Download files with AJAX (axios)
axios({
url: 'http://localhost:5000/static/example.pdf',
method: 'GET',
responseType: 'blob', // important
}).then((response) => {
const url = window.URL.createObjectURL(new Blob([response.data]));
const link = document.createElement('a');
link.href = url;
link.setAttribute('download', 'file.pdf');
document.body.appendChild(link);
@hjzheng
hjzheng / install_shadowsocks.sh
Created August 16, 2019 06:18
install_shadowsocks.sh
#!/bin/bash
# Install Shadowsocks on CentOS 7
echo "Installing Shadowsocks..."
random-string()
{
cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w ${1:-32} | head -n 1
}
@hjzheng
hjzheng / certificate.sh
Created August 1, 2019 05:18
自签名生成脚本
#!/bin/sh
# create self-signed server certificate:
read -p "Enter your domain [www.example.com]: " DOMAIN
echo "Create server key..."
openssl genrsa -des3 -out $DOMAIN.key 1024
@hjzheng
hjzheng / nginx.md
Last active July 31, 2019 07:19
nginx support https

使用生成免费证书 https://letsencrypt.org/

拥有真实域名,域名机构申请的域名

yum install python2-certbot-nginx

certbot --nginx --niginx-server-root <your_nginx_install_path> -d <your_domains>

注意: 两个参数 nginx 安装路径 和 真实域名,另外该命令会将配置写到 nginx 配置中

@hjzheng
hjzheng / http2.md
Last active July 31, 2019 03:31
http2 协议

HTTP/2 抓包

  • 使用 TLS/SSL 加密,都是随着连接生成有变化的(???)

     Mac 下
     $ export SSLKEYLOGFILE=/Users/username/sslkeylogs/output.log 
     $ open -a Google\ Chrome
    
    

打开 wireshark

@hjzheng
hjzheng / useful_npm_packages.md
Last active July 30, 2019 01:50
有用的 npm 包
  • json5 可以添加注释的 json
  • json5-loader
@hjzheng
hjzheng / composition.tsx
Created July 28, 2019 02:29
compositionstart and compositionend 解决输入法输入问题
import * as React from 'react'
import styled from 'styled-components'
import { observable } from 'mobx'
import { Tooltip, Input, message } from 'antd'
import { Icon } from '@/components'
import { observer } from 'mobx-react'
// 匹配非字母数字下划线空格中文的字符
const reg = /[^a-zA-Z0-9_\s\u4e00-\u9fa5]/g
@hjzheng
hjzheng / ts.md
Last active August 1, 2019 11:55
typescript

泛型的好处

  1. 函数和类可以支持多种类型,增加的程序的可扩展性
  2. 不必写多条函数重载,联合类型声明,增强代码的可读性
  3. 灵活控制类型之间的约束

总结: 泛型不仅可以保持类型的一致性,又不失程序的灵活性,同时也可以通过泛型约束,控制类型之间的约束。从代码的上来看,可读性,简洁性,远优于函数重载,联合类型声明以及 any 类型的声明。

类型检查机制: