Skip to content

Instantly share code, notes, and snippets.

View chengjianhua's full-sized avatar
💦

Jianhua Cheng chengjianhua

💦
View GitHub Profile
@chengjianhua
chengjianhua / simple-ajax.js
Created February 28, 2019 07:23
simple-ajax
function ajax(url: string, { method = 'GET', data = undefined } = {}) {
return new Promise((resolve, reject) => {
const xhr = new XMLHttpRequest();
xhr.open(method, url);
if (method === 'POST') {
xhr.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');
}
@chengjianhua
chengjianhua / format-git-commit-message.js
Created January 5, 2019 11:49
format-git-commit-message
const rawMessage = `Merge branch 'fix/bundle' into 'develop'
asdasdasdasdasd
fix(bundle): fix bug in bundle_edit
See merge request frontend/darwin-yy!63`;
const firstLineBreakIndex = rawMessage.indexOf('\n');
let computedMessage;
@chengjianhua
chengjianhua / keybase.md
Created September 12, 2018 04:25
keybase.md

Keybase proof

I hereby claim:

  • I am chengjianhua on github.
  • I am chengjianhua (https://keybase.io/chengjianhua) on keybase.
  • I have a public key ASCqPN_sFKquuM0syrbGghUGmzmWa8HWmlbN1kharxR-lAo

To claim this, I am signing this object:

@chengjianhua
chengjianhua / docker-compose-mysql.yaml
Created September 4, 2018 03:10
docker-compose-mysql.yaml
version: "3.4"
services:
server:
image: node
restart: unless-stopped
ports:
- "3000:3000"
networks:
- my_network
func watchLogsOfAllJobContainers(
podClient clientCoreV1.PodInterface,
podListOptions *meta_v1.ListOptions,
overallChannel *chan OverallEvent,
) (err error) {
jobContainers := []podContainer{}
var logsWaitGroup sync.WaitGroup
podList, err := podClient.List(*podListOptions)
// 遍历所有 pod 的容器, 将每个容器从属的 pod 名称以及本身的名称保存到总的数组中
@chengjianhua
chengjianhua / list-express-routes.js
Created July 7, 2018 20:13
list-express-routes
/* eslint-disable no-underscore-dangle */
function split(thing) {
if (typeof thing === 'string') {
return thing.split('/');
} else if (thing.fast_slash) {
return '';
}
const match = thing
.toString()
@chengjianhua
chengjianhua / bind-experiment.js
Last active March 17, 2018 05:21
test the behavior of bound function
function Func() {
this.a = 1;
console.log('this', this);
}
console.group('Func.invoke');
console.log(Func());
console.groupEnd();
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<script src="https://cdn.jsdelivr.net/lodash/4/lodash.min.js"></script>
@chengjianhua
chengjianhua / cnpm-login.js
Created October 24, 2017 05:00
The `cnpm login` in Continuous Integration. Because the private registry hosted by cnpm incapable of generating a `auth_token` after `npm login <registry>`.
const cp = require('child_process');
// eslint-disable-next-line no-unused-vars
function inspect(...args) {
return console.dir(...args, {
showHidden: true,
depth: Infinity,
colors: true,
});
}
@chengjianhua
chengjianhua / get-dist-tag.js
Created October 24, 2017 04:56
check a package version is whether a `beta` one
const cp = require('child_process');
const pkg = require('../package.json');
const BETA_NAMES = ['alpha', 'beta'];
const { version } = pkg;
// the alpha version No. should be like "v7.1.0-alpha.2", "v8.0.0"
const alphaReg = /(?:\d+\.\d+\.\d+)(-([a-zA-Z]+)\.\d+)?/i;