分类目录归档:Tools

centos下supervisor安装和使用

安装

dnf update -y
dnf install supervisor
sytemctl enable supervisord

配置

vim /etc/supervisor/xxx.conf

    [program:testprogram]
    directory = /root/go/src/test
    command = /root/go/src/test/bin/server
    autostart = true
    startsecs = 5
    autorestart = true
    startretries = 3
    user = root
    redirect_stderr = true
    stdout_logfile = /var/log/supervisor/test.log

使用

supervisorctl reload
supervisorctl start xxx
supervisorctl status

nginx 程序执行日志

log_format combined_with_time '$remote_addr - $remote_user [$time_local]  '
                     '"$request" $status $body_bytes_sent '
                     '"$http_referer" "$http_user_agent" '
                     '$request_time $upstream_response_time';   

access_log  /data/wwwroot/xxxx/vagrant/nginx/log/frontend-access.log combined_with_time;

基于微信的一些开源工具

Android -Xposed

项目地址:https://github.com/weechatfly/wtoolsdkrobot

项目简介:有趣的微信机器人,基于Xposed

开发语言:Java

项目地址:https://github.com/weechatfly/wtoolsdkroomlive/

项目简介:有趣的微信转发程序,用于微信群直播

开发语言:Java

项目地址:https://github.com/chaojimiaomiao/colorful_wechat

项目简介:微信美化插件,开发者是个大美女

项目地址:https://github.com/geeeeeeeeek/WeChatLuckyMoney

项目简介:微信抢红包外挂插件

开发语言:Java

WEB

项目地址:https://github.com/lu4kyd0y/WeChat-Cloud-Robot

项目简介:基于网页版的微信机器人

开发语言/框架:python

项目地址:https://github.com/sjdy521/Mojo-Weixin

项目简介:基于网页版的微信WEB版协议框架,可用于IRC转发

开发语言:Python

IOS-TWEAK

项目地址:https://github.com/cocos543/WeChatTimeLineRobot

项目简介:朋友圈自动点赞评论机器人

开发语言:C++

MacOSX-Tweak

项目地址:https://github.com/Sunnyyoung/WeChatTweak-macOS

项目简介:Mac微信多开及防撤回插件

开发语言:Objective-C

协议

Tencent/mars

Mars is a cross-platform network component developed by WeChat.

https://github.com/Tencent/mars

WeChatXY

微信ipad协议源码,可实现微信80%功能。支持62数据登录、扫码登录、收发朋友圈、查看朋友圈、微信建群、微信拉人进群、微信公众号阅读、微信消息收发、微信附近的人定位、微信添加好友、微信红包接收、微信防撤回、分享小程序、微信加粉、微信收藏、微信标签等。请联系qq:929918989

https://github.com/weixinbao/WeChatXY

PadChat-SDK

永久免费 微信ipad、微信mac协议,可实现微信80%功能;支持62数据登录、扫码登录、收发朋友圈、查看朋友圈、微信建群、微信拉人进群、微信公众号阅读、微信消息收发、微信附近的人定位、微信添加好友、微信红包接收、微信防撤回、分享小程序、微信加粉、微信收藏、微信标签等

https://github.com/AvengersWeChat/PadChat-SDK

PyMicroChat

https://github.com/fatesinger/PyMicroChat

MicroChat

使用腾讯微信Mars跨平台通信库实现模拟微信App通信

https://github.com/FlyingGlass/MicroChat

WeChatProtocolStudy

微信协议研究,实现基于Android/MAC/IPAD协议的PC客户端

https://github.com/214175590/WeChatProtocolStudy

SDK

Chatie/wechaty

wechaty-puppet-puppeteer - Angular Hook for Web Wechat <- This is the DEFAULT
wechaty-puppet-wechat4u - HTTP API for Web Wechat
wechaty-puppet-padchat - iPad App Protocol
wechaty-puppet-ioscat - iPhone App Hook
wechaty-puppet-mock - Mock for Testing

https://github.com/Chatie/wechaty

WSL 服务自启动脚本

支持在Windows启动时启动WSL中的Linux服务.

安装

  • 使用 git clone 到任意目录 (e.g C:\wsl-autostart)
git clone https://github.com/troytse/wsl-autostart
  • 在注册表中加入启动项 run-regedit

  • HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run下新增字符串项目 (e.g WSLAutostart) regedit-new-item

  • 设定脚本的路径 (e.g C:\wsl-autostart\start.vbs) regedit-set-path

使用

  • 修改在WSL中/etc/sudoers文件,为需要自启动的服务指定为免密码. 如:
%sudo ALL=NOPASSWD: /etc/init.d/cron
%sudo ALL=NOPASSWD: /etc/init.d/ssh
%sudo ALL=NOPASSWD: /etc/init.d/mysql
%sudo ALL=NOPASSWD: /etc/init.d/apache2
  • 修改commands.txt文件指定需要自启动的服务. 如:
/etc/init.d/cron
/etc/init.d/ssh
/etc/init.d/mysql
/etc/init.d/apache2

来源:WSL服务自启动脚本

