nginx access log 记录cgi执行时间

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;

firebase替代

Google的firebase只能在国外用,且不开源,国内的有野狗、leancloud都是小厂。

参考

PouchDB

PouchDB is an open-source JavaScript database inspired by Apache CouchDB that is designed to run well within the browser.

PouchDB was created to help web developers build applications that work as well offline as they do online.

It enables applications to store data locally while offline, then synchronize it with CouchDB and compatible servers when the application is back online, keeping the user\'s data in sync no matter where they next login.

var db = new PouchDB('dbname');

db.put({
  _id: 'dave@gmail.com',
  name: 'David',
  age: 69
});

db.changes().on('change', function() {
  console.log('Ch-Ch-Changes');
});

db.replicate.to('http://example.com/mydb');

CouchDB

Apache CouchDB™ lets you access your data where you need it. The Couch Replication Protocol is implemented in a variety of projects and products that span every imaginable computing environment from globally distributed server-clusters, over mobile phones to web browsers.

Store your data safely, on your own servers, or with any leading cloud provider. Your web- and native applications love CouchDB, because it speaks JSON natively and supports binary data for all your data storage needs.

The Couch Replication Protocol lets your data flow seamlessly between server clusters to mobile phones and web browsers, enabling a compelling offline-first user-experience while maintaining high performance and strong reliability. CouchDB comes with a developer-friendly query language, and optionally MapReduce for simple, efficient, and comprehensive data retrieval.

$ curl -X PUT http://127.0.0.1:5984/my_database/001 -d
'{  Name  :  Raju  ,  age  : 23  ,  Designation  :  Designer  }'

{ok:true,id:001,rev:1-1c2fae390fa5475d9b809301bbf3f25e}

gunDB

A realtime, decentralized, offline-first, mutable graph protocol to sync the web. https://gun.eco/docs

<script src=https://cdn.jsdelivr.net/npm/gun/gun.js></script>
<script>
// var Gun = require('gun'); // in NodeJS
// var Gun = require('gun/gun'); // in React
var gun = Gun();

gun.get('mark').put({
  name: Mark,
  email: mark@gunDB.io,
});

gun.get('mark').on(function(data, key){
  console.log(update:, data);
});
</script>

gun官网

RxDB

⛁ A realtime Database for JavaScript Applications https://rxdb.info/

myCollection.insert({
  name: 'foo',
  lastname: 'bar'
});
const query = myCollection
    .find()
    .where('age')
    .gt(18);

Meteor

Meteor is a full-stack JavaScript platform for developing modern web and mobile applications. Meteor includes a key set of technologies for building connected-client reactive applications, a build tool, and a curated set of packages from the Node.js and general JavaScript community.

  • Meteor allows you to develop in one language, JavaScript, in all environments: application server, web browser, and mobile device.
  • Meteor uses data on the wire, meaning the server sends data, not HTML, and the client renders it.
  • Meteor embraces the ecosystem, bringing the best parts of the extremely active JavaScript community to you in a careful and considered way.
  • Meteor provides full stack reactivity, allowing your UI to seamlessly reflect the true state of the world with minimal development effort.

Meteor 官网

import { Mongo } from 'meteor/mongo'; 
export const Tasks = new Mongo.Collection('tasks'); 
import { Tasks } from '../api/tasks.js'; 
db.tasks.insert({ text: Hello world!, createdAt: new Date() });

Kinto

Kinto is a minimalist JSON storage service with synchronisation and sharing abilities. It is meant to be easy to use and easy to self-host.

Kinto is used at Mozilla and released under the Apache v2 licence.

http GET https://kinto.dev.mozaws.net/v1/buckets/default/collections/tasks/records \
       -v --auth 'bob:s3cr3t'

Kinto文档

Kinto官网

Hoodie

Hoodie is a free and Open Source Software for building applications for the web and iOS. It is a complete backend for your apps, ready for you to get creative. It works immediately out-of-the-box: develop your frontend code, plug it into Hoodie’s frontend-friendly API and your app is ready.

When you develop it, your app runs locally first, you can then deploy and host it wherever you want to. And if you want to extend Hoodie’s core features, you can check our list of currently available plugins or build plugins yourself.

Hoodie is a noBackend technology — it\'s there for making the lives of frontend developers easier by abstracting away the backend and keeping you from worrying about backends. It gives you Dreamcode: a simple, easy-to-learn-and-implement frontend API built into it. Hoodie is also Offline First, which means that your app users’ data is stored locally by default so your Hoodie-based apps are accessible and usable anytime, independent from your users’ internet connection.

hoodie.store.add({
    type: 'todo-item',
    content: 'Try out hoodie!',
    done: false
})

使用阿里云certbot插件实现letsencrypt泛域名https自动更新和续期

https://github.com/tengattack/certbot-dns-aliyun

获取证书

certbot certonly -a certbot-dns-aliyun:dns-aliyun \
    --certbot-dns-aliyun:dns-aliyun-credentials aliyun.ini \
    -d c4ys.com \
    -d *.c4ys.com

更新证书

certbot renew

自动重新加载nginx(需要更新成功后,所以等前一个任务进行几分钟之后再执行)

nginx -s reload

基于微信的一些开源工具

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

Python进入交互模式4种方法

使用python -i参数

添加-i参数

python -i myapp.py

使用code.interact()

    import code
    # before
    code.interact()
    # after

使用pdb lib

for thing in set_of_things:
    import pdb;
    pdb.set_trace()
    do_stuff_to(thing)

使用IPython embed

from IPython import embed

