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;
作者归档:ning
firebase替代
Google的firebase只能在国外用,且不开源,国内的有野狗、leancloud都是小厂。
参考
- open-source alternative to Firebase and Parse
- Open source self hosted firebase
- What\’s the closest open-source alternative to Firebase?
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>
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.
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'
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
})
letsencrypt https证书自动更新和续期(支持泛域名)
安装阿里云获取证书插件
https://github.com/tengattack/certbot-dns-aliyun
certbot certonly -a certbot-dns-aliyun:dns-aliyun \
--certbot-dns-aliyun:dns-aliyun-credentials /data/aliyun.ini \
-d c4ys.com \
-d *.c4ys.com
安装腾讯云(dnspod)获取证书插件
https://github.com/tengattack/certbot-dns-dnspod
certbot certonly -a certbot-dns-dnspod:dns-dnspod \
--certbot-dns-dnspod:dns-dnspod-credentials /data/aliyun.ini \
-d c4ys.com \
-d *.c4ys.com
查看已经安装插件
certbot plugins
更新证书
certbot renew
自动重新加载nginx(需要更新成功后,所以等前一个任务进行几分钟之后再执行)
nginx -s reload
基于微信的一些开源工具
Wechaty
https://github.com/wechaty/wechaty
Wechaty 是一个开源的的 个人号 微信机器人接口,是一个使用Typescript 构建的Node.js 应用。支持多种微信接入方案,包括网页,ipad,ios,windows, android 等。同时支持Linux, Windows, Darwin(OSX/Mac) 和 Docker 多个平台。
在GitHub上可以找到很多支持微信个人号接入的第三方类库,其中大多都是基于Web Wechat的API来实现的,如基于Python的WeixinBot,基于Node.js的Wechaty等。少数支持非Web协议的库,大多是商业私有闭源的,Wechaty是少有的开源项目支持非Web协议的类库。
只需要6行代码,你就可以 通过个人号 搭建一个 微信机器人功能 ,用来自动管理微信消息。
import { Wechaty } from 'wechaty'
Wechaty.instance()
.on('scan', qrcode => console.log('扫码登录:' + qrcode))
.on('login', user => console.log('登录成功:' + user))
.on('message', message => console.log('收到消息:' + message))
.on('friendship', friendship => console.log('收到好友请求:' + friendship))
.on('room-invite', invitation => console.log('收到入群邀请:' + invitation))
.start()
更多功能包括:
- 消息处理:关键词回复
- 群管理:自动入群,拉人,踢人
- 自动处理好友请求
- 智能对话:通过简单配置,即可加入智能对话系统,完成指定任务
- … 请自行开脑洞
wtoolsdkroomlive
https://github.com/weechatfly/wtoolsdkroomlive/
微控工具xp模块-开发版[微信(wechat)二次开发模块]sdk微信多群直播demo
WeChatLuckyMoney
https://github.com/geeeeeeeeek/WeChatLuckyMoney
微信红包
一个帮助你在微信抢红包时战无不胜的Android应用。自动检测并且拆开红包,速度超乎你的想象。
支持中英文。前往Release下载最新版本。已下载用户可直接在设置里面更新。
WeChatTimeLineRobot
https://github.com/cocos543/WeChatTimeLineRobot
项目简介:朋友圈自动点赞评论机器人
开发语言:C++
WeChatTweak-macOS
https://github.com/Sunnyyoung/WeChatTweak-macOS
项目简介:Mac微信多开及防撤回动态库
开发语言:Objective-C
Tencent/mars
腾讯官方微信网络通讯协议
https://github.com/Tencent/mars
WeChatXY
收费(谨慎购买)
微信ipad协议源码,可实现微信80%功能。支持62数据登录、扫码登录、收发朋友圈、查看朋友圈、微信建群、微信拉人进群、微信公众号阅读、微信消息收发、微信附近的人定位、微信添加好友、微信红包接收、微信防撤回、分享小程序、微信加粉、微信收藏、微信标签等。
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客户端
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