Windows docker快速上手(含镜像设置)

下载并安装Docker的Windows桌面端

登录桌面端

  • 安装完成后,点击桌面右下角docker小图标,然后点击sign in,或注册帐号

登录命令行

  • 按Win键盘输入cmd,打开windows命令提示符,输入docker login,输入密码帐号,登录docker命令行工具

设置镜像

  • 点击桌面右下角docker小图标,然后点击setting,然后点击Daemon,然后在Rigisty mirrors里面输入https://docker.mirrors.ustc.edu.cn/,然后点击Apply

启动一次操作容器

docker run ubuntu echo 'hello world'

启动交互式容器

docker run -i -t ubuntu /bin/bash

查看容器

docker ps -a # 不带参数表示正在运行的容器,-a所有,-l最近

查看指定容器:

docker inspect name | id

重新启动停止的容器:

docker start [-i] 容器名

删除停止的容器:

docker rm name | id

启动守护式容器

docker run -d IMAGE_NAME

使用pdfbox给pdf去背景图片

前面采用了Python写的pdfrw做的,发现用acrobat不能编辑。

用pdfbox工具查看发现missing xobject。

java -jar pdfbox-app-2.0.13.jar PDFDebugger out.pdf

所以改用java的pdfbox库来写

package com.c4ys;

import org.apache.pdfbox.contentstream.PDContentStream;
import org.apache.pdfbox.contentstream.operator.Operator;
import org.apache.pdfbox.cos.COSName;
import org.apache.pdfbox.pdfparser.PDFStreamParser;
import org.apache.pdfbox.pdfwriter.ContentStreamWriter;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPage;
import org.apache.pdfbox.pdmodel.PDResources;
import org.apache.pdfbox.pdmodel.common.PDStream;
import org.apache.pdfbox.pdmodel.graphics.PDXObject;
import org.apache.pdfbox.pdmodel.graphics.form.PDFormXObject;
import org.apache.pdfbox.pdmodel.graphics.pattern.PDAbstractPattern;
import org.apache.pdfbox.pdmodel.graphics.pattern.PDTilingPattern;

import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;

public class Main {

    public static void main(String[] args) throws IOException {
        if (args.length != 3) {
            usage();
        } else {
            PDDocument doc = PDDocument.load(new File(args[0]));
            if (doc.isEncrypted()) {
                System.err.println(
                        "Error: Encrypted documents are not supported .");
                System.exit(1);
            }

            for (PDPage page : doc.getPages()) {
                List<Object> newTokens = createTokensWithoutImage(page, args[2]);
                PDStream newContents = new PDStream(doc);
                writeTokensToStream(newContents, newTokens);
                page.setContents(newContents);
                processResources(page.getResources(), args[2]);
            }

            doc.save(args[1]);
            doc.close();
        }
    }

    private static List<Object> createTokensWithoutImage(PDContentStream contentStream, String im) throws IOException {
        PDFStreamParser parser = new PDFStreamParser(contentStream);
        Object token = parser.parseNextToken();
        List<Object> newTokens = new ArrayList<Object>();
        while (token != null) {
            if (token instanceof Operator) {
                Operator op = (Operator) token;
                if (op.getName().equalsIgnoreCase("do")) {
                    COSName previous = (COSName) newTokens.get(newTokens.size() - 1);
                    System.out.println(previous.getName());
                    if (previous.getName().equalsIgnoreCase(im)) {
                        // remove the argument to this operator
                        newTokens.remove(newTokens.size() - 1);
                        token = parser.parseNextToken();
                        continue;
                    }
                }
            }
            newTokens.add(token);
            token = parser.parseNextToken();
        }
        return newTokens;
    }


    private static void processResources(PDResources resources, String im) throws IOException {
        for (COSName name : resources.getXObjectNames()) {
            PDXObject xobject = resources.getXObject(name);
            if (xobject instanceof PDFormXObject) {
                PDFormXObject formXObject = (PDFormXObject) xobject;
                writeTokensToStream(formXObject.getContentStream(),
                        createTokensWithoutImage(formXObject, im));
                processResources(formXObject.getResources(), im);
            }
        }
        for (COSName name : resources.getPatternNames()) {
            PDAbstractPattern pattern = resources.getPattern(name);
            if (pattern instanceof PDTilingPattern) {
                PDTilingPattern tilingPattern = (PDTilingPattern) pattern;
                writeTokensToStream(tilingPattern.getContentStream(),
                        createTokensWithoutImage(tilingPattern, im));
                processResources(tilingPattern.getResources(), im);
            }
        }
    }

    private static void writeTokensToStream(PDStream newContents, List<Object> newTokens) throws IOException {
        OutputStream out = newContents.createOutputStream(COSName.FLATE_DECODE);
        ContentStreamWriter writer = new ContentStreamWriter(out);
        writer.writeTokens(newTokens);
        out.close();
    }


    /**
     * This will print the usage for this document.
     */
    private static void usage() {
        System.err.println("Usage: java " + Main.class.getName() + " <input-pdf> <output-pdf> <image-object-name>");
    }
}