for thing in set_of_things:
  embed()
  do_stuff_to(thing)

忘读读书法

有没有一种(功利的)读书法,读得快但是效果又最好?

进过不懈的努力,这个读书法被我发现了,就是“忘读读书法”。

这个方法类似张三丰教张无忌的太极神功,强调一个“忘”字。

方法原理:为什么是“忘”?我们相信:

  • 记住几个关键词,比记住整本书要容易得多
  • 记住当前最有效的部分并行动,比按照整本书去行动可行性更高
  • 书本的价值在于你利用多少,而不在于你知道多少

方法步骤:

  • 找到一步本书进行阅读,阅读的时候思考当前阅读的内容是否有新的观点,这个观点是否能够作为自己未来的人生信条和行为纲领,如果不是则忘掉,如果是则标记,这样读完;(因为一本书能够作为信条和纲领的比较少,所以能很快读完)
  • 重新阅读标记部分,提炼成几个关键字,根据关键字形成自己的关键字理解笔记(理解归纳,便于形成自己观点)
  • 将关键字作为自己未来的人生信条和行为纲领(学以致用)

《马云:未来已来》读后感 – 担当、乐观与坚持

担当

有担当才有未来,担当是个人和企业的对人类未来的价值和意义,担当能保证方向正确

  • 一家伟大的公司,必须解决社会问题
  • 企业家要思考十年之后的事
  • 如果地球病了,没有人会健康
  • 公益的本质是唤醒善良
  • 我相信,要改变世界,先改变自己,改变自己比改变世界更重要,也更简单。然后,我想改善世界。

乐观

机会就在被抱怨的地方,人类只要还存在不满,就不会停止进步,我们就还有机会

  • 机会就在被抱怨的地方
  • 所谓改革就是改革自己

坚持

三十年后不忘初心,就是成功

  • 少一些抱怨,多一些坚持
  • 三十年后不忘初心,就是成功
  • 一家企业没有经历过残酷时代,经不起风浪
  • 在阳光灿烂的日子修屋顶,年轻力壮的的时候生孩子
  • 晚上想想千条路,早上醒来走原路

Imagick给图片加文字和二维码

    // 初始化画布
    set_time_limit(0);
    $bg_file = Yii::getAlias('@frontend/web/test/wxbg.jpg');
    $image = new \Imagick($bg_file);

    // 写字
    $font_file = Yii::getAlias('@frontend/web/test/msyhbd.ttc');
    $draw = new \ImagickDraw();
    $draw->setFillColor('#FF7F24');
    $draw->setFont($font_file);
    $draw->setFontSize(64);
    $draw->setTextKerning(5);
    $draw->setFontWeight(700);
    $draw->setTextEncoding('UTF-8');
    $metrics = $image->queryFontMetrics($draw, $name);
    $draw->annotation(158, 50 + $metrics['ascender'], $name);
    $image->drawImage($draw);

    // 二维码
    $qr_image = new \Imagick(Yii::getAlias('@frontend/web/test/qr.png'));
    $qr_image->scaleImage(248, 248);
    $image->compositeImage($qr_image, \Imagick::COMPOSITE_COPY, 254, 504);

    // 返回
    $response = Yii::$app->getResponse();
    $response->format = Response::FORMAT_RAW;
    $response->headers->set('Content-Type', 'image/jpeg');
    $response->data = $image->getImageBlob();
    return $response->send();

Yii2按需加载js,css文件,并自动加上时间戳

网上找遍了国内和国外的资料,没有能够为动态增加的文件加上时间戳的,进过分析Yii2源码,发现其实非常简单:

开启assetManager支持自动加上时间戳

修改main.php

    'assetManager' => [
        'appendTimestamp' => true,
    ],

按需加载js,css

$bundle=AppAsset::register($this);
$bundle->js[]='js/windowview.js';
$bundle->css[]='css/robot.css';

Linux Shell生成随机数和随机字符串的5种方法

使用系统的 $RANDOM 变量

(CentOS、Ubuntu、MacOS 都支持,但只有5位数随机)

echo $RANDOM
24308

使用date +%s%N

(CentOS、Ubuntu支持,MacOS不支持纳秒 +%N)

date +%s%N
1557366636971317933

使用 /dev/random 和 /dev/urandom 随机文件

(CentOS、Ubuntu、MacOS 都支持)

head -20 /dev/urandom | cksum | cut -f1 -d " "
1053195602

使用 linux uuid

(CentOS、Ubuntu支持,MacOS不支持)

cat /proc/sys/kernel/random/uuid
bf05d41c-d69e-4247-8a79-baf3ab3f98ed

使用 openssl rand

(CentOS、Ubuntu支持、MacOS 都支持,需安装 openssl,推荐)

openssl rand -base64 128 
Smt+jcaMSQ64Y4La8U6OUFl/TZWm+cKGtDqg+MRbKY6Zwp5iOzg3xoVZv+6NQv/W 
UL+sqAHBhbTD1ZPgsyeloxTVLRV/SjU2O/mJAZoFLLZXtDhldl5lfgz3s3s28R+u 
24TUNXnxGLGqQQxaudcF8Lhgq3LjDLQWzrgrTOIv1e0=

openssl rand -base64 128 | md5sum | cut -c1-32 
2cbb48ea9bac4b08c2a9b4518e1faf79

openssl rand -hex 16 
339a905406bb4ef3631dfa1ad67d8d6a

openssl rand -hex 8 | cksum 
307618125 17

openssl rand -hex 8 | cksum | cut -c1-8 
41657201