Skip to content

Instantly share code, notes, and snippets.

View ziyoung's full-sized avatar
🤒
I may be slow to respond.

hetech ziyoung

🤒
I may be slow to respond.
  • 上海浦东
View GitHub Profile
@ziyoung
ziyoung / async.js
Last active May 12, 2023 10:02
泛泛而谈
View async.js
const { EventEmitter } = require('event-emitter');
function mapAsync(iterable, mapper, option) {
// consumer 控制 concurrency
}
function filterAsync(iterable, filterer) {
// promise 控制
}
@ziyoung
ziyoung / cli.js
Last active March 30, 2021 03:40
Shebang and common snippet
View cli.js
#!/usr/bin/env node
console.log('cli application');
process.on('rejectionHandled', error => {
throw error;
});
@ziyoung
ziyoung / Makefile
Created June 26, 2020 13:53
go build flag
View Makefile
# go build link
PKG_NAME = github.com/ziyoung/repo
GO_LDFLAGS = -X ${PKG_NAME}/pkg.Var=123
build:
go build -ldflags "${GO_LDFLAGS}" -o file ./some-file.go
@ziyoung
ziyoung / Run.java
Created August 7, 2019 03:39
Java 中注解可以添加在方法的参数上
View Run.java
public class Run {
@Target(ElementType.PARAMETER)
@Retention(RetentionPolicy.RUNTIME)
static @interface QueryParam {
String value();
}
public void testAnnotation(@QueryParam("action") String action) {
System.out.printf("action is %s\n", action);
}
@ziyoung
ziyoung / docker-compose.yml
Created August 1, 2019 12:11
MySQL container
View docker-compose.yml
version: "3"
services:
my-db:
image: "mysql:5.7"
container_name: "my-db"
restart: always
environment:
MYSQL_ROOT_PASSWORD: 12345
volumes:
@ziyoung
ziyoung / docker-compose.yml
Last active August 22, 2019 02:31
快速搭建 elk
View docker-compose.yml
# https://www.elastic.co/guide/en/elasticsearch/reference/current/docker.html
version: '3'
services:
es01:
image: elasticsearch:7.2.0
container_name: es01
environment:
- node.name=es01
- discovery.seed_hosts=es02
- cluster.initial_master_nodes=es01,es02
@ziyoung
ziyoung / send-mail.js
Created June 6, 2019 07:41
批量发送邮件
View send-mail.js
const nodemailer = require('nodemailer');
const config = require('./config.json');
const wait = () => new Promise(resolve => setTimeout(resolve, 800));
async function main() {
let transporter = nodemailer.createTransport({
host: "email.example.com",
port: 587,
secure: false, // true for 465, false for other ports
@ziyoung
ziyoung / note.md
Last active April 29, 2019 10:09
数组与指针的关系
View note.md

指针的介绍

  • 指针仅仅是指向计算机中的某个地址,并带有类型限定符。
  • 你可以对一个指针使用数组的语法来访问指向的东西,也可以对数组的名字做指针的算数运算。
  • 你应该每次尽可能使用数组,并且按需将指针用作提升性能的手段。

指针并不是数组

无论怎么样,你都不应该把指针和数组混为一谈。它们并不是相同的东西,即使C让你以一些相同的方法来使用它们

@ziyoung
ziyoung / test-load.js
Created April 28, 2019 09:30
测试 element 中的 Markdown loader
View test-load.js
const genInlineComponentText = require('./build/md-loader/util').genInlineComponentText;
const template = '<el-input v-model="input" placeholder="请输入内容"></el-input>';
const script = `
export default {
data() {
return {
input: ''
}
@ziyoung
ziyoung / delete-dangling-image.sh
Last active April 23, 2019 10:17
remove none docker image
View delete-dangling-image.sh
# 下面的这个命令更简洁一些,docker image ls -f "dangling=true" -q
IMAGES=`docker images -f "dangling=true" -q`
docker rmi $IMAGES
# 更为简洁的命令
docker rmi -f $(docker images --filter "dangling=true" -q --no-trunc)