Skip to content

Instantly share code, notes, and snippets.

View webrick-webify.rb
require 'webrick'
require 'open3'
server = WEBrick::HTTPServer.new :Port => 8000
server.mount_proc('/') { |req, res| res.body = Open3.capture2(ARGV[0], :stdin_data=>req.body)[0] }
trap('INT') { server.shutdown }
server.start
# server:
# ruby webify-webrick.rb "wc -c"
View CHANGELOG-keepachangelog-strictly.md
View cita-monitor-introduce.md

功能介绍:

为了方便CITA服务的运维,我们开发了 CITA 的监控服务,可用于监控节点中CITA的服务运行情况,包括区块链数据、CITA进程的存活监控、运行环境监控、故障自动告警通知。

软件架构:基于 Prometheus 框架开发;使用 Grafana 做可视化面板;使用 Alertmanager 做告警消息分发;运行架构上分为用于数据存储、信息展示、告警分发的 Server 端;区块链数据、软件进程、运行环境监控指标收集的 Agent 端;各端均使用微服务架构分离功能职责,并使用 Docker Compose 部署方式解决服务的依赖管理,轻松做到一行命令更新、启动服务。

功能列表

  • CITA 服务进程监控
@rainchen
rainchen / cita-jsonrpc-api-cache-demo.py
Created Apr 20, 2019
demo for using package "requests-cache" to cache the API request result, store cached data in a sqlite db
View cita-jsonrpc-api-cache-demo.py
#!/usr/bin/python3
# -*- coding: utf-8 -*-
# demo for using package "requests-cache" to cache the API request result, store cached data in a sqlite db as "cita_testnet_jsonrpc_cache.sqlite"
import requests
import requests_cache # doc: https://requests-cache.readthedocs.io/en/latest/
import time
# doc: http://flask.pocoo.org/docs/1.0/
@rainchen
rainchen / chrome-extensions.sh
Created Sep 15, 2017
scan Google Chrome installed Extensions dir and show each extension's info
View chrome-extensions.sh
#!/bin/bash
# scan Google Chrome installed Extensions dir and show each extension's info
# refs: https://www.jamf.com/jamf-nation/discussions/11307/chrome-extension-reporting
loggedInUser=$( ls -l /dev/console | awk '{print $3}' )
path="/Users/${loggedInUser}/Library/Application Support/Google/Chrome/Default/Extensions"
if [[ $1 != "" ]]; then
path=$1
echo "Read extensions from \"$path\""
echo
View qiniu-upload
#!/bin/bash
# refs:
# https://segmentfault.com/q/1010000003000974
# http://blog.csdn.net/guoer9973/article/details/46459971
# http://www.cnblogs.com/sink_cup/p/cloud_storage_aliyun_oss_vs_qiniu_rs.html
# api:
# https://developer.qiniu.com/kodo/api/1312/upload
View application.rb
require_relative 'boot'
require_relative 'rails_initializable_hack'
require 'rails/all'
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)
module Rails5NewDemo
@rainchen
rainchen / active_record_vs_exception.rb
Last active Nov 16, 2016
benchmark for active_record_vs_exception
View active_record_vs_exception.rb
# ref: http://blog.arkency.com/2016/11/ruby-exceptions-are-4400-times-faster-than-activerecord-base-number-create/
require 'active_record'
require 'benchmark/ips'
ActiveRecord::Base.logger = nil
ActiveRecord::Base.establish_connection adapter: 'sqlite3',
database: ':memory:'
ActiveRecord::Schema.define do
create_table :whatevers do |table|
table.column :text, :string
View statistic.rb
class Statistic
# save message to a log file
# usage:
# Statistic.log "message"
# Statistic.log { var }
def self.log(message = nil, &block)
@logger ||= Logger.new(Rails.root.join('log', "statistic.#{Rails.env}.log"))
begin
message = yield if block_given?
@logger.info("#{Time.current} #{message}")
View gist:7fd55e4a4aced4aff144
/*
_ooOoo_
o8888888o
88" . "88
(| -_- |)
O\ = /O
____/`---'\____
.' \\| |// `.
/ \\||| : |||// \
/ _||||| -:- |||||- \